我希望首先只过滤具有Max的行,然后只对嵌套列中具有Max的行进行爆破。
我的阿夫罗记录:
{
"name": "Parent",
"type":"record",
"fields":[
{"name": "firstname", "type": "string"},
{
"name":"children",
"type":{
"type": "array",
"items":{
"name":"child",
"type":"record",
"fields":[
{"name":"name", "type":"string"}
{"name":"price","type":["long", "null"]}
]
}
}
}
]
}我使用Spark上下文来查询读取的数据。所以如果输入是
Row no Firstname Children.name
1 John [[Max, 20],[Pg, 22]]
2 Bru [[huna, 10], [aman, 12]]我首先通过爆炸内表来查询。因此嵌套列分裂为2行。
Row no Firstname Children.name children.price
1 John Max 20
1 John Pg 22
2 Bru huna 10
2 Bru aman 12Q1)我想先过滤那些有Max的行,然后我只想爆掉其中包含Max的行。在当前情况下,如果在一列中有一百万个值,它首先生成百万行,然后检查是否存在Max。
q2),首先只过滤价格> 12的行,然后只过滤价格> 12的行。在当前情况下,如果在一列中有一百万个值,那么它首先生成百万行,然后检查价格是否大于12。
如下所示:val results =sqlc.sql(“从父侧视图中选择child.name,从父侧视图中爆炸(子) childTable AS childTable,其中child.price > 12")
发布于 2016-05-23 08:46:19
下面是两个问题的ans : ans1) 如果您想要查找嵌套记录数组中是否存在"string“:
var results = sqlc.sql("SELECT firstname, children.name FROM parent where array_contains(children['name'], 'pg') ")如果要对嵌套记录数组应用条件,则为ans2) 。使用UDF
sqlc.udf.register("myPriceFilter", (price: mutable.WrappedArray[String]) => (price exists (a => (a.toLong < 67735) )))
var results = sqlc.sql("SELECT firstname, explode(children.price) FROM parent where myPriceFilter(children['price']) ")https://stackoverflow.com/questions/37382927
复制相似问题