Getting error while reading ArrayType values(phoneNumbers), without ArrayType values, I can read rest values.
{
"firstName": "Rack",
"lastName": "Jackon",
"gender": "man",
"age": 24,
"address": {
"streetAddress": 126,
"city": "San Jone",
"state": "CA",
"postalCode": 394221
},
"phoneNumbers": [
{ "type": "home", "number": 7383627627}
]
}
My schema ->
val schema=StructType(List(
StructField("firstName",StringType),
StructField("lastName",StringType),
StructField("gender",StringType),
StructField("age",IntegerType),
StructField("address",StructType(List(
StructField("streetAddress",StringType),
StructField("city",StringType),
StructField("state",StringType),
StructField("postalCode",IntegerType)))),
StructField("phoneNumbers",ArrayType(StructType(List(
StructField("type",StringType),
StructField("number",IntegerType))))),
))
json_df.selectExpr("firstName","lastName",
"gender","age","address.streetAddress","address.city",
"address.state","address.postalCode",
"explode(phoneNumbers) as phone","phone.type","phone.number").drop("phone").show()
When I do .show
, it shows only column names and no values but when I don't take "phoneNumbers" array, it works fine.