hive基础知识

hive内部表和外部表的区别
内部表:创建表时,默认创建的就是内部表,删除时会删除元数据(数据库中tabs中的表数据)和数据内容(hdfs dfs -ls /user/hive/warehouse/数据库名.db/表名),都会删除掉,所以内部表多用于临时表和中间表
外部表:创建时需要一个关键字external,删除时,只删除元数据,不删除数据内容,所以多用于数据源。

hive查询:union all 和union的区别
union:查询结果及合并,并且去除重复行:
union all:查询结果集合并,不删除重复行;

hive:分区关键字partitioned 并且分区字段可以不用真正的字段,查询的时候却可以用这个字段查询,比如where year=2018
create table if not exists student(
id bigint comment ‘studentId’,
name String
)
partitioned by(year String)
row format delimited fields terminated by ‘\t’

分区加载数据时:
load data local inpath ‘/home/data/student’ into table student partition(year=’2018’);

显示分区:
show partitions student ;

猜你喜欢

转载自blog.csdn.net/lkpklpk/article/details/81047945