我正在尝试根据 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,使用sqoop中的增量更新将mysql表中department_id 8的最后一条记录导入到hive表中。
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 表中。
请告诉我哪里出错了。
最佳答案
我不知道我们是否正在大学实验室工作。好吧,我已经使用下面的代码完成了这件事。也许这也适合你。
首先在hive中加载数据
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
关于mysql - 使用sqoop增量更新更新Hive表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41354296/