Sqoop : Truncate SQL Server table before exporting data from Hadoop Sqoop : Truncate SQL Server table before exporting data from Hadoop hadoop hadoop

Sqoop : Truncate SQL Server table before exporting data from Hadoop


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.


Sqoop is not a general query tool, the "eval" functionality is provided only for evaluation purpose and should not be used in production mode. You can always put together simple java code that will do that in a way that is best for your use case.


There is a feature request to implement sqoop --truncate optionhttps://issues.apache.org/jira/browse/SQOOP-1313

Please vote up on that JIRA page if you're interested.