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

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM