我有一个 csv 文件
第1577章
我尝试使用自定义模式加载 csv 文件,
val customSchema = StructType(Array(
StructField("id", StringType, nullable = false),
StructField("flag1", BooleanType, nullable = false),
StructField("flag2", BooleanType, nullable = false),
StructField("flag3", BooleanType, nullable = false),
StructField("flag4", BooleanType, nullable = false),
StructField("flag6", BooleanType, nullable = false))
)
val df =
spark.read.schema(customSchema).option("header","false").
option("inferSchema","false").csv("mycsv.csv")
但是可以正确地为空的模式并没有像预期的那样改变。
df.printSchema
root
|-- id: string (nullable = true)
|-- flag1: boolean (nullable = true)
|-- flag2: boolean (nullable = true)
|-- flag3: boolean (nullable = true)
|-- flag4: boolean (nullable = true)
|-- flag6: boolean (nullable = true)