xiedeyantu commented on code in PR #4706:
URL: https://github.com/apache/calcite/pull/4706#discussion_r2647964924
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -3034,6 +3038,71 @@ private static class VariableCollector extends
RexVisitorImpl<Void> {
}
}
+ private static final Set<SqlKind> CONSTANT_VALUE_CONSTRUCTOR_KINDS =
+ EnumSet.of(
+ SqlKind.ARRAY_VALUE_CONSTRUCTOR,
+ SqlKind.MAP_VALUE_CONSTRUCTOR,
+ SqlKind.MULTISET_VALUE_CONSTRUCTOR);
+
+ private static @Nullable Pair<RexNode, RexNode> constantEquality(RexCall
call) {
+ final RexNode o0 = call.getOperands().get(0);
+ final RexNode o1 = call.getOperands().get(1);
+ if (RexUtil.isReferenceOrAccess(o0, true) && isConstant(o1)) {
+ return Pair.of(o0, o1);
+ }
+ if (RexUtil.isReferenceOrAccess(o1, true) && isConstant(o0)) {
+ return Pair.of(o1, o0);
+ }
+ return null;
+ }
+
+ private static boolean constantsEquivalent(RexNode node1, RexNode node2) {
+ if (Objects.equals(node1, node2)) {
+ return true;
+ }
+ if (!(node1 instanceof RexCall) || !(node2 instanceof RexCall)) {
+ return false;
+ }
+ final RexCall call1 = (RexCall) node1;
+ final RexCall call2 = (RexCall) node2;
+ if (call1.getKind() != call2.getKind()) {
+ return false;
+ }
+ switch (call1.getKind()) {
+ case MULTISET_VALUE_CONSTRUCTOR:
+ return multisetLiteralEquals(call1, call2);
+ case MAP_VALUE_CONSTRUCTOR:
+ return mapLiteralEquals(call1, call2);
+ default:
+ return false;
+ }
+ }
+
+ private static boolean multisetLiteralEquals(RexCall left, RexCall right) {
+ return HashMultiset.create(left.getOperands())
+ .equals(HashMultiset.create(right.getOperands()));
Review Comment:
Thank you for your reply. I have a question: do we need to support
comparisons of complex types like MAP? I found that DuckDB and ClickHouse
support it, but they don't perform sorting. Also, currently I'm using
RexSimplify, which doesn't seem to have a way to handle dialect-based
comparisons. Do we need to add a configuration to enable or disable comparisons
of complex types? Or perhaps it would be good to have Calcite support
simplified comparisons of complex types by default?
--
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]