I am trying different ways to query a record within a array of records and display complete Row as output.
I dont know which nested Object has String "pg". But i want to query on particular object. Whether the object has "pg" or not. If "pg" exist then i want to display that complete row. How to write "spark sql query" on nested objects without specfying the object index.So i dont want to use the index of children.name
My Avro Record:
{
"name": "Parent",
"type":"record",
"fields":[
{"name": "firstname", "type": "string"},
{
"name":"children",
"type":{
"type": "array",
"items":{
"name":"child",
"type":"record",
"fields":[
{"name":"name", "type":"string"}
]
}
}
}
]
}
I am using Spark SQL context to query dataframe which is read. So if input is
Row no Firstname Children.name
1 John Max
Pg
2 Bru huna
aman
Output should return poq 1 since it has row where one object of children.name is pg.
val results = sqlc.sql("SELECT firstname, children.name FROM nestedread where children.name = 'pg'")
results.foreach(x=> println(x(0), x(1).toString))
The above query doesn't work. but it works when i query children[1].name.
I ALSO want to know that if i can filter a set of records and then explode. Instead of first explode and create large number of rows and then filter.