在导入之前,是否可以在新文件上编写带过滤器的Sqoop增量导入?

时间:2018-02-01 05:47:51

标签: hadoop merge hdfs sqoop

我的疑问是,Say,我有一个文件A1.csv在sql-server表上有2000条记录,我将这些数据导入hdfs,那天晚些时候我已经在sql-server表的同一个文件中添加了3000条记录。 现在,我想为hdfs上添加的第二块数据运行增量导入,但是,我不希望导入完整的3000条记录。根据我的必要性,我只需要输入一些数据,例如1000条记录,其中某些条件要作为增量导入的一部分导入。

有没有办法使用sqoop incremental import命令?

请帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

您需要一个唯一键或一个Timestamp字段来标识增量,这是您案例中的新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 for 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