Column uniqueness is calculated incorrectly for 'Correlate' expression – and in some cases this leads to java.lang.IndexOutOfBoundsException. Example of such code:
The problems seems to be related to the org.apache.calcite.rel.metadata.RelMdColumnUniqueness.areColumnsUnique(Correlate rel, ImmutableBitSet columns, boolean ignoreNulls) method – it just delegates uniqueness check to left input without changing columns list, which leads to Exception if this list references columns from right input.
It seems, that right behavior should be following:
- For Anti/Semi join type keep the current behavior (as resulting rows contains fields only from left input).
- For Left/Inner join type columns set for correlate is unique only if it includes unique sets from both sides.