2

I tried to import all tables using the sqoop into one of the directories.But one of the tables has no primary key.This is the code I executed.

sqoop import-all-tables --connect "jdbc:mysql://quickstart.cloudera/retail_db" 
--username=retail_dba 
--password=cloudera 
--warehouse-dir  /user/cloudera/sqoop_import/

I am getting the following error:

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'.

By seeing sqoop import without primary key in RDBMS

I understood that we can just use --split-by for a single table import.Is there a way i can specify --splity-by for Import-all-tables command. Is there a way I can use more than one mapper for the multi-table import with no primary-key.

Community
  • 1
  • 1
Priyaranjan
  • 407
  • 3
  • 9
  • 16

1 Answers1

8

you need to use --autoreset-to-one-mapper:

Tables without primary key will be imported with one mapper and others with primary key with default mappers (4 - if not specified in sqoop command)

  • As @JaimeCr said you can't use --split-by with import-all-tables but this just a quote from sqoop guide in context of error you got:

    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.

  • The option --autoreset-to-one-mapper is typically used with the import-all-tables tool to automatically handle tables without a primary key in a schema.

    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/
    
Ronak Patel
  • 3,819
  • 1
  • 16
  • 29