配置单元:to_map功能不起作用

时间:2016-03-28 00:09:20

标签: hive udf

我将以下数据放入hive表中;

select pid, year, catches  from fielding_s where  pid = 'zobribe01' group by id;

zobribe01       2006    [{"p1":52,"p2":50,"p3":1322,"p4":86}]  
zobribe01       2007    [{"p1":30,"p2":26,"p3":674,"p4":37}]  
zobribe01       2008    [{"p1":8,"p2":4,"p3":123,"p4":11}]  
zobribe01       2008    [{"p1":1,"p2":0,"p3":14,"p4":0}]  
zobribe01       2008    [{"p1":5,"p2":3,"p3":81,"p4":8}]  
zobribe01       2008    [{"p1":14,"p2":8,"p3":238,"p4":21}]  
zobribe01       2008    [{"p1":19,"p2":12,"p3":340,"p4":29}]  
zobribe01       2008    [{"p1":2,"p2":1,"p3":21,"p4":0}]  
zobribe01       2008    [{"p1":35,"p2":33,"p3":880,"p4":51}]  
zobribe01       2009    [{"p1":3,"p2":2,"p3":39,"p4":6}]  
zobribe01       2009    [{"p1":91,"p2":81,"p3":2144,"p4":143}]  
zobribe01       2009    [{"p1":1,"p2":1,"p3":17,"p4":0}]  
zobribe01       2009    [{"p1":7,"p2":5,"p3":140,"p4":15}]  
zobribe01       2009    [{"p1":1,"p2":null,"p3":null,"p4":null}]  
zobribe01       2009    [{"p1":9,"p2":2,"p3":114,"p4":8}]  
zobribe01       2009    [{"p1":70,"p2":44,"p3":1242,"p4":112}]  
zobribe01       2009    [{"p1":59,"p2":37,"p3":988,"p4":89}]  
zobribe01       2009    [{"p1":13,"p2":6,"p3":186,"p4":9}]  
zobribe01       2010    [{"p1":14,"p2":9,"p3":237,"p4":77}]  
zobribe01       2010    [{"p1":55,"p2":45,"p3":1113,"p4":74}]  
zobribe01       2010    [{"p1":2,"p2":1,"p3":30,"p4":1}]  
zobribe01       2010    [{"p1":14,"p2":9,"p3":250,"p4":22}] 
zobribe01       2010    [{"p1":1,"p2":0,"p3":6,"p4":0}]  
zobribe01       2010    [{"p1":110,"p2":89,"p3":2504,"p4":204}]    
zobribe01       2010    [{"p1":103,"p2":80,"p3":2248,"p4":182}]  
zobribe01       2011    [{"p1":131,"p2":118,"p3":3175,"p4":213}]  
zobribe01       2011    [{"p1":38,"p2":33,"p3":869,"p4":65}]  

我想使用to_map函数将这些行合并到一个表中。我在查询下运行,但它给了我以下错误。

select pid, to_map(year, catches) from fielding_s where  pid = 'zobribe01' group by pid;
  

FAILED:SemanticException [错误10025]:第1:12行不在GROUP BY键中表达'捕获'

1 个答案:

答案 0 :(得分:0)

从查询中删除register()子句,然后尝试

group by