Skip to content

Commit

Permalink
[CALCITE-6688] Allow basic symmetric operators to be reversed.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbanghart committed Nov 22, 2024
1 parent d4b7342 commit 6274092
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public static SqlBasicFunction create(String name,
@Override public boolean isDeterministic() {
return deterministic;
}

@Override public @Nullable SqlOperator reverse() {
return isSymmetrical() ? this : null;
}

@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
return monotonicityInference.apply(call);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ class RexNormalizeTest extends RexProgramTestBase {
assertNodeEquals(
ne(vBool(0), vBool(1)),
ne(vBool(1), vBool(0)));

assertNodeEquals(
greatest(vInt(0), vInt(1)),
greatest(vInt(1), vInt(0)));

assertNodeEquals(
least(vInt(0), vInt(1)),
least(vInt(1), vInt(0)));
}

@Test void reversibleDifferentArgOps() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeSystem;
import org.apache.calcite.sql.fun.SqlInternalOperators;
import org.apache.calcite.sql.fun.SqlLibraryOperators;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.type.SqlTypeName;

Expand Down Expand Up @@ -326,6 +327,13 @@ protected RexNode sub(RexNode n1, RexNode n2) {
protected RexNode add(RexNode n1, RexNode n2) {
return rexBuilder.makeCall(SqlStdOperatorTable.PLUS, n1, n2);
}
protected RexNode greatest(RexNode... nodes) {
return rexBuilder.makeCall(SqlLibraryOperators.GREATEST, nodes);
}

protected RexNode least(RexNode... nodes) {
return rexBuilder.makeCall(SqlLibraryOperators.LEAST, nodes);
}

protected RexNode m2v(RexNode n) {
return rexBuilder.makeCall(SqlInternalOperators.M2V, n);
Expand Down

0 comments on commit 6274092

Please sign in to comment.