1 建表语法
create table if not exists tb_name(
列的属性 数据类型 ,
列的属性 数据类型…
)
row format delimited fields terminated by “分隔符” ;
2 什么是分区表 为什么有分区表
分区表就是使用分区字段对数据进行分区,方便快速查找数据。
当数据量很大时,一张表已经不适合装载全部数据,
同时很多场景的查询操作都是对部分数据的查询,
这时用分区表会节省很多时间
3 创建分区表 二级分区表 导入数据
create table if not exists tb_name(
列的属性 数据类型 ,
列的属性 数据类型…
)
partitioned by (分区字段 数据类型)
row format delimited fields terminated by “分隔符” ;
create table if not exists tb_name(
列的属性 数据类型 ,
列的属性 数据类型…
)
partitioned by (分区字段 数据类型,分区字段 数据类型)
row format delimited fields terminated by “分隔符” ;
import table 表名 from hdfs中文件路径
4 数据导入方式总结 *****
1)直接将数据文件上传到对应的表的目录下
hdfs dfs -put 数据文件 hdfs中表的目录
2)使用命令导入本地文件
load data local inpath “文件目录” into table 表名 ;
3)使用命令导入HDFS文件到表中
load data inpath “hdfs中数据目录” into table 表名 ;
4)建表的时候指定表的位置
create table if not exists 表名(
列的属性 数据类型 ,
列的属性 数据类型…
)
row format delimited fields terminated by “,”
location “hdfs中数据目录”;
5)使用insert 方式插入数据
into是追加
建表 insert into table 表名 select … from …
overwrite是覆盖
insert overwrite table 表名 select … from …
6)import table 表名 from hdfs中文件路径
5 导出方式总结
1)导出到本地文件系统
insert overwrite local directory
insert overwrite local directory ‘本地路径’
row format delimited fields terminated by ‘分隔符’
select … from …;
2)导出到HDFS
导出到本地文件系统少个local
insert overwrite directory
insert overwrite directory ‘hdfs路径’
row format delimited fields terminated by ‘分隔符’
select … from …;
3)导出到hive的另一张表中
insert into table 表名
[partition(…)]
select … from …;
4)使用hive的-e和-f
hive –e “select … from …” >>文件路径
hive –f 文件名(里面是sql语句) >> 文件路径
6 管理查询几种语法
select … from 表名 where … and|or|like …;
select … from …(right|left|full) join … on …;
select … from … group by … having… order by… limit…;
select … from … where … is (not) null;