【问题标题】:Hive - Loading into default location of external tableHive - 加载到外部表的默认位置
【发布时间】:2018-10-21 12:18:54
【问题描述】:

我在 hive 中使用默认位置创建了一个外部表

 CREATE EXTERNAL TABLE `testtable`(
      `id` int, 
      `name` string)
    ROW FORMAT DELIMITED 
     FIELDS TERMINATED BY ',' 
    STORED AS INPUTFORMAT 
     'org.apache.hadoop.mapred.TextInputFormat' 
   OUTPUTFORMAT 
    'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
    LOCATION
    '<hdfs-uri>/hive/warehouse/testtable'

想确认是否可以将包含 ID/名称值的文本文件从本地移动到外部表 testtable 的 HDFS 位置 /hive/warehouse/testtable/test.txt?谢谢。

【问题讨论】:

    标签: hive hiveql


    【解决方案1】:

    是的。您可以将test.txtlocal 上传到外部表testtable (&lt;hdfs-uri&gt;/hive/warehouse/testtable) 的HDFS 位置。即使&lt;hdfs-uri&gt;/hive/warehouse/ 是默认的Hive 仓库目录,这也将起作用。

    请记住 - 对于非外部(称为 Hive 管理)表,删除该表将自动删除其仓库 HDFS 目录。对于external表,删除该表不会删除备份它的HDFS目录,需要单独删除。

    插图:

    Here the Hive warehouse directory is hdfs:///apps/hive/warehouse
    

    创建表

    hive> CREATE EXTERNAL TABLE `testtable`(
          `id` int, 
          `name` string)
           ROW FORMAT DELIMITED 
           FIELDS TERMINATED BY ',' 
          STORED AS INPUTFORMAT 
            'org.apache.hadoop.mapred.TextInputFormat' 
          OUTPUTFORMAT 
            'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
          LOCATION 'hdfs:///apps/hive/warehouse/testtable';
    

    test.txt 中的数据

    1,name-1
    2,name-2
    3,name-3
    

    将数据上传到 HDFS

    hadoop fs -put test.txt hdfs:///apps/hive/warehouse/testtable
    

    查询表

    hive> select * from testtable;
    1   name-1
    2   name-2
    3   name-3
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多