使用sqoop增量更新来更新Hive表

时间:2016-12-28 01:43:32

标签: mysql hadoop hive sqoop

我正在尝试根据mysql表中的记录更新hive表。

mysql-table: (table name: delimiter_test)

+---------------+-----------------+
| department_id | department_name |
+---------------+-----------------+
|             2 | Fitness         |
|             3 | Footwear        |
|             4 | Apparel         |
|             5 | Golf            |
|             6 | Outdoors        |
|             7 | Fan Shop        |
|             8 | Test            |
+---------------+-----------------+

hive-table (table name: my_test)

2   Fitness
3   Footwear
4   Apparel
5   Golf
6   Outdoors
7   Fan Shop

我正在尝试使用sqoop,使用department_id 8将mysql表中的最后一条记录导入hive表,并使用sqoop中的incremental-update。

my-sqoop命令:

sqoop import --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" --username xxx --password xxx --table delimiter_test  --hive-import  --hive-table my_test  --split-by department_id  --check-column department_id --incremental append --last-value 7

我没有收到任何错误,但是mysql表中带有department_id 8的额外记录没有更新到hive表中。

请建议我哪里出错了。

1 个答案:

答案 0 :(得分:0)

我不知道我们是否正在研究虚拟实验室。好吧,我使用下面的代码做了这件事。可能这对你也有用。

首先在配置单元中加载数据

sqoop import --connect jdbc:mysql://xxxxx/retail_db --username xxxx --password xxxx \
--table departments --where department_id=2 --hive-import --hive-database poc --hive-table departments_sqoop  \
--target-dir /user/ingenieroandresangel/sqoop/dep_hive --split-by department_id -m 1

然后我使用下面的脚本执行更新:

sqoop import --connect jdbc:mysql://xxxxxx/retail_db --username xxxxx --password xxxx \
--table departments --where 'department_id>=2' --hive-import --hive-database poc --hive-table departments_sqoop  --incremental append \
--check-column department_id --last-value 2 --target-dir /user/ingenieroandresangel/sqoop/dep_hive --split-by department_id -m 1