Create an internal table:
create table hive_1_1(id string, name string, gender string)
row format delimited fields terminated by ‘,’
stored as textfile;
Create an out table:
create external table hive_1_1(id string, name string, gender string)
row format delimited fields terminated by ‘,’
stored as textfile;
Load data from local computer:
load data local inpath ‘/home/hadoop/hive-0.13.1/student.txt’ into table hive_1_1;
Load data and overwrite:
load data local inpath ‘/home/hadoop/hive-0.13.1/student.txt’ overwrite into table hive_1_1;
Load data from HDFS. It will move the file from HDFS to hive directory in HDFS.
load data local inpath ‘/user/hive/data/student.txt’ into table hive_1_1;
Delete table:
drop table hive_1_1; //hive_1_1是内部表,只删除schema与HDFS上的数据
drop table hive_1_2; //hive_1_2是外部表,只删除schema, HDFS上的数据还在
Create a table with 2 partitions. Partition should be before row. Partition field shouldn’t be showed in table field.
create table partition_table(
name string,
salary float,
gender string,
level string
)
partitioned by (dt string, dep string)
row format delimited fields terminated by ‘,’
stored as textfile;
Load data into partition table:
load data local inpath [overwrite] ‘/home/hadoop/hive-0.13.1/emp.log’ into table partition_table partition(dt=’2014-04-01′,dep=’R&D’);
List the partition table:
show partitions partition_table;