代码之家  ›  专栏  ›  技术社区  ›  AbtPst

配置单元:无法插入具有映射列的表

  •  0
  • AbtPst  · 技术社区  · 7 年前

    hive> desc test_tab;
    OK
    test_map    map<string,string>
    test_date               string
    
    # Partition Information
    # col_name              data_type               comment
    
    test_date               string
    Time taken: 0.087 seconds, Fetched: 7 row(s)
    

    这是我的插入声明

    hive> insert into table test_tab
        > values ('2018-02-28', map("key","val"));
    

    FAILED: ParseException line 2:0 cannot recognize input near 'values' '(' ''2018-02-28'' in select clause
    

    我也试过了

    hive> insert into table test_tab partition (test_date = '2018-02-28')
        > select  map("key","val");
    FAILED: NullPointerException null
    

    我做错什么了?

    Hive 0.13.1-SNAPSHOT

    0 回复  |  直到 7 年前
        1
  •  0
  •   Skanda Shastry    7 年前

    可以通过两种方式将数据加载到配置单元表中
    *使用HDFS命令:

    CREATE TABLE `test_sample`(
      `test_map` map<string,string>   
    )
    PARTITIONED BY (
      `test_date ` string)
    ROW FORMAT DELIMITED
      FIELDS TERMINATED BY ','
      MAP KEYS TERMINATED BY '='
    STORED AS INPUTFORMAT
      'org.apache.hadoop.mapred.TextInputFormat'
    OUTPUTFORMAT
      'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
    

    样品输入文件

    hadoop fs -put input.txt HDFS_dest_Path
    

    将文件上载到Hadoop fs之后,再将数据加载到表中:

    load data inpath <location of the hadoop table> into table test_sample partition(test_date='2019-02-28');
    
    • 使用查询:

    如果文件系统中已经存在类似的数据,则可以通过配置单元查询将其插入表中。

    INSERT INTO TABLE test_tab PARTITION(test_date= '2019-02-28')
    select map from  test_sample;
    

    注意:由“=”约束终止的映射键对于测试选项卡表不一定是必需的。