表格结构:
CREATE TABLE IF NOT EXISTS test.test_complex_alter(
`id` STRING,
`items` array<struct<
quantity: INT,
articleData:struct<subsysNumber:string>,
pickedReason:string>>
) STORED AS ORC;
如何使用INSERT
查询INSERT
数据到此复杂表中?
答案 0 :(得分:1)
dummy
。test.test_complex_alter
表中插入1行: INSERT INTO TABLE test.test_complex_alter SELECT "id1", array(named_struct('quantity',20, 'articleData', named_struct('subsysNumber', 'subsys1'), 'pickedReason', 'reason1'),named_struct('quantity',30, 'articleData', named_struct('subsysNumber', 'subsys2'), 'pickedReason', 'reason2')) from dummy;
array(named_struct(n1,v1,..,nn,vn),...,named_struct(n1,v1,..,nn,vn))
hive> select * from test100.test_complex_alter;
OK
test_complex_alter.id test_complex_alter.items
id1 [{"quantity":20,"articleData":{"subsysNumber":"subsys1"},"pickedReason":"reason1"},{"quantity":30,"articleData":{"subsysNumber":"subsys2"},"pickedReason":"reason2"}]
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF - &gt; &#34;复杂类型构造函数&#34;