HiveSQL:查询结构数组(HiveSQL: Query an array of structs)

编程入门 行业动态 更新时间:2024-10-19 22:18:01
HiveSQL:查询结构数组(HiveSQL: Query an array of structs)

我有一个结构数组的表(源自Spark镶木地板文件)。 例如,表树看起来像这样:

| -- family_name : string | -- kids : array | -- element : struct | -- name : string | -- id : string | -- class_grades : struct | -- math : int | -- science : int

我想得到所有family_name ,其中至少有一个孩子的math成绩高于90.请注意,孩子的数量可能因家庭而异。 我怎样才能做到这一点?

I have a table with an array of structs (originates from Spark parquet file). As an example, The table tree looks like this:

| -- family_name : string | -- kids : array | -- element : struct | -- name : string | -- id : string | -- class_grades : struct | -- math : int | -- science : int

I'd like to get all the family_names where there's at least one kid with a math grade above 90. Note that the number of kids may vary between families. How can I do this?

最满意答案

想办法:

SELECT family_name, grades.math FROM (SELECT family_name, grades FROM table_name LATERAL VIEW OUTER explode(class_grades) c as grades) AS exploded_grades WHERE grades.math > 90

Figure it out:

SELECT family_name, grades.math FROM (SELECT family_name, grades FROM table_name LATERAL VIEW OUTER explode(class_grades) c as grades) AS exploded_grades WHERE grades.math > 90

更多推荐

本文发布于:2023-08-01 14:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1359173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   结构   HiveSQL   structs   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!