Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export HDFS file with custom delimiter into Mysql via Sqoop

  • I have file like this:

    1^%~binod^*~1^%~ritesh^*~1^%~shisir^*~1^%~budhdha^*~1^%~romika^*~1^%~rubeena^*~
    
  • Where --input-fields-terminated-by '^%~' --input-lines-terminated-by '^*~'.

  • I tried to export via command:

    sqoop export --connect jdbc:mysql://localhost/sqoop --username root -P --table makalu --export-dir sqoop/makalu --input-fields-terminated-by '^%~' --input-lines-terminated-by '^*~'
    
  • But it writes a single line of:

id|name
1|%~binod

in MySQL.

  • Now my question is what would be the command to solve this scenario.
like image 728
RaiBnod Avatar asked Sep 29 '22 20:09

RaiBnod


1 Answers

arguments --input-fields-terminated-by and --input-lines-terminated-by accepts single character

when you execute your export command in terminal you can see below warnings

02/03 18:55:21 WARN sqoop.SqoopOptions: Character argument ^%~ has multiple characters; only the first will be used.
15/02/03 18:55:21 WARN sqoop.SqoopOptions: Character argument ^*~ has multiple characters; only the first will be used.

Update:

One thing that I have observed is if lines are terminated other than \n or new line, then its only inserting one record into the database when you export. I tried couple of combination with field and line termination but only in case of line is terminated with \n data is exported into RDBMS table

Even tried with --input-lines-terminated-by and --lines-terminated-by arguments but no luck.

I have tested this on

Cloudera CDH-5.0.0-1
Sqoop version: 1.4.4-cdh5.0.0

Only thing that I'm able to find is this.

like image 174
Prasad Khode Avatar answered Oct 02 '22 14:10

Prasad Khode