Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqoop import having SQL query with where clause

Tags:

sqoop import --connect jdbc:teradata://192.168.xx.xx/DBS_PORT=1025,DATABASE=ds_tbl_db 
--driver com.teradata.jdbc.TeraDriver 
--username dbc 
--password dbc 
--query 'select * from reason where id>20' 
--hive-import 
--hive-table reason_hive 
--target-dir <hdfs-location> 
-m 1

I got the error:

Query [select * from reason where id>20] must contain '$CONDITIONS' in WHERE clause.

I know there must be a where clause in query for Sqoop.

So, for queries like

select * from reason

I modify it to:

select * from reason WHERE $CONDITIONS

What to do for queries having where clause?

like image 904
Dev Avatar asked Feb 28 '16 08:02

Dev


People also ask

How do you import using Sqoop import command specific columns with where condition?

Run Sqoop Command In order to run this command, open the terminal on your computer and paste above sqoop import command into it and press enter. When you do that, Sqoop import will start importing specific columns from MySQL table and store them into flat files in HDFS.

How do I import a query into Sqoop?

Apache Sqoop can import the result set of the arbitrary SQL query. Rather than using the arguments –table, –columns and –where, we can use –query argument for specifying a SQL statement. Note: While importing the table via the free-form query, we have to specify the destination directory with the –target-dir argument.

Can free form SQL queries be used with Sqoop import command if yes then how can they be used?

Free-form Query Imports. Sqoop can also import the result set of an arbitrary SQL query. Instead of using the --table , --columns and --where arguments, you can specify a SQL statement with the --query argument. When importing a free-form query, you must specify a destination directory with --target-dir .

What is the purpose of the $conditions value in the where clause of a Sqoop query?

Sqoop performs highly efficient data transfers by inheriting Hadoop's parallelism. To help Sqoop split your query into multiple chunks that can be transferred in parallel, you need to include the $CONDITIONS placeholder in the where clause of your query.


1 Answers

You have to add AND \$CONDITIONS

--query "select * from reason where id>20 AND \$CONDITIONS"

Please refer Sqoop documentation .

like image 174
vinayak_narune Avatar answered Sep 29 '22 07:09

vinayak_narune