[ https://issues.apache.org/jira/browse/FLINK-28247?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rui Li reassigned FLINK-28247: ------------------------------ Assignee: luoyuxia > 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 > > 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)