hive—在分组集中使用case的语法

edqdpe6u  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(454)

有关的配置单元查询片段如下所示:

group by
  case
    when inte.subId is not null then 'int'
    else 'ext'
  end,
  taskType,
  result
grouping sets(
  (
    case
      when inte.subId is not null then 'int'
      else 'ext'
    end,  -- line 36
    taskType,
    result
  ),  -- line 39
  (
    taskType,
    result
  )
)

日志显示第36行和第39行出现语法错误:

FAILED: ParseException line 36:7 missing ) at ',' near ')'
line 39:3 missing EOF at ',' near ')'

你知道吗?如果你需要我的更多信息,请随时发表评论。

23c0lvtd

23c0lvtd1#

好的,下面是@gordonlinoff在评论中建议的解决方案。基本上,这个想法是使用一个子查询 Category 选择为

case 
  when inte.subId is not null then 'int'
  else 'ext'
end as Category

然后,在外部主查询中,组部分是

group by Category, Type, Result
grouping sets(
    (Category, Type, Result),
    (Type, Result)
)

至于问题中为什么会出现语法错误,我们还不确定。也许 吧, case 不能在中使用 grouping sets .

相关问题