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

"IndexOutOfBoundsException" when subquery select all field from using hive dialect

    XMLWordPrintableJSON

Details

    Description

      With hive dialect, can be reproduced using following code:

       tableEnv.executeSql("CREATE TABLE t1 (c1 INT, c2 CHAR(100))");
       tableEnv.executeSql("CREATE TABLE t2 (c1 INT)");
      List<Row> results = CollectionUtil.iteratorToList(tableEnv.executeSql("SELECT c1 FROM t1 WHERE c1 IN (SELECT c1 FROM t2)").
                              collect());
      

      Then it will throw IndexOutOfBoundsException: 0, the reason is from the following comments:
      If it's a subquery and the project is identity, we skip creating this project. This is to handle an issue with calcite SubQueryRemoveRule. The rule checks col uniqueness by calling RelMetadataQuery::areColumnsUnique with an empty col set, which always returns null for a project and thus introduces unnecessary agg node.

      So there could be no project node and only tablescan node in subquery. Then when we try to do type conversion for the subquery, with the following code, it'll throw exception when there's no project node.

      if (queryRelNode instanceof Project) {
        return replaceProjectForTypeConversion(
                          rexBuilder,
                          (Project) queryRelNode,
                          targetCalcTypes,
                          targetHiveTypes,
                          funcConverter);
      } else {
        RelNode newInput =
                              addTypeConversions(
                                      rexBuilder,
                                      queryRelNode.getInput(0),
                                      targetCalcTypes,
                                      targetHiveTypes,
                                      funcConverter);
                      queryRelNode.replaceInput(0, newInput);
                      return queryRelNode;
      }
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: