Different ways to insert data into Hive table - Big Data In Real World

Different ways to insert data into Hive table

How to get specific fields from a document in Elasticsearch?
March 29, 2021
How to recursively list files and directories in HDFS?
April 2, 2021
How to get specific fields from a document in Elasticsearch?
March 29, 2021
How to recursively list files and directories in HDFS?
April 2, 2021

There are several different variations and ways when it comes to inserting or loading data into Hive tables. This post will cover 3 broad ways to insert or load data into Hive tables.

Create Table As Select (CTAS)

A table named newtable will be created with the same structure as oldtable and all records from oldtable will also be copied to the newtable. 

create table newtable as select * from oldtable;

 

Load data

Load the data that is available under the local directory – /home/hirw/localdirectory into the table sales.

Note that overwrite is optional and will overwrite the data in the sales table.

load data local inpath '/home/hirw/localdirectory' 
overwrite into table sales;

Below script will load the data that is available in HDFS directory – /user/hirw/hdfsdirectory into the table sales2.

Note that overwrite is optional and will overwrite the data in the sales2 table.

load data inpath '/user/hirw/hdfsdirectory' 
overwrite into table sales2;

 

Insert data

Below is a simple insert statement to insert a row into table Sales. Sales table have 3 columns – id, item and quantity.

insert into sales
values(100, 'Shirt', 3);

Inserting multiple records in to sales tables.

insert into sales
values(100, 'Shirt', 3)
values(200, 'Pants', 2)
values(300, 'Skirt', 4);

Below is a simple insert into a table using select from another table.

insert into table sales2
select id, item, quantity from sales;

 

Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.

Comments are closed.

Different ways to insert data into Hive table
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X