【问题标题】:Is there a way to prevent insertion of duplicate rows in Hive?有没有办法防止在 Hive 中插入重复行?
【发布时间】:2017-12-01 12:57:10
【问题描述】:

我有一个ORC 表。我使用其他表中的数据填充它,如下所示:

INSERT INTO TABLE orc_table_name SELECT * FROM other_table_name

有什么方法可以防止在 ORC 表中插入重复条目?

【问题讨论】:

    标签: hadoop hive orc


    【解决方案1】:

    您可以在命令中使用 not 参见下面的通用代码:它根据之前未插入 TABLE_1 中的 value1 的事实将记录插入到 orc_table_name 中。

    INSERT INTO orc_table_name
      (Value1, Value2)
    SELECT t1.Value1,
           t1.Value2
      FROM TABLE_1 t1
     WHERE t1.Value1 NOT IN (SELECT Value1 FROM orc_table_name)
    

    【讨论】:

      【解决方案2】:
      INSERT INTO orc_table_name(field1,field2....fieldn)
      select field1,field2... field(n-1),MIN(fieldn) as fieldn
      from other_table_name
      Group By field1,field2...field(n-1)
      

      【讨论】:

      • 这不会避免orc_table_name中的重复行...它只能确保没有从other_table_name中选择重复行。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 2020-10-10
      • 1970-01-01
      • 2018-02-04
      • 2021-08-26
      • 1970-01-01
      相关资源
      最近更新 更多