连接客户端:beeline -u jdbc:hive2://localhost:10000 -n root
文章目录
建表
create table t_course(id string,name string,amout float)
row format delimited
fields terminated by ',';
分区表
1.建表
同一目录下的子目录不同
create table t_pv_log(ip string,commit_time string)
partitioned by (day string)
row format delimited fields terminated by ',';
注意:分区字段不能是表定义中的已存在字段,因为它已经是表中的伪字段了。
2.导数据
load data local inpath '/root/hivetest/pv.log.15' into table partition(day='20190915') ;
不加local 是从hdfs上导入。
本地文件导入表示复制
hdfs文件导入表示移动
CTAS建表
1.通过已存在的表来建表:
create table t_pv_log2 like t_pv_log;
desc t_pv_log2;
表结构和原表一致,但没有数据。
2.建表的同时插入数据:
create tabe t_pv_log3 as select * from t_pv_log where ip='192.168.1.13';
有结构+有数据
Join表
--1.内连接(笛卡尔积)
select a.*,b.* from t_a a inner join t_b b ;
--2.内连接(指定连接对应条件)
select a.*,b.* from t_a a join t_b b on a.name=b.name;
--3.左外连接
select a.*,b.* from t_a a left outer join t_b b on a.name=b.name;
--4.右外连接
select a.*,b.* from t_a a right outer join t_b b on a.name=b.name;
--5.全外连接
select a.*,b.* from t_a a full outer join t_b b on a.name=b.name;
--6.左半连接
select a.* from t_a a left semi join t_b b on a.name=b.name