From f0ff385c7cf2208de7070f4c58398d0f7858d165 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Mon, 29 Aug 2022 14:28:06 -0500 Subject: [PATCH] ARTEMIS-3962 porting changes from AMQ-9052 Optimisations to improve the efficiency of the selectors. --- .../selector/filter/ComparisonExpression.java | 25 +++++++++++++++++++ .../selector/filter/UnaryExpression.java | 10 ++++++++ 2 files changed, 35 insertions(+) diff --git a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/ComparisonExpression.java b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/ComparisonExpression.java index 0cfd122b33..13f2f5b336 100755 --- a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/ComparisonExpression.java +++ b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/ComparisonExpression.java @@ -232,6 +232,31 @@ public abstract class ComparisonExpression extends BinaryExpression implements B return Boolean.FALSE; } + @Override + public boolean matches(Filterable message) throws FilterException { + Object lv = left.evaluate(message); + Object rv = right.evaluate(message); + + // If one of the values is null + if (lv == null ^ rv == null) { + return false; + } + if (lv == rv || lv.equals(rv)) { + return true; + } + if (lv.getClass() == rv.getClass()) { + // same class, but 'equals' return false, and they are not the same object + // there is no point in doing 'compare' + // this case happens often while comparing non equals Strings + return false; + } + if (lv instanceof Comparable && rv instanceof Comparable) { + Boolean compareResult = compare((Comparable) lv, (Comparable) rv); + return compareResult != null && compareResult; + } + return false; + } + @Override protected boolean asBoolean(int answer) { return answer == 0; diff --git a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java index e70de83861..265d089b6c 100755 --- a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java +++ b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java @@ -139,6 +139,16 @@ public abstract class UnaryExpression implements Expression { return !lvalue.booleanValue(); } + @Override + public boolean matches(Filterable message) throws FilterException { + Boolean lvalue = (Boolean) right.evaluate(message); + if (lvalue == null) { + // NOT NULL returns NULL that eventually fails the selector + return false; + } + return !lvalue; + } + @Override public String getExpressionSymbol() { return "NOT";