【问题标题】:Hive - grouping rows into mapHive - 将行分组到地图中
【发布时间】:2013-12-05 20:04:00
【问题描述】:

我有一张这样的桌子

Col1   Col2   Col3
A      1      word1
A      2      word2
A      3      word3
A      4      word4
B      1      word1
B      3      word3

我想按 col1 对 col2 和 col3 进行分组,但将 col2 和 col3 保留在地图中,如下所示:

Col1   map(col2, col3)
A      [(1, word1), (2, word2), (3, word3), (4, word4)]
B      [(1, word1), (3, word3)]

我知道有一种方法可以只使用一个数组,如下所示:Grouping hive rows in an array of this rows

但我想知道这是否可以通过映射(键/值对)实现。

【问题讨论】:

    标签: dictionary hive grouping


    【解决方案1】:

    在 BrickHouse http://github.com/klout/brickhouse 中使用“收集”UDF

    select col1, collect( col2, col3 )
    from mytable
    group by col1
    

    您还可以将地图与“union_map”UDAF 合并

    【讨论】:

    • 它不喜欢分组的某些东西......hive> create table t1 as select A, collect(B, C) FROM t2 group by A; FAILED: SemanticException [Error 10025]: Line 1:35 Expression not in GROUP BY key 'C' 我也用group by A, C 尝试过它仍然给出同样的错误。
    • 确保 BrickHouse 罐子在您的 HIVE_AUX_JARS 中,并且您已通过采购 brickhouse.hql 定义了砖房 UDF。 IE... CREATE TEMPORARY FUNCTION collect AS 'brickhouse.udf.collect.CollectUDAF';
    • CREATE TEMPORARY FUNCTION collect AS 'brickhouse.udf.collect.CollectUDAF'; 成功了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 2015-08-01
    • 1970-01-01
    • 2019-12-23
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多