Hive - 将行分组到地图 [英] Hive - grouping rows into map

查看:162
本文介绍了Hive - 将行分组到地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的表

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保存在地图中,如下所示:

And I want to group col2 and col3 by col1, but keep col2 and col3 in a map, like so:

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

我知道有一种办法,只需一个阵列,如下所示:将这个hive行分组到这个数组中行

I know there is a way to do this with just an array, as appears here: Grouping hive rows in an array of this rows

但我想知道是否可以使用地图(键/值对)。

But I'm wondering if this is possible with a map (key/value pairs).

推荐答案

在BrickHouse中使用收集UDF http:// github .COM /的Klout / brickhouse

Use the "collect" UDF in BrickHouse http://github.com/klout/brickhouse

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

您还可以将地图与union_mapUDAF

You can also merge maps with the "union_map" UDAF

这篇关于Hive - 将行分组到地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