diff --git a/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java b/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java index e6737dc7f99f..8e4766a5a156 100644 --- a/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java +++ b/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java @@ -240,6 +240,9 @@ public RelTraitSet replaceIfs(RelTraitDef def, return this; // trait is not enabled; ignore it } final List traitList = traitSupplier.get(); + if (traitList == null) { + return replace(index, def.getDefault()); + } return replace(index, RelCompositeTrait.of(def, traitList)); } @@ -250,7 +253,10 @@ public RelTraitSet replaceIf(RelTraitDef def, if (index < 0) { return this; // trait is not enabled; ignore it } - final T traitList = traitSupplier.get(); + T traitList = traitSupplier.get(); + if (traitList == null) { + traitList = def.getDefault(); + } return replace(index, traitList); }