To insert data into a table you use a familiar ANSI SQL statement. A simple example
shows you have to accomplish this basic task.
To insert data into an ACID table, use the Optimized Row Columnar (ORC) storage
format. To insert data into a non-ACID table, you can use other Hive-supported formats. You
can specify partitioning as shown in the following syntax:INSERT INTO TABLE
tablename [PARTITION (partcol1=val1, partcol2=val2 ...)] VALUES values_row [,
values_row...]
where
values_row
is (value [, value])
.
A value can be NULL or any SQL literal.
-
Create an ACID table to contain student information.
CREATE TABLE students (name VARCHAR(64), age INT, gpa DECIMAL(3,2));
-
Insert name, age, and gpa values for a few students into the table.
INSERT INTO TABLE students VALUES ('fred flintstone', 35, 1.28), ('barney rubble', 32, 2.32);
-
Create a table called pageviews and assign null values to columns you do not want to
assign a value.
CREATE TABLE pageviews (userid VARCHAR(64), link STRING, origin STRING) PARTITIONED BY (datestamp STRING) CLUSTERED BY (userid) INTO 256 BUCKETS;
INSERT INTO TABLE pageviews PARTITION (datestamp = '2014-09-23') VALUES ('jsmith', 'mail.com', 'sports.com'), ('jdoe', 'mail.com', null);
INSERT INTO TABLE pageviews PARTITION (datestamp) VALUES ('tjohnson', 'sports.com', 'finance.com', '2014-09-23'), ('tlee', 'finance.com', null, '2014-09-21');
The ACID data resides in the Hive warehouse.