zac*_*con 5 arrays hadoop hive
使用 Hive 我创建了一个包含以下字段的表:
这是通过以下 SQL 命令填充数据的:
Insert overwrite table temp_output Select a.ID, a.MSISDN, a.DAY, a.MONTH, a.YEAR, a.GENDER, a.RELATIONSHIPSTATUS, b.NAME, COLLECT_SET(c.NAME) FROM temp_basic_info a JOIN temp_education b ON (a.ID = b.ID) JOIN likes_and_music c ON (c.ID = b.ID) GROUP BY a.ID, a.MSISDN, a.DAY, a.MONTH, a.YEAR, a.Gender, a.RELATIONSHIPSTATUS, b.NAME;
Run Code Online (Sandbox Code Playgroud)
Likes 和 Preferences 是一个数组,但我没有足够的远见来指定它(相反,它是一个字符串)。我将如何选择在数组中具有特定项目的记录?
是不是就这么简单:
select * from table_result where LIKES_AND_PREFERENCES = "item"
Run Code Online (Sandbox Code Playgroud)
还是会出现一些不可预见的问题?
我尝试了上面的查询,但它确实输出了仅包含数组中的“项目”的文件。
也许你应该尝试这样的事情:
select * from (
select col1,col2..coln, new_column from table_name lateral view explode(array_column_name) exploded_table as new_column
) t where t.new_column = '<value of items to be searched>'
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助...!!!