Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
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

avatar
Contributor

@Geoffrey Shelton Okot

Kindly help me out

avatar
Explorer

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