平凡小站

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

HIVE带中括号的列名取数

某次取数,某表中有奇怪的字段名:pointchange_ygz_[yyyy],带了个中插号,用简单查询出错

select
  pointchange_ygz_[yyyy] as p
from
  t

出错信息:

Error while compiling statement: FAILED: SemanticException [Error 10004]: 
Line 1:7 Invalid table alias or column reference 'pointchange_ygz_': (possible column names are: ……

不论在该字段名加单引号,双引号,反单引号,还是什么斜杠、反斜杠,统统不行。后来茂名黄工指出用这样的语法即可解决:

set hive.support.quoted.identifiers=none;
select `pointchange_ygz_[yyyy]` as p from t;

注意列名还是要用反单引号括起来,否则还是不行。

hive.support.quoted.identifiers 查询时正则表达式的内容。

例:显示某表中除cust_id外的其它所有字段

set hive.support.quoted.identifiers = none;
select
  `(cust_id)?+.+`
from
  t

(来自hive通过正则表达式筛选列,简化select - tianyaDream - 博客园 (cnblogs.com))

posted on   何辉煌  阅读(141)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示