Reply
New Contributor
Posts: 4
Registered: ‎03-24-2017
Accepted Solution

Sqoop import - special characters

All,

Working on importing data from DB2 using sqoop import, it worked fine for the most part except one table, which seemed to have some special characters ( control-M = ^M ) in contents, hence while sqooping, these characters are treated as newline and hence everything after it will be on the next line in the imported files, which will affect all the records after one bad record.

I am unable to guess how to fix the imports? is there any easy way?

Posts: 394
Topics: 11
Kudos: 60
Solutions: 35
Registered: ‎09-02-2016

Re: Sqoop import - special characters

@Freakabhi

 

If your business allows to replace Ctrl+M with something else then I would suggest two steps

 

1. Understand the regexp_replace function

ex: regexp_replace(col2,  '<the char that you want to replce>', '')

 

2. Use --query option instead of --table option in sqoop

 

So you have to use the following method to replace Ctrl+M with something else in your sqoop script

--query "select col1, regexp_replace(col2,  '<the char that you want to replce>', '') from db.table"

Explorer
Posts: 6
Registered: ‎09-20-2017

Re: Sqoop import - special characters

@saranvisa @Freakabhi 

 

I tried the same with Teradata but it throws an error 

 

[Teradata Database] [TeraJDBC 15.10.00.26] [Error 6706] [SQLState HY000] The string contains an untranslatable character.

 

Did i add the parameter right ?

 

PFB my sqoop command

 

sqoop import --connect jdbc:teradata://xx.xx.xx/DATABASE=xxx --username xxx -P --query "SELECT TOP 1000 regexp_replace(load_hash_key_val,'^M',''),regexp_replace(load_hash_data_val,'^M','') FROM db.tble_name  where 1=1 AND \$CONDITIONS" --target-dir /hadoop/test -m1

 

Any suggestions please ?

 

Thanks in advance.

Announcements