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

Fix IndexOutOfBoundsException for non equality condition exists in left semi join in Hive dialect

    XMLWordPrintableJSON

Details

    Description

      It'll throw exception "java.lang.IndexOutOfBoundsException: Index: 0, Size: 0" with the following sql which can be executed in Hive:

      select count(1)
      from
        (select key
        from t1
        where key = 0) t1
      left semi join
        (select key
        from t2
        where key = 0) t2
      on 1 = 1;
      

      From the source code, it will call `RelOptUtil.splitJoinCondition` to split join condition and initialize the `leftJoinKeys` and `rightJoinKeys` passed in the method:

        public static RexNode splitJoinCondition(
            List<RelDataTypeField> sysFieldList,
            RelNode leftRel,
            RelNode rightRel,
            RexNode condition,
            List<RexNode> leftJoinKeys,
            List<RexNode> rightJoinKeys,
            List<Integer> filterNulls,
            List<SqlOperator> rangeOp)
      

      But when meet the case that there's no equality join keys found, the behavior will be wired that the `leftJoinKeys` will contain two RexNodes and the `rightJoinKeys` contains nothing. Then it'll cause the exception for we expect the size of `leftJoinKeys` is equal to `rightJoinKeys`.
      It seems a issue of Calcite CALCITE-5032.

      To fix it, just following what hive has done, we can rewrite the method `RelOptUtil.splitJoinCondition` to fix it. And what's more,
      it makes it's possible to support non-equi LEFT SEMI JOIN supported in Hive HIVE-17766.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: