我尝试将所有使用 sqoop 的表导入其中一个目录。但是其中一个表没有主键。这是我执行的代码。
sqoop import-all-tables --connect "jdbc:mysql://quickstart.cloudera/retail_db"
--username=retail_dba
--password=cloudera
--warehouse-dir /user/cloudera/sqoop_import/
我收到以下错误:
Error during import: No primary key could be found for table departments_export. Please specify one with --split-by or perform a sequential import with '-m 1'.
通过观察 sqoop import without primary key in RDBMS
我知道我们可以只使用 --split-by
进行单个表导入。有没有一种方法可以为 指定
命令。有没有一种方法可以在没有主键的情况下使用多个映射器进行多表导入。--split-by
>导入所有表
最佳答案
你需要使用--autoreset-to-one-mapper :
没有主键的表将使用一个映射器导入,而其他具有主键的表将使用默认映射器导入(4 - 如果未在 sqoop
命令中指定)
正如@JaimeCr 所说,您不能使用
--split-by
与import-all-tables
但这只是 sqoop 指南中您遇到错误的引述:If a table does not have a primary key defined and the
--split-by> <col>
is not provided, then import will fail unless the number of mappers is explicitly set to one with the--num-mappers 1
or--m 1
option or the--autoreset-to-one-mapper
option is used.选项
--autoreset-to-one-mapper
通常与import-all-tables
一起使用自动处理模式中没有主键的表的工具。sqoop import-all-tables --connect "jdbc:mysql://quickstart.cloudera/retail_db" \ --username=retail_dba \ --password=cloudera \ --autoreset-to-one-mapper \ --warehouse-dir /user/cloudera/sqoop_import/
关于import - 使用 Sqoop 导入表时出现主键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38669301/