Overwriting Partitioned Data in Hive

Earlier posts on this site addressed the most of the use cases for Hive Partitioning. There will always be some questions when it comes to implementation and new types of needs. In this post, we’ll go through how to replace existing partitioned data in HDFS subdirectories that have already been created.

Syntax for Static Partitioning:
     LOAD DATA LOCAL INPATH ‘Location’
     OVERWRITE INTO TABLE <TableName>
     PARTITION (Partition_Specification);

Example:
    LOAD DATA LOCAL INPATH ‘Desktop/Docs/UK_Cities.txt’
    OVERWRITE INTO TABLE CitiesList
    PARTITION (Country=’UK’);

Syntax for Dynamic Partitioning:
    INSERT OVERWRITE INTO <TableName> PARTITION(Partioned_Column)
    SELECT * FROM <SourceTable>;

Example:

    INSERT OVERWRITE INTO TownsList_Dynamic PARTITION(Country)
    SELECT * FROM TownsList;

I hope you found this post useful.

Please do subscribe for more interesting updates.

 

One comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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