1.hive2.x新特性
cast(null as string) as xx                              --union all 前后表字段类型严格要求一致
 regexp_replace(ta.gds_nm,'\" ',' ') as xx      --双引号需要转移2.相关sql
show grant on database xxx                       --查看数据库权限
 show grant on table xxx                              --查看表权限set hive.exec.mode.local.auto=false;        --set hive.exec.mode.local.auto=false改成非本地模式重跑下
 truncate 无法删除外部表
 非分区表不支持cascade//client切换hive版本可以通过change_hive_version脚本,
 譬如source change_hive_version hive-1.2.2和source change_hive_version hive-2.3.4 hive1.x不支持 通过like方式建es表
 1、建表
 create table if not exists 表名(id int,name string,sex string,num float)
 partitioned by (dt string,hour string)
 row format delimited fields terminated by ','; //hive似乎只支持一个字符作为分隔符,不支持多个字符作为分隔符--建表(as)
create table if not exists hive_create1 as select * from hive_create3;
 --建表(like)
 create [temporary] [external] table [if not exists] [db_name.]table_name like 存在的表名or视图名 [location hdfs_path];
 create table if not exists hive_create2 like table hive_create3;--修改表名      alter table old表名 rename to new表名;
--删除表          drop table 表名;
--删除表数据   truncate table 表名;
--修改表名       alter table old表名 rename to new表名;
--查看表结构
 desc formatted table_name;
 desc table_name;添加分区
 alter table 表名    add partition(dt='20180115'); //新创建时未创建分区的表无法进行增加分区操作;新增分区要保持跟创建表时的分区保持一致(类型,数量)--删除分区
 alter table 表名                  drop partition(dt='20180115');--重命名分区                     alter table 表名 partition(dt="20180111") rename to partition(dt="20180115");
--查看分区信息                  show partitions 表名;
--修复分区,倒入表数据之后,一般需要重新修复分区,否则无数据
 MSCK REPAIR TABLE table_name3、新增字段,新增列       alter table 表名 add columns (last_name string);
--重命名字段名
 eg:create table 表名 (a int,b int,c int);
 alter table 表名 change a a1 string after b; //修改后的类型范围必须大于之前的,after是将其放在某一列之后

 4、加载数据
 --HDFS加载
 load data inpath '/home/bigdata/aa.txt' into table 表名 partition(dt='20190222');--本地加载
 load data local inpath '/home/bigdata/aa.txt' into table 表名 partition(dt='20180115');5、--创建库           create database 库名;
     --删除库            drop database 库名;
--数据库的dbproperties设置键值对属性值,来描述数据库属性信息,数据库其他元数据都是不可更改的,包括数据库名和数据库所在目录位置
6、查看用户权限
 use sopdm;
 show grant user sopdm on table test;角色
