You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Rui Li (Jira)" <ji...@apache.org> on 2022/07/08 04:12:00 UTC

[jira] [Resolved] (FLINK-28247) Exception will be thrown when over window contains grouping in Hive Dialect

     [ https://issues.apache.org/jira/browse/FLINK-28247?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rui Li resolved FLINK-28247.
----------------------------
    Fix Version/s: 1.16.0
       Resolution: Fixed

> Exception will be thrown when over window contains grouping in Hive Dialect
> ---------------------------------------------------------------------------
>
>                 Key: FLINK-28247
>                 URL: https://issues.apache.org/jira/browse/FLINK-28247
>             Project: Flink
>          Issue Type: Sub-task
>            Reporter: luoyuxia
>            Assignee: luoyuxia
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.16.0
>
>
> The exception will be reprodued by the following sql when using Hive Dialect:
> {code:java}
> create table t(category int, live int, comments int)
> SELECT grouping(category), lag(live) over(partition by grouping(category)) FROM t GROUP BY category, live; {code}
> The reson is it will first call `HiveParserCalcitePlanner#genSelectForWindowing` to generate the window, which will then call `HiveParserUtils#rewriteGroupingFunctionAST` to rewrite the group function in the over window :
>  
> {code:java}
> // rewrite grouping function
> if (current.getType() == HiveASTParser.TOK_FUNCTION
>         && current.getChildCount() >= 2) {
>     HiveParserASTNode func = (HiveParserASTNode) current.getChild(0);
>     if (func.getText().equals("grouping")) {
>         visited.setValue(true);
>         convertGrouping(
>                 current, grpByAstExprs, noneSet, legacyGrouping, found);
>     }
> } 
> {code}
>  
> So `grouping(category)` will be converted to `grouping(0, 1)`. 
> After `HiveParserCalcitePlanner#genSelectForWindowing`, it will try to rewrite it again:
>  
> {code:java}
> if (!qbp.getDestToGroupBy().isEmpty()) {
>     // Special handling of grouping function
>     expr =
>             rewriteGroupingFunctionAST(
>                     getGroupByForClause(qbp, selClauseName),
>                     expr,
>                     !cubeRollupGrpSetPresent);
> } {code}
> And it will also fall back to `convertGrouping` again as `current.getChildCount() >= 2` will be true. But then, it can't find any field 
> presented  in group by  for it's `grouping(0, 1)` now.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)