zoudan commented on code in PR #3185:
URL: https://github.com/apache/calcite/pull/3185#discussion_r1184764934
##########
core/src/main/java/org/apache/calcite/plan/RelOptPlanner.java:
##########
@@ -350,4 +350,49 @@ public CannotPlanException(String message) {
super(message);
}
}
+
+ /**
+ * Converts a relation expression to a given set of traits, if it does not
+ * already have those traits.
+ *
+ * @param rel Relational expression to convert
+ * @param toTraits desired traits
+ * @return a relational expression with the desired traits; never null
+ */
+ default RelNode convert(RelNode rel, RelTraitSet toTraits) {
+ RelTraitSet outTraits = rel.getTraitSet();
+ for (int i = 0; i < toTraits.size(); i++) {
+ RelTrait toTrait = toTraits.getTrait(i);
+ if (toTrait != null) {
+ outTraits = outTraits.replace(i, toTrait);
+ }
+ }
+
+ if (rel.getTraitSet().matches(outTraits)) {
+ return rel;
+ }
+
+ return this.changeTraits(rel, outTraits);
+ }
+
+ /**
+ * Converts one trait of a relational expression, if it does not
+ * already have that trait.
+ *
+ * @param rel Relational expression to convert
+ * @param toTrait Desired trait
+ * @return a relational expression with the desired trait; never null
+ */
+ default RelNode convert(RelNode rel, @Nullable RelTrait toTrait) {
+ RelTraitSet outTraits = rel.getTraitSet();
Review Comment:
How about use `return convert(rel,
RelTraitSet.createEmpty().plus(toTrait))`, so that we could reuse most of the
code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]