QBoard » Big Data » Big Data - Data Ingestion Tools : Sqoop, Flume, Kafka, Nifi.. » Sqoop import without primary key in RDBMS

Sqoop import without primary key in RDBMS

  • Can I import RDBMS table data (table doesn't have a primary key) to hive using sqoop? If yes, then can you please give the sqoop import command.

    I have tried with sqoop import general command, but it failed.

      October 5, 2020 1:25 PM IST
    0
  • You can import data from RDBMS into hive without Primarykey.

    First you need to create a table in hive.After that you need to write the following code:

    sqoop import \
        --connect jdbc:mysql://localhost/test_db \
        --username root \
        --password **** \
        --table <RDBMS-Table-name> \
        --target-dir /user/root/user_data \
        --hive-import \ 
        --hive-table <hive-table-name> \
        --create-hive-table \
        -m 1 (or) --split-by <RDBMS-Column>
     
      October 5, 2020 2:54 PM IST
    0
  • Use the following in your command:

    --autoreset-to-one-mapper

    Import should use one mapper if a table has no primary key and no split-by column is provided. It cannot be used with --split-by <col> option.

      October 5, 2020 2:54 PM IST
    0
  • In the first scenario using 1 Mapper ... If the size of the file is very large this process is going to take more time to respond or might fail. Check the size of the data before using mapper = 1 .
      October 5, 2020 2:55 PM IST
    0
  • If your table has no primary key defined then you have to give -m 1 option for importing the data or you have to provide --split-by argument with some column name, otherwise it gives the error: 

    ERROR tool.ImportTool: Error during import: No primary key could be found for table <table_name>. Please specify one with --split-by or perform a sequential import with '-m 1'

    then your sqoop command will look like

    sqoop import \
        --connect jdbc:mysql://localhost/test_db \
        --username root \
        --password **** \
        --table user \
        --target-dir /user/root/user_data \
        --columns "first_name, last_name, created_date"
        -m 1

    or

    sqoop import \
        --connect jdbc:mysql://localhost/test_db \
        --username root \
        --password **** \
        --table user \
        --target-dir /user/root/user_data \
        --columns "first_name, last_name, created_date"
        --split-by created_date
     
      October 5, 2020 2:57 PM IST
    0