【问题标题】:How to insert into Hive table with a column of data type array<struct<int>>如何使用数据类型 array<struct<int>> 的列插入 Hive 表
【发布时间】:2016-01-08 13:26:14
【问题描述】:

我正在尝试将数据插入到我创建的 Hive 中的表中。我一直在苦苦挣扎,所以我试图尽可能地简化它以找到问题的根源。

这是我创建基本表格的简化代码。我基本上有一个包含单个元素的结构数组。

DROP TABLE IF EXISTS foo.S_FILE_PA_JOB_DATA_T;

CREATE TABLE foo.S_FILE_PA_JOB_DATA_T
  PARTITIONED BY (customer_id string)
  STORED AS AVRO
  TBLPROPERTIES (
 'avro.schema.literal'=
 '{
   "namespace": "com.foo.oozie.foo",
   "name": "S_FILE_PA_JOB_DATA_T",
   "type": "record",
   "fields":
   [
      {"name":"pa_hwm"             ,"type":{
         "type":"array",
         "items":{
           "type":"record",
           "name":"pa_hwm_record",
           "fields":
           [
             {"name":"pa_axis"           ,"type":["int","null"]}
           ]
         }
      }}
   ]
   }');

我的问题是我不知道插入表格的语法。

insert into table foo.s_FILE_PA_JOB_DATA_T partition (customer_id) values (0,'a390c1cf-4ee5-4ab9-b7a3-73f5f268b669')

0 需要以某种方式成为array&lt;struct&lt;int&gt;&gt;,但我无法正确使用语法。任何人都可以帮忙吗?谢谢!

【问题讨论】:

    标签: arrays hadoop hive hql avro


    【解决方案1】:

    很遗憾,您不能直接这样做。另见Hive inserting values to an array complex type column

    理论上,你应该可以使用类似的东西来做到这一点

    insert into table s_file_pa_job_data_t partition(customer_id)  
      values (array(named_struct('pa_axis',0)) );
    

    也就是说,使用array()named_struct() udfs,它们将从一些标量值分别构造一个数组和一个根据您的规范的结构。 (请参阅此处的 UDF 文档:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-ComplexTypeConstructors

    但不幸的是,如果你这样做,你会得到

    FAILED: SemanticException [Error 10293]: Unable to create temp file 
    for insert values Expression of type TOK_FUNCTION not supported in insert/values
    

    因为不幸的是,hive 还不支持在 VALUES 子句中使用 UDF 函数。正如其他帖子所建议的那样,您可以使用虚拟表来完成此操作,这有点难看,但可以。

    【讨论】:

      猜你喜欢
      • 2017-10-05
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      相关资源
      最近更新 更多