Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-26360 [Umbrella] Improvement for Hive Query Syntax Compatibility
  3. FLINK-28247

Exception will be thrown when over window contains grouping in Hive Dialect

Attach filesAttach ScreenshotVotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.16.0
    • None

    Description

      The exception will be reprodued by the following sql when using Hive Dialect:

      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; 

      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 :

       

      // 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);
          }
      } 
      
      
      

       

      So `grouping(category)` will be converted to `grouping(0, 1)`. 

      After `HiveParserCalcitePlanner#genSelectForWindowing`, it will try to rewrite it again:

       

      if (!qbp.getDestToGroupBy().isEmpty()) {
          // Special handling of grouping function
          expr =
                  rewriteGroupingFunctionAST(
                          getGroupByForClause(qbp, selClauseName),
                          expr,
                          !cubeRollupGrpSetPresent);
      } 

      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.

       

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            luoyuxia luoyuxia
            luoyuxia luoyuxia
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment