我正在尝试创建一个具有以下逻辑的Hive View :

create view test.view as
select
distinct(
  case
  when substr(value_1, 1, 10) < "2016-01-01" then
     regexp_extract(value_2,'(?i-sx:\\|([1-9][0-9]{0,3}x[1-9][0-9]{0,3})\\|)',1)
   else
     split(value_2, '\\|')[5]
   end
  ) as value_3
from test.table;

但是当我运行它时,我得到以下输出:
FAILED: ParseException line 128:2 cannot recognize input near 'distinct' '(' 'case' in select expression

有谁知道我该怎么写,这样我不会出错?或告诉我为什么会这样?

最佳答案

distinct不是函数。它应用于所有选定的列,并产生所有选定列的唯一组合。

试试这个:

select distinct case
        when substr(value_1, 1, 10) < "2016-01-01"
            then regexp_extract(value_2, '(?i-sx:\\|([1-9][0-9]{0,3}x[1-9][0-9]{0,3})\\|)', 1)
        else split(value_2, '\\|') [5]
        end as value_3
from test.table;

所以这:
select distinct (col), col2

与:
select distinct col, col2

09-10 07:55
查看更多