当前位置:网站首页>【HQL】(二) 查询使用正则表达式做列选择
【HQL】(二) 查询使用正则表达式做列选择
2022-08-03 05:22:00 【cbigchaos】
工作中遇到这样的场景:查询时少数列不需要,需要的其余列数量又较多
Hive 0.13.0
之后,select列表支持正则表达式
了
查询时使用SELECT语句的时候采用正则表达式做列选择
废话不多说上例子
原表数据:
hive> select * from tab1;
OK
user_id opration log_time
1 A 2019/5/1
1 A 2019/5/2
1 A 2019/5/3
2 A 2019/5/1
2 A 2019/5/3
2 A 2019/5/7
2 A 2019/5/31
3 A 2019/5/1
3 A 2019/5/2
Time taken: 0.046 seconds, Fetched: 10 row(s)
查询除个别字段外的剩余所有字段
PS:使用这个技巧需要设定一个参数set hive.support.quoted.identifiers=none
select `(user_id)?+.+` from tab1;
结果:
踩了个坑
未设定参数导致报错
hive> select `(user_id)?+.+` from tab1;
FAILED: SemanticException [Error 10004]: Line 1:7 Invalid table alias or column
reference '(user_id)?+.+': (possible column names are: user_id, opration, log_time)
在spark SQL中加参数
set spark.sql.parser.quotedRegexColumnNames=true
参考:https://blog.csdn.net/qq_29232943/article/details/79462381