标签:通过 like AC change ati 使用场景 for exist 中间
创建一个数据库,数据库在HDFS上的默认存储路径是/user/hive/warehouse/*.db
create database 库名;
避免要创建的数据库已经存在错误,增加if not exists判断。(标准写法)
create database if not exists 库名;
创建一个数据库,指定数据库在HDFS上存放的位置
create database db_hive2 location ‘/db_hive2.db‘;
用户可以使用ALTER DATABASE命令为某个数据库的DBPROPERTIES设置键-值对属性值,来描述这个数据库的属性信息。数据库的其他元数据信息都是不可更改的,包括数据库名和数据库所在的目录位置。
alter database db_hive set dbproperties(‘createtime‘=‘20180830‘);
在mysql中查看修改结果
desc database extended db_hive;
显示数据库
show databases;
过滤显示查询的数据库
show databases like ‘db_hive*‘;
显示数据库信息
desc database db_hive;
显示数据库详细信息,extended
desc database extended db_hive;
use db_hive;
drop database db_hive2;
drop database if exists db_hive2;
drop database db_hive cascade;
1.提示:如果将sql语句写到文件中是,可以用:hive -f 文件名的方式来执行文件中的sql语句
2.默认创建的表都为内部表
create table if not exists 表名(eid int, name string, sex string) row format delimited fields terminated by ‘\t‘;
查询表类型
desc formatted 表名;
因为表是外部表,所有Hive并非认为其完全拥有这份数据。删除该表并不会删除掉这份数据,不过描述表的元数据信息会被删除掉
建表语句:
create external table if not exists 表名(eid int, name string, sex string) row format delimited fields terminated by ‘\t‘;
每天将收集到的网站日志定期流入HDFS文本文件。在外部表(原始日志表)的基础上做大量的统计分析,用到的中间表、结果表使用内部表存储,数据通过SELECT+INSERT进入内部表
load data local inpath ‘本地文件路径‘ into table 库名.表名;
分区表实际上就是对应一个HDFS文件系统上的独立的文件夹,该文件夹下是该分区所有的数据文件。Hive中的分区就是分目录,把一个大的数据集根据业务需要分割成小的数据集。在查询时通过WHERE子句中的表达式选择查询所需要的指定的分区,这样的查询效率会提高很多
create table dept_partition(
deptno int, dname string, loc string
)
partitioned by (month string)
row format delimited fields terminated by ‘\t‘;
load data local inpath ‘/opt/module/datas/dept.txt‘ into table default.dept_partition partition(month=‘201709‘);
单分区查询
select * from dept_partition where month=‘201709‘;
多分区查询
select * from dept_partition where month=‘201709‘
union
select * from dept_partition where month=‘201708‘
union
select * from dept_partition where month=‘201707‘;
创建当个分区
alter table dept_partition add partition(month=‘201706‘) ;
同时创建多个分区
alter table dept_partition add partition(month=‘201705‘) partition(month=‘201704‘);
删除单个分区
alter table dept_partition drop partition (month=‘201704‘);
同时删除多个分区
alter table dept_partition drop partition (month=‘201705‘), partition (month=‘201706‘);
show partitions dept_partition;
desc formatted dept_partition;
create table dept_partition2(
deptno int, dname string, loc string
)
partitioned by (month string, day string)
row format delimited fields terminated by ‘\t‘;
load data local inpath ‘/opt/module/datas/dept.txt‘ into table default.dept_partition2 partition(month=‘201709‘, day=‘13‘);
select * from dept_partition2 where month=‘201709‘ and day=‘13‘;
alter table dept_partition2 rename to dept_partition3;
alter table dept_partition add columns(deptdesc string);
alter table dept_partition change column deptdesc desc int;
alter table dept_partition replace columns(deptno string, dname string, loc string);
drop table dept_partition;
标签:通过 like AC change ati 使用场景 for exist 中间
原文地址:https://www.cnblogs.com/screen/p/8999057.html