如何为复数数组<struct <...>&gt;编写插入注释输入蜂巢?

时间:2018-04-15 14:11:34

标签: hadoop hive hdfs

表格结构:

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数据到此复杂表中?

1 个答案:

答案 0 :(得分:1)

回答OP:

  1. 创建一个包含1行的虚拟表(架构并不重要)。我们称之为dummy
  2. 运行以下查询,在您的test.test_complex_alter表中插入1行:
  3. 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;

    阵列的结构(第2列):

    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;