Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Sqoop Import - Need double quotes for string fields, and no double quotes needed for non-string fields

Sqoop Import - Need double quotes for string fields, and no double quotes needed for non-string fields

New Contributor

I am trying to import data from mysql to hdfs. While importing, I need all the string fields to have double quotes and non-string fields with no double quotes.

sqoop import \
  --connect jdbc:mysql://<hostname>:3306/retail_db \
  --username <user> \
  --password <password> \
  --target-dir /user/nikhilvemula/sqoop_import/retail_db/orders_test \
  --num-mappers 1 \
  --query "SELECT * FROM orders WHERE \$CONDITIONS and order_date LIKE '2014-01-%'" \
  --enclosed-by '"' \
  --null-string '\\N' \
  --null-non-string '\\N' \
  --delete-target-dir
Expected: 25876,2014-01-01 00:00:00.0,3414,"PENDING_PAYMENT"
Actual result I got: "25876","2014-01-01 00:00:00.0","3414","PENDING_PAYMENT"






2 REPLIES 2

Re: Sqoop Import - Need double quotes for string fields, and no double quotes needed for non-string fields

New Contributor

@Geoffrey Shelton Okot

Kindly help me out

Re: Sqoop Import - Need double quotes for string fields, and no double quotes needed for non-string fields

New Contributor

Hello,

Your requirement can be fulfilled in two ways.

1. Using the below query.

--query "select order_id, order_date, order_customer_id, concat('\"', order_status, '\"') from orders WHERE \$CONDITIONS and order_date LIKE '2014-01-%'"

2. You can further process your actual output in spark and get your expected output.

Thanks

Don't have an account?
Coming from Hortonworks? Activate your account here