【发布时间】:2020-03-18 18:40:34
【问题描述】:
我有一段代码,最后我将数据帧写入镶木地板文件。
逻辑使得数据框有时可能为空,因此我收到以下错误。
df.write.format("parquet").mode("overwrite").save(somePath)
org.apache.spark.sql.AnalysisException: Parquet data source does not support null data type.;
当我打印“df”的模式时,我得到了下面。
df.schema
res2: org.apache.spark.sql.types.StructType =
StructType(
StructField(rpt_date_id,IntegerType,true),
StructField(rpt_hour_no,ShortType,true),
StructField(kpi_id,IntegerType,false),
StructField(kpi_scnr_cd,StringType,false),
StructField(channel_x_id,IntegerType,false),
StructField(brand_id,ShortType,true),
StructField(kpi_value,FloatType,false),
StructField(src_lst_updt_dt,NullType,true),
StructField(etl_insrt_dt,DateType,false),
StructField(etl_updt_dt,DateType,false)
)
是否有一种解决方法可以只使用架构写入空文件,或者在为空时根本不写入文件? 谢谢
【问题讨论】:
标签: scala apache-spark apache-spark-sql parquet