* 创建角色             create role role_name;
* 显示角色             show roles;
* 删除角色             drop role role_name;
2. 用户
 * 用户进入admin角色权限
 set hive.users.in.admin.role;
 set role admin;* 查看某用户的所有角色
 show role grant user user_name* 给角色添加用户
 grant role role_name to user user_name;3. 用户授权
 * 基于数据库
 grant select on database default to user admin;* 基于某张表
 grant select on table ppdata to user admin;
 . 组授权
 * 基于数据库
 grant select on database default to group admin;* 基于某张表
 grant select on table ppdata to group admin;
 . 角色授权
 * 基于数据库
 grant select on database default to role admin;* 基于某张表
 grant select on table ppdata to role admin;用户移除权限
 * 基于数据库
 revoke select on database default from user userB;* 基于某张表
 revoke select on table ppdata from user userB;7. 查看角色权限
 * 在某个数据库的权限
 show grant role role_name on database database_name;* 在某表的权限
 show grant role role_name on [table] table_name;8. 权限说明
 名称 描述
 ALL 赋予所有的权限
 ALTER 有修改表结构的权限
 CREATE 有创建表的权限
 DROP 有删除表或表中的分区的权限
 LOCK 开启并发后,锁定和解锁定表的权限
 SELECT 查询表或者分区中数据的权限
 SHOW_DATABASE 查看所有数据库的权限
 UPDATE 向表或者分区中插入或加载数据的权限14、赋权
 grant create on table 表名 to user 用户名;
 grant create on database 库名 to user 用户名;15、收权
 revoke create on table 表名 from user 用户名;
 revoke create on database 库名 from user 用户名;16、插入insert
 insert into table 表名 partition(dt='201707') select id, name from testB;追加(字段数量要一致,不一致用null代替)
 insert overwrite table 表名1 [partition (partcol1=val1, partcol2=val2 ...)] select 字段名 from 表名2;eg:insert表A时用的as select 表B
 1)create table if not exists 表名1(id int,name string,sex string,num float) partitioned by (dt string)
 row format delimited fields terminated by ',';
 2)create table if not exists 表名2(id int,name string,sex string,num float) partitioned by (dt string)
 row format delimited fields terminated by ',';
 3)load data local inpath '文件路径' into table 表名2 partition(dt='20180115');
 4)insert into table err1 partition(ds='20180115') select id,name,sex,num from err2 where dt='20180115';17、创建视图
 eg:create table 表名(id int,name string);
 create view 视图名(id,name_length)as select id,length(name) from 表名;18、创建临时函数
 add jar /opt/bigdata/software/hive/ext-lib/suning-commons-udf.jar;
 create temporary function 函数名 as 'com.suning.commons.udf.UDFCut';(临时函数)
 执行select 函数名('aaaa112b11',6) from 表名(存在的表);create function 函数名 as 'com.suning.commons.udf.UDFCut';
19、删除函数
 drop temporary function [if exists] 函数名;
 drop function [if exists] 函数名;20、删除视图
 drop view [if exists] [db_name.]视图名;21、查看函数
 show functions 函数名;
 show functions like '*.testCutb';(模糊查询)22、打印表的字段信息
 describe 表名;23、表添加属性
 alter table 表名 set tblproperties ('note'='hello welcome');
 show create table 表名;24、查看内置函数
 show functions;

 25、查看某一函数具体描述
 describe function 函数名;26、添加UDFZodiacSign的jar包
 add jar /home/udf.jar27、将little_bigdata表中name字段中数据传入临时函数zodiac中
 select zodiac(name) from little_bigdata;28、删除列
 Textfile,sequencefile的表可以使用下面命令删除字段,rcfile的不可以。
 alter table test replace columns(name string);30、修改表位置,(只能是 hdfs 上的全路径)
 alter table 表名 set location 'hdfs://mini1:9000/data/ttt';设置命令
 set xx=xx;---hive两种命令方式
 !是执行shell命令,dfs是hive自身sql命令hdfs客户端的常用操作命令
 1、上传文件到hdfs中
 hadoop fs -put /本地文件 /aaa(hdfs_path)2、下载文件到客户端本地磁盘
 hadoop fs -get /hdfs中的路径 /本地磁盘目录3、在hdfs中创建文件夹
 hadoop fs -mkdir -p /aaa/xxx3.1创建文件
 hdfs dfs -touchz /zj1.txt 4、移动hdfs中的文件(更名)
 hadoop fs -mv /hdfs的路径1 /hdfs的另一个路径2复制hdfs中的文件到hdfs的另一个目录
 hadoop fs -cp /hdfs路径_1 /hdfs路径_2 5、删除hdfs中的文件或文件夹
 hadoop fs -rm -r /aaa6、查看hdfs中的文本文件内容
 hadoop fs -cat /demo.txt
 hadoop fs -tail -f /demo.txt7、修改文件的权限
 hadoop fs -chown user:group /aaa
 hadoop fs -chmod 700 /aaa8、追加内容到已存在的文件
 hadoop fs -appendToFile /本地文件 /hdfs中的文件regex Column Specification
 SELECT 语句可以使用正则表达式做列选择,下面的语句查询除了 ds 和 hr 之外的所有列:
 SELECT `(ds|hr)?+.+` FROM salesssh 远程连接服务