在将JSON读入数据框并合并架构时,这使您可以推断数据并提出最佳的架构。这使您可以将给定年份的大量JSON文件读取到数据框中;效果很好。我们想利用Parquet列式功能并最终将每个JSON文件转换为Parquet,尽管遇到了一个问题,即您无法将架构与Parquet文件合并,因为Parquet会推断数据并为每个Parquet文件创建一个架构。为什么通过数据框架的镶木地板文件不允许您覆盖架构并推断数据以允许您读取所有数据而不会出现不兼容的数据类型异常?我想避免在创建镶木地板文件时必须提前创建通用架构。
有什么解决方案可以读取镶木地板文件并推断数据类型,例如如何将大量JSON文件读取到数据框中?
df_p = spark.read.options(mergeSchema=True).parquet('s3a://parquet_example_data/year=2020/')
Exception thrown:
Caused by: org.apache.spark.SparkException: Failed to merge fields 'field1' and 'field1'. Failed to merge fields 'field2' and 'field2'. Failed to merge fields 'field3' and 'field3'. Failed to merge fields 'field4' and 'field4'. Failed to merge fields 'field5' and 'field5'. Failed to merge incompatible data types bigint and double
at org.apache.spark.sql.types.StructType$$anonfun$merge$1$$anonfun$apply$3.apply(StructType.scala:502)
at org.apache.spark.sql.types.StructType$$anonfun$merge$1$$anonfun$apply$3.apply(StructType.scala:495)
at scala.Option.map(Option.scala:146)
at org.apache.spark.sql.types.StructType$$anonfun$merge$1.apply(StructType.scala:495)