蜂巢中的地图分组价值

问题描述

我在蜂巢中有一张桌子

CREATE TABLE IF NOT EXISTS user
(
    name STRING,creation_date DATE,cards map<STRING,STRING>
) STORED AS PARQUET ; 

让我们假设我要查询每个用户和按他们分组的Gobelin卡的数量

我的查询如下:

 select card["Gobelin"],COUNT(*) from user GROUP BY card["Gobelin"] ;

我说的话对群组有误

FAILED: SemanticException [Error 10033]: Line 54:30 [] not valid on non-collection types '"Gobelin"': string
 

解决方法

据我了解,您想使用键"Gobelin"计算地图元素。您可以分解地图,然后过滤掉其他键并计算剩余值,例如

select count(*) as cnt
  from(select explode(cards) as (key,val) from table)
 where key = 'Gobelin'

您也可以使用lateral view,有关详细信息,请参见Hive's manual

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...