Sqoop导入多个表但不是全部

时间:2016-04-07 19:17:17

标签: hadoop sqoop data-ingestion

我发现的所有搜索都显示了如何导入一个表或推荐import-all-tables。如果我需要db中的440个表中的35个,该怎么办?我可以只编写一个命令并用逗号分隔表,还是必须将它放在脚本中并反复复制并通过命令并每次更改表名?

我想做什么:

echo "Sqoop Import"
--options-file ${path} 
--table tbl1,tbl2,tbl3\
--target-dir ${path}
--m 1\  

我担心我可能要做的事情:

echo "Sqoop Import"
--options-file ${path} 
--table tbl1\
--target-dir ${path}
--m 1

wait 

echo "Sqoop Import"
--options-file ${path} 
--table tbl2\
--target-dir ${path}
--m 1

4 个答案:

答案 0 :(得分:1)

显然,一个sqoop开发人员和你一样。 :)

您可以使用import-all-tables 然后添加--exclude-tables以逗号分隔的表列表,以便从导入过程中排除。

https://sqoop.apache.org/docs/1.4.0-incubating/SqoopUserGuide.html#id1766722

答案 1 :(得分:0)

您还可以使用相同的命令将Hive导入应用为:

sqoop import-all-tables --connect jdbc:mysql://your_ip_address:3306/database_name --driver com.mysql.jdbc.Driver --username root --warehouse-dir temp_dir_for_staging --hive-import --hive-overwrite --hive-database hive_db --exclude-tables list_of_tables_to_be_excluded -m 1

请记住,在Hive中你需要临时区域。

答案 2 :(得分:0)

使用--exclude-tables "table1,table2"选项忽略table1和table2。

不要不要在表名之间添加空格(也称为"table1, table2"

答案 3 :(得分:0)

sqoop import-all-tables --connect jdbc:mysql://localhost/sqoop --username root --password hadoop --target-dir '/Sqoop21/AllTables' --exclude-tables table1,表2