2015-05-25 44 views
8

我無法使用insert into語句將數據追加到包含數組列的表中;數據類型是陣列< VARCHAR(200)>Hive將值插入到數組複雜類型列

使用jodbc我無法通過像值將值插入一個陣列列:

INSERT INTO demo.table (codes) VALUES (['a','b']); 

不識別「[」或「{」符號。

使用陣列功能像...

INSERT INTO demo.table (codes) VALUES (array('a','b')); 

我使用陣列功能得到以下錯誤:

Unable to create temp file for insert values Expression of type TOK_FUNCTION not supported in insert/values 

試圖解決辦法...

INSERT into demo.table (codes) select array('a','b'); 

失敗:

Failed to recognize predicate '<EOF>'. Failed rule: 'regularBody' in statement 

如何使用jdbc將數組數據加載到列中?

回答

2

作出dummy表,其中至少有one row

INSERT INTO demo.table (codes) VALUES (array('a','b')) from dummy limit 1; 

hive> select codes demo.table; 
OK 
["a","b"] 
Time taken: 0.088 seconds, Fetched: 1 row(s) 
+0

請問具體的虛擬表需要包含哪些內容? –

+0

虛擬表是一個簡單的演示表,至少有一行。 –

+0

我創建了一個帶有兩個STRING字段的虛擬表,並使用命令INSERT INTO ADS(pageid,adid_list)VALUES('front_page',array(1,2,3))FROM DUMMY LIMIT 1;'得到了錯誤:' FAILED:ParseException行1:16無法識別'(''pageid'','聲明'附近的輸入。你能幫忙嗎? – SrinivasR

5

我的表格有兩列:a STRING, b ARRAY<STRING>

當我使用@Kishore庫馬爾Suthar的方法,我得到這個:

FAILED: ParseException line 1:33 cannot recognize input near '(' 'a' ',' in statement

但我發現另一種方式,它的工作對我來說:

INSERT INTO test.table 
SELECT "test1", ARRAY("123", "456", "789") 
FROM dummy LIMIT 1; 

dummy是任何至少有一排的桌子。