如何为以下 json 创建模式以读取模式。我正在使用 hiveContext.read.schema().json("input.json"),我想忽略前两个“ErrorMessage”和“IsError”只读报告。下面是 JSON:
{
"ErrorMessage": null,
"IsError": false,
"Report":{
"tl":[
{
"TlID":"F6",
"CID":"mo"
},
{
"TlID":"Fk",
"CID":"mo"
}
]
}
}
我创建了以下架构:
val schema = StructType(
Array(
StructField("Report", StructType(
Array(
StructField
("tl",ArrayType(StructType(Array(
StructField("TlID", StringType),
StructField("CID", IntegerType)
)))))))))
Below is my json.printSchema() :
root
|-- Report: struct (nullable = true)
| |-- tl: array (nullable = true)
| | |-- element: struct (containsNull = true)
| | | |-- TlID: string (nullable = true)
| | | |-- CID: integer (nullable = true)