4

In the sqoop statements, is there a provision where we can select only specific columns from oracle side?

1 : works

sqoop import --target-dir /tmp/customers --query "SELECT * FROM schema1.customers where item>=1234 and \$CONDITIONS" --connect jdbc:oracle:thin:@server1.companyxyz.com:4567/prod --username xyz --password xyz --hive-drop-import-delims -m 8 --fields-terminated-by , --escaped-by \\ --split-by cust_id

2 : fails

sqoop import --target-dir /tmp/customers --query "SELECT cust_id, name, address, date, history, occupation FROM schema1.customers where item>=1234 and \$CONDITIONS" --connect jdbc:oracle:thin:@server1.companyxyz.com:4567/prod --username xyz --password xyz --hive-drop-import-delims -m 8 --fields-terminated-by , --escaped-by \\ --split-by cust_id
Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
sharp
  • 2,140
  • 9
  • 43
  • 80

2 Answers2

8

you can use --columns --table --where clauses to achieve it. Sample is below:

sqoop import  
--connect jdbc:oracle:thin:@server1.companyxyz.com:4567/prod/DATABASE=schema1
--username xyz 
--password xyz 
--table customers
--columns cust_id, name, address, date, history, occupation  
--where item>=1234 
--target-dir /tmp//customers
--m 8
--split-by cust_id
--fields-terminated-by , 
--escaped-by \ 
--hive-drop-import-delims  
--map-column-java
  cust_id=string, name=string, address=string, date=string, history=string, occupation=string
Ram Manohar
  • 1,004
  • 8
  • 18
  • for the --columns I put "cust_id, name, ...etc" and same for the --where and it worked. Thanks! – sharp Dec 04 '15 at 16:43
0

I suspect SELECT cust_id, name, address, date, history, occupation FROM schema1.customers where item>=1234 is incorrect. I tried all possible scenarios. Try running it in your database. Also have you dropped directory /tmp/customers before running your second statement. You should paste the errors as well.

sqoop import \
     --connect "jdbc:mysql://sandbox.hortonworks.com:3306/retail_db" \
     --username=retail_dba \
     --password=hadoop \
     --query "select department_id, department_name from departments where \$CONDITIONS" \
     --target-dir /user/root//testing \
     --split-by department_id \
     --outdir java_files \
     --hive-drop-import-delims \
     -m 8 \
     --fields-terminated-by , \
     --escaped-by '\'
Durga Viswanath Gadiraju
  • 3,896
  • 2
  • 14
  • 21