Python pyspark:为Json文件列表创建公共模式

Python pyspark:为Json文件列表创建公共模式,python,json,apache-spark,pyspark,Python,Json,Apache Spark,Pyspark,我有一堆JSON文件,试图从JSON文件中提取数据。JSON文件假设每个文件都有以下模式: JSON File 1 root |-- a: struct (nullable = true) | |-- field1: string (nullable = true) | |-- field2: Array (nullable = true) | | |-- field3: Array (nullable = true) | | | |-- field4:

我有一堆JSON文件,试图从JSON文件中提取数据。JSON文件假设每个文件都有以下模式:

JSON File 1
root
|-- a: struct (nullable = true)
|    |-- field1: string (nullable = true)
|    |-- field2: Array (nullable = true)
|    |    |-- field3: Array (nullable = true)
|    |    |    |-- field4: Array (nullable = true)

JSON File 2
root
|-- a: struct (nullable = true)
|    |-- field1: string (nullable = true)
|    |-- field2: struct (nullable = true)
|    |    |-- field3: struct (nullable = true)
|    |    |    |-- field4: struct (nullable = true)

JSON File 3
root
|-- a: struct (nullable = true)
|    |-- field1: string (nullable = true)
|    |-- field2: struct (nullable = true)
|    |    |-- field3: Array (nullable = true)
|    |    |    |-- field4: Array (nullable = true)
field2、field3和field4的数据类型根据每个JSON文件中的数据从结构类型动态更改为数组类型

当前解决方案-我们有三个模式代表所有上述JSON文件。现在,我们使用fromJSON方法通过这三个模式解析所有JSON文件。之后 除去三个数据帧中的空记录,我们使用union函数将数据合并到单个数据帧中

我们希望为所有这些类型的文件编写通用模式以提取数据