简体   繁体   English

通过使用配置单元查询可以将表数据转换为复杂类型列表 <structure> ?

[英]By using hive query Can I convert table data into complex type list<structure>?

Here is the table details 这是表格的详细信息

Id    Data  
a     {"col1":"11.0","col2":30.0}  
a     {"col1":"12.0","col2":10.0}  
b     {"col1":"11.0","col2":20.0}  
b     {"col1":"12.0","col2":25.0}  
b     {"col1":"15.0","col2":25.0}  
c     {"col1":"12.0","col2":15.0}  
c     {"col1":"13.0","col2":16.0}  

Expected Output - List of Data structures grouped by Id. 预期输出-按ID分组的数据结构列表。

ID  Data  
a   list[ {"col1":"11.0","col2":30.0},{"col1":"12.0","col2":10.0}]  
b   list[ {"col1":"11.0","col2":20.0},{"col1":"12.0","col2":25.0},{"col1":"15.0","col2":25.0}]  
c   list[ {"col1":"12.0","col2":15.0},{"col1":"13.0","col2":16.0}] 

Is it possible by functions supported by HIVE or need to write any user define function. HIVE支持的功能是否可能,还是需要编写任何用户定义的功能。

The short answer is yes, and there are previous answers to this, see here 简短的答案是肯定的,并且对此有以前的答案,请参见此处

How to get array/bag of elements from Hive group by operator? 如何通过运算符从Hive组获取数组/元素袋?

But in summary if you you have only unique elements then use collect_set otherwise use collect_list (only works in hive 0.13+), apart from that it is a standard group by query. 但总而言之,如果您只有唯一元素,则使用collect_set,否则使用collect_list(仅适用于hive 0.13+),除了它是标准的按查询分组。

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

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