Skip to content

Commit

Permalink
[CALCITE-4215] Avoid NPE in RelMdCollation from ImmutableList.copyOf
Browse files Browse the repository at this point in the history
Return null instead when metadata is not known
  • Loading branch information
vlsi committed Oct 1, 2020
1 parent 97e4f0c commit 2f1d764
Showing 1 changed file with 19 additions and 15 deletions.
Expand Up @@ -112,17 +112,21 @@ public MetadataDef<BuiltInMetadata.Collation> getDef() {
*/
public ImmutableList<RelCollation> collations(RelNode rel,
RelMetadataQuery mq) {
return ImmutableList.of();
return null;
}

private static <E> ImmutableList<E> copyOf(Collection<? extends E> values) {
return values == null ? null : ImmutableList.copyOf(values);
}

public ImmutableList<RelCollation> collations(Window rel,
RelMetadataQuery mq) {
return ImmutableList.copyOf(window(mq, rel.getInput(), rel.groups));
return copyOf(window(mq, rel.getInput(), rel.groups));
}

public ImmutableList<RelCollation> collations(Match rel,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
match(mq, rel.getInput(), rel.getRowType(), rel.getPattern(),
rel.isStrictStart(), rel.isStrictEnd(),
rel.getPatternDefinitions(), rel.getMeasures(), rel.getAfter(),
Expand All @@ -142,65 +146,65 @@ public ImmutableList<RelCollation> collations(TableModify rel,

public ImmutableList<RelCollation> collations(TableScan scan,
RelMetadataQuery mq) {
return ImmutableList.copyOf(table(scan.getTable()));
return copyOf(table(scan.getTable()));
}

public ImmutableList<RelCollation> collations(EnumerableMergeJoin join,
RelMetadataQuery mq) {
// In general a join is not sorted. But a merge join preserves the sort
// order of the left and right sides.
return ImmutableList.copyOf(
return copyOf(
RelMdCollation.mergeJoin(mq, join.getLeft(), join.getRight(),
join.analyzeCondition().leftKeys, join.analyzeCondition().rightKeys,
join.getJoinType()));
}

public ImmutableList<RelCollation> collations(EnumerableHashJoin join,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
RelMdCollation.enumerableHashJoin(mq, join.getLeft(), join.getRight(), join.getJoinType()));
}

public ImmutableList<RelCollation> collations(EnumerableNestedLoopJoin join,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
RelMdCollation.enumerableNestedLoopJoin(mq, join.getLeft(), join.getRight(),
join.getJoinType()));
}

public ImmutableList<RelCollation> collations(EnumerableCorrelate join,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
RelMdCollation.enumerableCorrelate(mq, join.getLeft(), join.getRight(),
join.getJoinType()));
}

public ImmutableList<RelCollation> collations(Sort sort,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
RelMdCollation.sort(sort.getCollation()));
}

public ImmutableList<RelCollation> collations(SortExchange sort,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
RelMdCollation.sort(sort.getCollation()));
}

public ImmutableList<RelCollation> collations(Project project,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
project(mq, project.getInput(), project.getProjects()));
}

public ImmutableList<RelCollation> collations(Calc calc,
RelMetadataQuery mq) {
return ImmutableList.copyOf(calc(mq, calc.getInput(), calc.getProgram()));
return copyOf(calc(mq, calc.getInput(), calc.getProgram()));
}

public ImmutableList<RelCollation> collations(Values values,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
values(mq, values.getRowType(), values.getTuples()));
}

Expand All @@ -216,7 +220,7 @@ public ImmutableList<RelCollation> collations(HepRelVertex rel,

public ImmutableList<RelCollation> collations(RelSubset rel,
RelMetadataQuery mq) {
return ImmutableList.copyOf(
return copyOf(
Objects.requireNonNull(
rel.getTraitSet().getTraits(RelCollationTraitDef.INSTANCE)));
}
Expand Down Expand Up @@ -326,7 +330,7 @@ public static List<RelCollation> project(RelMetadataQuery mq,
collations.add(RelCollations.of(fieldCollationsForRexCalls));
}

return ImmutableList.copyOf(collations);
return copyOf(collations);
}

/** Helper method to determine a
Expand Down

0 comments on commit 2f1d764

Please sign in to comment.