【问题标题】:Using sqoop incremental update for updating Hive table使用 sqoop 增量更新更新 Hive 表
【发布时间】:2017-05-12 06:41:57
【问题描述】:

我正在尝试根据 mysql 表中的记录更新配置单元表。

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,将 mysql 表中的 department_id 8 的最后一条记录导入到 hive 表中,使用 sqoop 中的增量更新。

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 表中的部门 ID 为 8 的额外记录没有更新到 hive 表中。

请建议我哪里出错了。

【问题讨论】:

  • 命令对我来说似乎不错。您可以在 swoop 命令末尾添加--verbose 以查看扩展日志并查看是否发现任何错误?
  • @devツ 我注意到一些奇怪的事情,当我将映射器的数量添加为 10 (--m 10) 时,department_id 为 8 的额外记录在 hive 表中插入了两次,并且--m 6,记录插入正确。
  • hive 表中是否有部门 _id 字符串?分享--verbose之后的完整日志

标签: mysql hadoop hive sqoop


【解决方案1】:

我不知道我们是否正在研究 itversity 实验室。好吧,我已经使用下面的代码完成了这件事。也许这对你也有用。

首先在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

【讨论】:

    猜你喜欢
    • 2016-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多