0

如果我有多个类似的表,例如:

表 A "users":,列:user_name, user_id, user_address, etc etc

表 B:"customers"列:customer_name, customer_id, customer_address, etc etc

表 C:"employee"列:employee_name, employee_id, employe_address, etc etc

是否可以使用 Sqoop 将三个表导入到一个 HBase 或 Hive 表中?所以导入后,我有一个 HBase 表包含表 A、B、C 中的所有记录?

4

1 回答 1

7

如果表格以某种方式相关,那绝对是可能的。在 Sqoop 中可以使用自由形式的查询来做到这一点。在这种情况下,自由格式查询将是一个联接。例如,当导入 Hive 时:

sqoop import --connect jdbc:mysql:///mydb --username hue --password hue --query "SELECT * FROM users JOIN customers ON users.id=customers.user_id JOIN employee ON users.id = employee.user_id WHERE \$CONDITIONS" --split-by oozie_job.id --target-dir "/tmp/hue" --hive-import --hive-table hive-table

同样,对于 Hbase:

sqoop import --connect jdbc:mysql:///mydb --username hue --password hue --query "SELECT * FROM users JOIN customers ON users.id=customers.user_id JOIN employee ON users.id = employee.user_id WHERE \$CONDITIONS" --split-by oozie_job.id --hbase-table hue --column-family c1

所有这一切的关键因素是提供的 SQL 语句:

SELECT * FROM users JOIN customers ON users.id=customers.user_id JOIN employee ON users.id = employee.user_id WHERE \$CONDITIONS

有关自由格式查询的更多信息,请查看http://sqoop.apache.org/docs/1.4.4/SqoopUserGuide.html#_free_form_query_imports

于 2013-12-23T20:34:11.063 回答