【问题标题】:Sqoop incremental import and update does not workSqoop 增量导入和更新不起作用
【发布时间】:2018-07-12 02:08:47
【问题描述】:

如何更新 HDFS 文件中的数据,类似于 MySQL 表中的数据? 我查了互联网,但所有给出的例子都是 --incremental lastmodified 例子。

在我的情况下,我的 MySQL 表不包含日期或时间戳列。 如何更新 HDFS 文件中的数据,类似于 MySQL 表中不包含日期列的数据?

我有如下的 MySQL 表

mysql> select * from employee;
+----+--------+--------+------+-------+-----------+
| id | name   | gender | age  | state | language  |
+----+--------+--------+------+-------+-----------+
|  1 | user1  | m      |   25 | tn    | tamil     |
|  2 | user2  | m      |   41 | ka    | tamil     |
|  3 | user3  | f      |   47 | kl    | tamil     |
|  4 | user4  | f      |   52 | ap    | telugu    |
|  5 | user5  | m      |   55 | ap    | telugu    |
|  6 | user6  | f      |   43 | tn    | tamil     |
|  7 | user7  | m      |   34 | tn    | malayalam |
|  8 | user8  | f      |   33 | ap    | telugu    |
|  9 | user9  | m      |   36 | ap    | telugu    |

我使用以下命令导入到 HDFS。

[cloudera@localhost ~]$ sqoop import --connect jdbc:mysql://localhost:3306/mydatabase --username root --table employee --as-textfile --target-dir hdfs://localhost.localdomain:8020/user/cloudera/data/employee 

数据按预期导入。

[cloudera@localhost ~]$ hadoop fs -ls /user/cloudera/data/employee/
Found 6 items
-rw-r--r--   3 cloudera cloudera          0 2017-08-16 23:57 /user/cloudera/data/employee/_SUCCESS
drwxr-xr-x   - cloudera cloudera          0 2017-08-16 23:56 /user/cloudera/data/employee/_logs
-rw-r--r--   3 cloudera cloudera        112 2017-08-16 23:56 /user/cloudera/data/employee/part-m-00000
-rw-r--r--   3 cloudera cloudera        118 2017-08-16 23:56 /user/cloudera/data/employee/part-m-00001
-rw-r--r--   3 cloudera cloudera        132 2017-08-16 23:56 /user/cloudera/data/employee/part-m-00002
-rw-r--r--   3 cloudera cloudera        136 2017-08-16 23:56 /user/cloudera/data/employee/part-m-00003

现在我更新了 mysql 表中的值和插入值。但此表不包含日期列。

mysql> update employee set language = 'marathi' where id >= 8;
mysql> insert into employee (name,gender,age,state,language from people) values('user11','f','25','kl','malayalam');

我知道新插入的值可以使用 --check-column、增量追加和 --last-value 插入到 hdfs。

但是如何更新 hdfs 中 mysql 表第 8 行和第 9 行的值,这些值已更新为“马拉地语”?此外,我的员工表不包含日期或时间戳列。

【问题讨论】:

    标签: mysql hadoop hdfs sqoop


    【解决方案1】:

    对于新插入的行,你总是可以使用:

    --incremental append --check-column id --last-value 9

    但是为了从没有 updated_at 列的表中获取更新,我认为这是不可能的。如果您的表非常小,那么可能每次都进行一次完全转储。

    或者,如果您以某种方式可以跟踪自上次导入以来所有 id 的更新情况,那么假设您知道 id 7, 3, 4 and 8 自上次导入以来已更新,您可以使用最少的更新 id 并用作 --last-value。所以你的配置将是:

    --incremental append --check-column id --last-value 3 --merge-key id

    其中--merge-key id 将告诉sqoop 到merge 基于id 列的旧增量数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-27
      • 2016-12-22
      • 1970-01-01
      相关资源
      最近更新 更多