Support Questions

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

Is there a way to execute free form query from a file in sqoop?

avatar
New Contributor

Have executed a similar kind of sqoop command as shown below. The free form query mentioned below, I wanted to keep it in a file and run the sqoop command since my real time queries are quite complex and bigger.

Wanted to know, Is there a way to keep the query in a file and execute the sqoop command which will refer the free form query inside the file and execute? like we do for --password-file case. Thanks in advance.

<code>sqoop  import --connect "jdbc:mysql://<localhost>:port" --username "admin" --password-file "<passwordfile>" --query "select * from employee" --split-by employee_id --target-dir "<target directory>" --incremental append --check-column employee_id --last-value 0 --fields-terminated-by "|"
1 REPLY 1

avatar

Hello @Nandan B R!
Maybe the sqoop options work in this case, but, I didn't test it.
https://sqoop.apache.org/docs/1.4.2/SqoopUserGuide.html#_using_options_files_to_pass_arguments

Another way would be to use shell variables and create a script which replaces the --query value by $variable. Or you can try the sqoop 2 using the JDBC Conn
https://sqoop.apache.org/docs/1.99.7/user/connectors/Connector-GenericJDBC.html

Hope this helps!