我想将 mysql 表同步到 hive 表。因为 orders
表中的记录通常会在不久的将来发生变化。我需要将它们更新到 hive 中。
例如,
- 我将所有 mysql 数据转储到 hive 中
- 日常工作查看
time_update
近1天的变化记录,并更新到hive表中。
我试过如下--incremental lastmodified
sqoop import \
"-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect $DB_URL \
--username $USERNAME \
--password $PASSWORD \
--direct \
--fields-terminated-by '\t' \
--target-dir '/data/hive/' \
--delete-target-dir \
--hive-database $HIVE_DB \
--hive-table $HIVE_TABLE \
--hive-import \
--hive-overwrite \
--create-hive-table \
--query 'select * from '$HIVE_TABLE' where $CONDITIONS' \
--split-by id \
-m 6 \
--merge-key id \
--incremental lastmodified \
--check-column time_update \
--last-value "2019-01-01 21:00:00"
出现错误 ——不支持配置单元导入的增量 lastmodified 选项。请删除参数 --incremental lastmodified。
没有 --incremental lastmodified option
的正确方法是什么。
最佳答案
首先,您必须删除 --delete-target-dir 和 --create-hive-table 参数,因为在增量导入中,目标目录将保留为所以 --delete-target-dir 不能与 --incremental 参数一起使用。此外,hive-table 应该只创建一次,因此您必须删除 --create-hive-table 参数并在具有相同模式的 hive 中手动创建 hive 表,获取该模式的位置并将其用作 --target-dir。
sqoop import \
--connect <<db_url>> \
--username <<username>> \
--password <<password>> \
--direct \
--fields-terminated-by '\t' \
--hive-database <<hive_db>> \
--hive-table <<hive_table>> \
--hive-import \
--hive-overwrite \
--query 'select * from <<db_table>> where $CONDITIONS' \
--split-by product_id \
-m 6 \
--merge-key product_id \
--incremental lastmodified \
--check-column timedate \
--last-value 0 \
--target-dir /user/hive/warehouse/problem5.db/products_hive (<<hive_table_location>>)
如果不成功请告诉我。
关于mysql - 如何将 mysql 表同步到 hive 表? (不支持 sqoop --incremental lastmodified 配置单元导入),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54141213/