【问题标题】:Is it possible to write a Sqoop incremental import with filters on the new file before importing?是否可以在导入之前在新文件上编写带有过滤器的 Sqoop 增量导入?
【发布时间】:2018-07-11 09:18:47
【问题描述】:

我的疑问是,比如说,我在 sql-server 表上有一个包含 2000 条记录的文件 A1.csv,我将此数据导入 hdfs,那天晚些时候我在 sql-server 表上的同一个文件中添加了 3000 条记录。 现在,我想为要在 hdfs 上添加的第二块数据运行增量导入,但是,我不想导入完整的 3000 条记录。我只需要根据我的需要导入一些数据,例如,作为增量导入的一部分导入具有一定条件的 1000 条记录。

有没有办法使用 sqoop 增量导入命令来做到这一点?

请帮忙,谢谢。

【问题讨论】:

    标签: hadoop merge hdfs sqoop


    【解决方案1】:

    您需要一个唯一键或时间戳字段来识别增量,即您的案例中的新 1000 条记录。使用该字段,您必须选择将数据引入 Hadoop。


    选项 1

    是使用sqoop增量追加,下面是它的例子

    sqoop import \
    --connect jdbc:oracle:thin:@enkx3-scan:1521:dbm2 \
    --username wzhou \
    --password wzhou \
    --table STUDENT \
    --incremental append \
    --check-column student_id \
    -m 4 \
    --split-by major
    

    参数:

    --check-column (col)  #Specifies the column to be examined when determining which rows to import.
    
    --incremental (mode)      #Specifies how Sqoop determines which rows are new. Legal values for mode include append and lastmodified.
    
    --last-value (value) Specifies the maximum value of the check column from the previous import.
    

    选项 2

    在 sqoop 中使用 --query 参数,您可以将本机 sql 用于 mysql/您连接的任何数据库。

    例子:

    sqoop import \
      --query 'SELECT a.*, b.* FROM a JOIN b on (a.id == b.id) WHERE $CONDITIONS' \
      --split-by a.id --target-dir /user/foo/joinresults
    
    sqoop import \
      --query 'SELECT a.*, b.* FROM a JOIN b on (a.id == b.id) WHERE $CONDITIONS' \
      -m 1 --target-dir /user/foo/joinresults
    

    【讨论】:

    • 那么,使用查询(选项 2)我们可以选择是想要全部 3000 条记录还是仅从中选择 1000 条?
    • 您可以将查询更改为您想要的任何方式,1000 或 2000 行。如果您想要所有记录,只需选择 * 没有任何条件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 2015-08-31
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多