0

在 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”:时间}

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 加载到地图列?

4

1 回答 1

0

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

于 2013-03-28T03:39:44.440 回答