mysql - 如何将 mysql 表同步到 hive 表? (不支持 sqoop --incremental lastmodified 配置单元导入)

标签 mysql import hive sqoop

我想将 mysql 表同步到 hive 表。因为 orders 表中的记录通常会在不久的将来发生变化。我需要将它们更新到 hive 中。

例如,

  1. 我将所有 mysql 数据转储到 hive 中
  2. 日常工作查看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/

相关文章:

mysql - Rails 中的嵌套 SQL 查询

mysql - 在 MYSQL 中查找组中的最新行

Php + MySQL 横幅旋转器按顺序

windows - 如何将 session 导入 MobaXterm?

hive - 在预分区数据之​​上创建外部表

sql - 在 Hive 或 Impala 或 Pig 中通过字符串匹配连接表

hadoop - 如何在一天内用所有时间戳(86400)填充 Hive 表

mysql - 元数据 Excel 文件 : What would the Domain and Range be?

import - 无法从 '_TPU_AVAILABLE' 导入名称 'pytorch_lightning.utilities'

node.js - 错误解析错误: Unexpected token *