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

使用hcatalog进行Sqoop增量导出?

  •  1
  • VoodooChild  · 技术社区  · 8 年前

    有没有一种方法可以使用sqloop进行增量导出?我正在为sqoop使用Hcatalog集成。我尝试使用用于增量导入的--lastvalue,--check列选项,但sqloop给我的错误是这些选项无效。

    2 回复  |  直到 8 年前
        1
  •  2
  •   gkc123    8 年前

    我还没有看到增量sqloop导出参数。您可以尝试的另一种方法是在hive中创建一个contol_table,在其中保存表名&上次导出的时间戳。

    create table if not exists control_table (
     table_name  string,
     export_date timestamp
    );
    
    insert into control_table 'export_table1' as table_name, from_unixtime(unix_timestamp()) as export_date from control_table;
    

    如果export_table1是要增量导出的表,并且假设If已经执行了以上两条语句。

    --execute below at once   
    --get the timestamp when the table was last executed
    create temporary table control_table_now as select table_name, max(export_date) as last_export_date from control_table group by table_name;
    
    --get incremental rows
    create table new_export_table1 as select field1, field2, field3, .... timestamp1 from export_table1 e, control_table_now c where c.table_name = 'export_table1' and e.timestamp1 >= c.last_export_date;
    
    --append the control_table for next process
    insert into control_table 'export_table1' as table_name, from_unixtime(unix_timestamp()) as export_date from control_table;
    

    现在,导出使用sqloop export命令增量创建的new_export_table1表。

        2
  •  0
  •   Sandesh Jain    8 年前

    默认情况下,sqoop不支持hcatalog集成的增量更新,当我们尝试时,会出现以下错误

    导入的附加模式与HCatalog不兼容。请删除参数--追加模式 位于org.apache.sqoop.tool.BaseSqoopTool.validateHCatalogOptions(BaseSqoopTool.java:1561)

    您可以使用查询选项使其工作。如中所述 this hortonworks document