hive通过正则表达式筛选列,简化select

Hive 0.13.0及以后,select列表支持正则表达式,可极大提高开发效率,demo如下。

 

-- 配置开启正则表达式筛选
set hive.support.quoted.identifiers=none;
-- 查询除了某个列以外的其他字段的内容语法
select `(col_name1|col_name2|col_name3)?+.+` from table;

 

比如:

-- 改造前
select t1.*
    ,t2.column4
    ,t2.column5
    ,t2.column6
from
    (select id
        ,column1
        ,column2
        ,column3
    from table1
    ) t1
left JOIN
    (select id
        ,column4
        ,column5
        ,column6
    from table2
    ) t2
on t1.id = t2.id

 

-- 改造后

set hive.support.quoted.identifiers=none;

select t1.*
    ,`(t2.id)?.+.`
from
    (select id
        ,column1
        ,column2
        ,column3
    from table1
    ) t1
left JOIN
    (select id
        ,column4
        ,column5
        ,column6
    from table2
    ) t2
on t1.id = t2.id

 

 

posted on 2021-06-01 14:35  tianyaDream  阅读(1552)  评论(0编辑  收藏  举报

导航