Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqoop : Truncate SQL Server table before exporting data from Hadoop

We are using Sqoop to export data from the hive to SQL Server. The new data is always appended to the existing data in SQL Server.

Is it possible to truncate the SQL Server table via Sqoop before starting the export?

like image 306
ganeshran Avatar asked Feb 17 '26 02:02

ganeshran


1 Answers

You can use sqoop eval to execute arbitrary SQL on the database. This will allow you to truncate the table without "leaving" Sqoop. For example:

sqoop eval --connect 'jdbc:sqlserver://1.1.1.1;database=SomeDatabase;username=someUser;password=somePassword' --query "TRUNCATE TABLE some_table"

sqoop export --connect 'jdbc:sqlserver://1.1.1.1;database=SomeDatabase;username=someUser;password=somePassword' --export-dir /path/to/someTable/on/HDFS --table some_table --fields-terminated-by \001

--fields-terminated-by \001 assumes that the Hive table is using the default delimiters.

like image 58
Daniel Koverman Avatar answered Feb 19 '26 08:02

Daniel Koverman