1、创建表:
create table if not exists employee (eid int,name String,salary String,destination String)
comment ‘employee details‘
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘\t‘
LINES TERMINATED BY ‘\n‘
STORED AS TEXTFILE;
如果增加分区必须在创建表的时候就创建分区,不然就会报错,创建分区的命令>partition by ‘根据哪个字段分区’,
create table employee (id int, name String, dept String)
PARTITIONED BY (year int)
ROW FORMAT delimited
fields terminated by ‘\t‘
lines terminated by ‘\n‘
stored as textfile;
stored as textfile文件格式,文件格式在hive中有三种: textfile、Sequencefile(序列化文件,学hadoop的都会知道啦)、Rcfile。
2、添加数据到表中
LOAD DATA LOCAL INPATH ‘/usr/hadoop/hive/sample.txt‘
OVERWRITE INTO TABLE employee;
如果table是个分区表则必须在hql中指定分区
LOAD DATA LOCAL INPATH ‘/usr/hadoop/hive/sample.txt‘
OVERWRITE INTO TABLE employee partition(year=2012);(虽然已经实现了分区,但还未明白为什么分区后所有的数据都根据分区条件发生变化)
LOAD DATA:加载数据; LOCAL:本地数据 INPATH:文件的地址 OVERWRITE:覆盖表中的数据 加overwrite是重写表的数据,不加是追加数据
插入表数据:insert into employee(eid,name) values (1208,‘jack‘);hive只支持插入不支持修改和删除
3、重命名表名字
ALTER TABLE employee RENAME TO emp;
原文:https://www.cnblogs.com/litstar/p/12133455.html