【问题标题】:Loading the map datatype column using python script as reducer using hive使用 python 脚本作为使用 hive 的 reducer 加载地图数据类型列
【发布时间】:2013-03-27 08:34:33
【问题描述】:

在 Hive 表的其中一列中,我想存储键值对。 Hive 的复杂数据类型映射支持该构造。

(这只是我想要做的一个玩具示例,我还有更多列 我想这样压缩)

所以我创建了一个这样的表:

hive>DESCRIBE transaction_detailed;
OK
id STRING
time STRING
Time taken: 0.181 seconds

hive>DROP TABLE IF EXISTS transactions;
hive>CREATE EXTERNAL TABLE transactions(
    id STRING,
    time_map MAP<STRING, INT>
    )
partitioned by (dt string) 
row format delimited fields terminated by '\t' collection items terminated by ',' map keys terminated by ':' lines terminated by '\n' 
location 's3://my_loaction/transactions/';

然后我尝试使用代码中描述的reducer加载地图列:结构 time_map 看起来像: {"min": time, "max": time, "average": time, "total": time}

hive>FROM( FROM transaction_detailed 
MAP transaction_detailed.id, transaction_detailed.time
USING "python unity mapper -- splits the same thing out as it takes it"
AS id, time
cluster by id) transaction_time_map
insert overwrite table transactions partition(dt="2013-27-03")
REDUCE transaction_time_map.id, transaction_time_map.time
USING "python reducer which takes time_stamp sequence for a single id and summarizes them using min, max, average and total and supposed to insert into map"
as id, time_map;

但我收到这样的错误:

FAILED: Error in semantic analysis: Line 6:23 Cannot insert into target table because column number/types are different "two_day": Cannot convert column 8 from string to map<string,int>.

如何使用我的 python reducer 加载到地图列?

【问题讨论】:

    标签: python amazon-s3 hive emr


    【解决方案1】:

    我认为上述问题的答案是在hive中使用str_to_map(text[, delimiter1, delimiter2])函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 2016-03-10
      相关资源
      最近更新 更多