我在尝试在配置单元中定义地图类型时遇到问题。根据蜂巢手册肯定有地图类型,不幸的是没有任何关于如何使用它的示例。 :-(
假设,我有一个包含以下列的表(用户):
Name Ph CategoryName
此“CategoryName”列具有一组特定的值。现在我想创建一个将 CategoryName 映射到 CategoryID 的哈希表。我尝试这样做:
set hivevar:nameToID=map('A',1,'B',2);
我有两个问题:
当我做set hivevar:${nameToID['A']}
我以为它会打印出值 1。但我得到
“${hivevar:nameToID['A']} 未定义”
我不知道我该怎么说,select name, ph, ${nameToID[CategoryName]} from users
假设您有下表:
describe test;
name string
ph string
category map<string,int>
select * from test;
name ph category
Name1 ph1 {"type":1000,"color":200,"shape":610}
Name2 ph2 {"type":2000,"color":200,"shape":150}
Name3 ph3 {"type":3000,"color":700,"shape":167}
访问地图列:
select ph, category["type"], category["color"] from test;
ph1 1000 200
ph2 2000 200
ph3 3000 700
使用 Hive 变量的等效项:
set hivevar:nameToID=
map("t", category["type"], "c", category["color"], "s", category["shape"]);
select ph, ${nameToID}["t"], ${nameToID}["c"] from test;
ph1 1000 200
ph2 2000 200
ph3 3000 700
这适用于 Hive 0.9.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)