Created on 04-27-2017 08:52 PM - edited 09-16-2022 04:31 AM
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?
Created 04-28-2017 07:59 AM
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"
Created 04-28-2017 07:59 AM
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"
Created 09-22-2017 05:24 AM
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.
Created 08-28-2019 05:50 AM
Hi,
Can you let me know how to replace a set of special characters in the sqoop import query.
I need to replace the column value if it contains any of the special characters(|,",^,$,% etc) in it
Thank You
Vijay
Created 12-13-2023 12:12 AM
use --hive-drop-import-delims |tr -d '\r'