Static Partitions in Hive

For detailed information about “Static Partitions” please click here.

In this lesson, we’ll see how to create the static partition. Consider the below data for the exercise. You can download the files from here.

Data sample is given here.

File: UK_Cities.txt
1     Aberdeen               UK
2     Armagh                  UK
3     Bangor                   UK
4     Bath                        UK
5     Belfast                    UK
6     Birmingham          UK
7     Bradford                UK
8     Brighton & Hove  UK
9     Bristol                    UK
10   Cambridge            UK

File: US_Cities.txt
1      New York             US
2      Los Angeles         US
3      Chicago                US
4      Houston               US
5      Phoenix                US
6      Philadelphia        US
7      San Antonio        US
8      San Diego            US
9      Dallas                   US
10    San Jose               US

Implementation:
CREATE TABLE CitiesList(Id INT, Name STRING)
PARTITIONED BY (Country STRING);

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

LOAD DATA LOCAL INPATH ‘Desktop/Docs/US_Cities.txt’
OVERWRITE INTO TABLE CitiesList
PARTITION (Country=’US’);

StaticPartition_Scrnsht

Let’s have a look at how the data is saved in the file browser using Hue.

Static_Hue
Static_Hue2

Hope you find this article helpful.

Please subscribe for more interesting updates.

5 comments

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