【问题标题】:Importing subset of columns from RDBMS to Hive table with Sqoop使用 Sqoop 将列的子集从 RDBMS 导入 Hive 表
【发布时间】:2018-09-24 18:54:31
【问题描述】:

假设我们有一个名为lastdb 的mysql 数据库和表person。此表包含 4 列,分别称为:id、firstname、lastname、age。

person 表内的行:

1, Firstname, Lastname, 20

我想从这个 mysql person 表中导入数据到具有相同结构的配置单元表中,但只从表 person 的第一列和最后一列导入。因此,在我导入后,配置单元表中的行应如下所示:

1, NULL, NULL, 20

我试过这个 sqoop 命令:

sqoop import --connect jdbc:mysql://localhost:3306/lastdb --table person --username root --password pass --hive-import --hive-database lastdb --hive-table person --columns id,age

但它以这种格式将行导入配置单元表: 1, 20, NULL, NULL

谁能告诉我如何解决这个问题?

【问题讨论】:

  • 为什么这么在意列的顺序?

标签: hadoop hive sqoop


【解决方案1】:

假设您的 MySQL 表中的行是 id, firstname, lastname, age 的值:1, NULL, NULL, 20,,那么运行下面的 sqoop 导入脚本将在 hive person 表中得到您想要的结果。

~]$ sqoop import \
--connect \
jdbc:mysql://localhost:3306/lastdb \
--username=root \
--password=pass \
--query 'select * from person WHERE $CONDITIONS' \
--hive-import \
--hive-table person \
--hive-database lastdb \
--target-dir  /user/hive/warehouse/person -m 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 2018-09-17
    • 1970-01-01
    相关资源
    最近更新 更多