常用命令
输出表头
set hive.cli.print.header=true;
set hive.resultset.use.unique.column.names=false;
使用正则表达式
set hive.support.quoted.identifiers=none;
比如select时候想过滤某些列名,在列很多的时候很有用,通过以下实现:
select a.`(stat_date)?+.+` from table_name
<!--输出结果将不包含stat_date,并展示表的其他所有列-->
添加分区
alter table table_name add if not exists partition(stat_date=20211021);
报错1
NoViableAltException(10@[130:7: ( ( ( KW_AS )? identifier ) | ( KW_AS LPAREN identifier ( COMMA identifier )* RPAREN ) )?])
看起来是语法错误,排查了很久,也没找到原因,后来发现是设置的冲突导致的
set hive.support.quoted.identifiers=none;
在sql开头设置了这个下,想着可以支持正则语法select的,但是发现和语句中的in有冲突,所以就两个解决方案,一个是去掉这个设置;一个是不适用in语句;我选择了第一种,至于原因还没搞明白。