【问题标题】:Need to add a constant value in a column while loading a hive table加载配置单元表时需要在列中添加一个常量值
【发布时间】:2015-03-21 10:15:09
【问题描述】:

我在 hive 中创建了一个名为 table1 的表,我需要将 table2 中的数据插入 table1。我使用以下语句来获取输出。 我还需要添加一个具有一些恒定值的新列——colx = 'colval' 以及 table2 中的列,但我不知道如何添加它.. 谢谢!

INSERT INTO TABLE table1 select * FROM table2;

【问题讨论】:

    标签: hive


    【解决方案1】:

    如果您愿意放弃 table1 并从头开始重新创建它,您可以这样做:

    -- I'm using Hive 0.13.0
    DROP TABLE IF EXISTS table1;
    CREATE TABLE table1 AS SELECT *, 'colval' AS colx FROM TABLE2;
    

    如果由于某种原因这不是一个选项,您可以使用INSERT OVERWRITE:

    ALTER TABLE table1 ADD COLUMNS (colx STRING); -- Assuming you haven't created the column already
    INSERT OVERWRITE TABLE table1 SELECT *, 'colval' FROM table2;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多