0

I have a java Map (Map) and a JDBC connection to hive server. The schema of the table at the server contains a column of type Map. Is it possible to insert the java Map to the hive table column with similar datatype using JDBC?

I tried:

"create table test(key string, value Map<String, String>)"

 "insert into table test values ('keywer', map('subkey', 'subvalue')) from dummy limit 1;"

ref: Hive inserting values to an array complex type column

but the insert failed with:

"Error: Error while compiling statement: FAILED: ParseException line 1:69 missing EOF at 'from' near ')' (state=42000,code=40000)"

[EDIT]

hive version is : 0.14.0

Thanks

Community
  • 1
  • 1
Sri
  • 23
  • 1
  • 8

3 Answers3

1

The manual clearly says you cannot insert into a Map data type using SQL:

"Hive does not support literals for complex types (array, map, struct, union), so it is not possible to use them in INSERT INTO...VALUES clauses. This means that the user cannot insert data into a complex datatype column using the INSERT INTO...VALUES clause.”

Walker Rowe
  • 953
  • 1
  • 12
  • 24
0

I think the correct DDL and query would be:

CREATE TABLE test(key STRING, value MAP<STRING, STRING>);
INSERT INTO TABLE test VALUES('keywer', map('subkey', 'subvalue')) from dummy limit 1;
Rahul Sharma
  • 5,562
  • 4
  • 24
  • 48
0

A working method to put a complex type from jdbc client is:

insert into table test select "key",map("key1","value1","key2","value2") from dummy limit 1;

where dummy is another table which has at least one row.

Sri
  • 23
  • 1
  • 8