【发布时间】:2018-02-05 17:53:29
【问题描述】:
我正在 Spark 中创建一个数据框,并且我已将架构定义如下:
SCHEMA = StructType([StructField('s3_location', StringType()),
StructField('partition_date', StringType()),
StructField('table_name', StringType()),
StructField('column_name', StringType()),
StructField('data_type', StringType()),
StructField('number_of_nulls', LongType()),
StructField('min', DoubleType()),
StructField('max', DoubleType()),
StructField('mean', DoubleType()),
StructField('variance', DoubleType()),
StructField('max_length', LongType())])
我有一堆遵循这个确切模式的行,我正在按如下方式创建数据框:
DF = SPARK.createDataFrame(ROWS, schema=SCHEMA)
然后我将此数据帧写入 AWS S3 中的 CSV 文件:
DF.repartition(1).write.mode('append').partitionBy('partition_date').csv(SAVE_PATH,
header=True)
此过程成功并在 S3 中创建 CSV 文件。现在,我在 AWS Glue 中抓取这个 S3 位置,它以不同的方式推断架构。我指定为DoubleType() 的所有字段都被推断为string。因此,如果我想使用 QuickSight 之类的工具对这些值运行任何聚合函数,我不能。
为什么会这样?有办法解决吗?
【问题讨论】:
-
好像和Spark没什么关系。更多的是其他工具无法从 csv 推断架构。
标签: csv apache-spark pyspark spark-dataframe aws-glue