You are on page 1of 2

Static Partitioning in Hive

You need to download the “Data Files” given below the video.
Note:​ You should download the file to your local system if you are using Quickstart VM. If you
are using Hue, you can upload the file to HDFS as shown in the video in previous session.

1. To create table use the below query

CREATE​ ​TABLE​ ​IF​ ​NOT​ ​EXISTS​ customer_partitioned(customer_fname


varchar​(​64​),customer_lname ​varchar​(​64​),customer_addr ​string​,city
varchar​(​64​))PARTITIONED ​BY​ (country ​VARCHAR​(​64​),state ​VARCHAR​(​64​))
ROW​ ​FORMAT​ ​DELIMITED
FIELDS​ ​TERMINATED​ ​BY​ ​','
STORED​ ​AS​ TEXTFILE;

2. To load data into the table use the below command

LOAD​ ​DATA​ INPATH ​'yourfilepath'


INTO​ ​TABLE​ customer_partitioned
PARTITION​(country=​'usa'​, state=​'az'​);
Note: If you are using the VM and data is on your local machine use the below command

LOAD​ ​DATA​ ​LOCAL​ INPATH ​'yourfilepath'


INTO​ ​TABLE​ customer_partitioned
PARTITION​(country=​'usa'​, state=​'az'​);
Also, note that you will need to provide path to the data file of the particular country and state
which you mention in the last line. Similarly you can load data for other countries also.

You might also like