0

In one of the columns of Hive table, I want to store key-value pairs. Hive's complex data-type map supports that construct.

(This is only a toy example of what I want to be able to do, I have many more columns that I want to compress like this)

So I create a table like this:

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/';

Then I try to load the map column using a reducer as described in the code: the structure of the time_map would look something like: {"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;

But I get a error like this:

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>.

How do I load to the map column using my python reducer ?

darshan
  • 1,230
  • 1
  • 11
  • 17

1 Answers1

0

I think the answer to the above question is to use str_to_map(text[, delimiter1, delimiter2]) function in hive.

darshan
  • 1,230
  • 1
  • 11
  • 17