Truncate Data From A Partition- Apache Hive

TRUNCATE is a term that SQL developers are familiar with because it is a commonly used command. However, it is used at the table level when the entire data in a table needs to be deleted. It is feasible to truncate a set of partitioned data in Hive, and we’ll show you how in this post.

TRUNCATE [TABLE] table_name [PARTITION partition_spec];

TRUNCATE TABLE AllUniversities PARTITION (Country=’ÚK’)
In the above example, all the rows will be deleted that are in country UK partition. The rows will be trashed if the filesystem Trash is enabled, otherwise they are deleted.

Please note the following points:

  • Currently the target table must be a native/managed table else you’ll get an exception.
  • For truncating many partitions at once, the user can supply partial partition specification as shown below:

          (partition_column = partition_col_value, partition_column = partition_col_value, …)

  • If no partition specification is supplied, the table’s entire data in all partitions is deleted.

Hope you find this article helpful.

Please follow us for more interesting updates.

One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s