简体   繁体   English

HiveSQL:查询结构数组

[英]HiveSQL: Query an array of structs

I have a table with an array of structs (originates from Spark parquet file). 我有一个带有结构数组的表(起源于Spark Parquet文件)。 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_name s where there's at least one kid with a math grade above 90. Note that the number of kids may vary between families. 我想获得所有family_name ,其中至少有一个孩子的math成绩高于90。注意,孩子的数量可能因家庭而异。 How can I do this? 我怎样才能做到这一点?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM