Monday 2 May 2022

Sqoop: difference between --target-dir and --warehouse-dir

When you execute ‘sqoop import’ command by specifying the target directory, then the table content is directly copied to the target directory as part files.

 

Example

sqoop import --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" --username "root" --password "cloudera" --table "orders" --target-dir /import_demo_4

Above command import the content of table orders to the folder /import_demo_4

[cloudera@quickstart Desktop]$ hadoop fs -ls /import_demo_4
Found 5 items
-rw-r--r--   1 cloudera supergroup          0 2022-03-31 12:05 /import_demo_4/_SUCCESS
-rw-r--r--   1 cloudera supergroup     741614 2022-03-31 12:05 /import_demo_4/part-m-00000
-rw-r--r--   1 cloudera supergroup     753022 2022-03-31 12:05 /import_demo_4/part-m-00001
-rw-r--r--   1 cloudera supergroup     752368 2022-03-31 12:05 /import_demo_4/part-m-00002
-rw-r--r--   1 cloudera supergroup     752940 2022-03-31 12:05 /import_demo_4/part-m-00003
[cloudera@quickstart Desktop]$

When you execute ‘sqoop import’ command by specifying the warehouse directory, it creates a sub folder with given table name in the ware house directory and import the content to subfolder.

 

Example

sqoop import --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" --username "root" --password "cloudera" --table "orders" --warehouse-dir /import_demo_5

[cloudera@quickstart Desktop]$ hadoop fs -ls /import_demo_5
Found 1 items
drwxr-xr-x   - cloudera supergroup          0 2022-03-31 12:08 /import_demo_5/orders
[cloudera@quickstart Desktop]$ 
[cloudera@quickstart Desktop]$ 
[cloudera@quickstart Desktop]$ hadoop fs -ls /import_demo_5/orders
Found 5 items
-rw-r--r--   1 cloudera supergroup          0 2022-03-31 12:08 /import_demo_5/orders/_SUCCESS
-rw-r--r--   1 cloudera supergroup     741614 2022-03-31 12:08 /import_demo_5/orders/part-m-00000
-rw-r--r--   1 cloudera supergroup     753022 2022-03-31 12:08 /import_demo_5/orders/part-m-00001
-rw-r--r--   1 cloudera supergroup     752368 2022-03-31 12:08 /import_demo_5/orders/part-m-00002
-rw-r--r--   1 cloudera supergroup     752940 2022-03-31 12:08 /import_demo_5/orders/part-m-00003
[cloudera@quickstart Desktop]$


 

Previous                                                    Next                                                    Home

No comments:

Post a Comment