Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3969

Method RelTrait.apply(Mappings.Mapping) throws exception when mapping doesn't cover collation or distribution keys

    XMLWordPrintableJSON

    Details

      Description

      Let's consider we have an input (id, name) ordered by id (i.e. collation == [0]). If we have a Project("name") on the top of this input and we apply project's mapping on the collation, we'll end up with exception:

      java.lang.NullPointerException: at index 0
      	at com.google.common.collect.ObjectArrays.checkElementNotNull(ObjectArrays.java:239)
      	at com.google.common.collect.ObjectArrays.checkElementsNotNull(ObjectArrays.java:230)
      	at com.google.common.collect.ObjectArrays.checkElementsNotNull(ObjectArrays.java:225)
      	at com.google.common.collect.ImmutableList.construct(ImmutableList.java:281)
      	at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:239)
      	at org.apache.calcite.rel.RelCollations.of(RelCollations.java:69)
      	at org.apache.calcite.rex.RexUtil.apply(RexUtil.java:1271)
      	at org.apache.calcite.rel.RelCollationImpl.apply(RelCollationImpl.java:122)
      	at org.apache.calcite.rel.RelCollationImpl.apply(RelCollationImpl.java:40)
      

      This happens because the collation field id is not a part of the mapping. The same problem is with distribution trait when distribution keys are not covered by the mapping.

      Calcite should handle such situations gracefully. If it is not possible to deduce the collation/distribution after the mapping application, we should return:

      • EMPTY collation for RelCollation trait.
      • RANDOM_DISTRIBUTED distribution for RelDistribution trait.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rkondakov Roman Kondakov
                Reporter:
                rkondakov Roman Kondakov
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3.5h
                  3.5h