【发布时间】: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 行的值,这些值已更新为“马拉地语”?此外,我的员工表不包含日期或时间戳列。
【问题讨论】: