Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 9704e609d -> 38819bcac


QPID-8104: [Broker-J] [Query] Generalise the implementation so that aliases may 
appear within expressions within the order-by clause


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/38819bca
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/38819bca
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/38819bca

Branch: refs/heads/master
Commit: 38819bcac6dc5481357d2c05aaf281e7c83532fe
Parents: 9704e60
Author: Keith Wall <kw...@apache.org>
Authored: Fri Feb 23 09:21:04 2018 +0000
Committer: Keith Wall <kw...@apache.org>
Committed: Fri Feb 23 09:23:12 2018 +0000

----------------------------------------------------------------------
 .../qpid/server/filter/OrderByExpression.java   | 10 ------
 .../servlet/query/ConfiguredObjectQuery.java    | 33 +++++++++++++-------
 .../query/ConfiguredObjectQueryTest.java        | 18 +++++++++++
 3 files changed, 39 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/38819bca/broker-core/src/main/java/org/apache/qpid/server/filter/OrderByExpression.java
----------------------------------------------------------------------
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/filter/OrderByExpression.java
 
b/broker-core/src/main/java/org/apache/qpid/server/filter/OrderByExpression.java
index 20120dc..87d45d1 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/filter/OrderByExpression.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/filter/OrderByExpression.java
@@ -58,14 +58,4 @@ public class OrderByExpression implements Expression
     {
         return 
((Number)((ConstantExpression)_expression).getValue()).intValue();
     }
-
-    public boolean isNamed()
-    {
-        return (_expression instanceof NamedExpression);
-    }
-
-    public String getName()
-    {
-        return ((NamedExpression) _expression).getName();
-    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/38819bca/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQuery.java
----------------------------------------------------------------------
diff --git 
a/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQuery.java
 
b/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQuery.java
index 1b22da0..f06051d 100644
--- 
a/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQuery.java
+++ 
b/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQuery.java
@@ -266,9 +266,8 @@ public final class ConfiguredObjectQuery
         private final List<OrderByExpression> _orderByExpressions;
 
         public OrderByComparator(final List<OrderByExpression> 
orderByExpressions,
-                                 final HeadersAndValueExpressions 
headersAndValue)
+                                 final List<Expression> valueExpressions)
         {
-            final List<Expression> valueExpressions = 
headersAndValue.getValueExpressions();
             _orderByExpressions = new ArrayList<>(orderByExpressions);
             for (ListIterator<OrderByExpression> iterator = 
_orderByExpressions.listIterator(); iterator.hasNext(); )
             {
@@ -287,12 +286,6 @@ public final class ConfiguredObjectQuery
                         iterator.set(orderByExpression);
                     }
                 }
-                else if (orderByExpression.isNamed() && 
headersAndValue.hasHeader(orderByExpression.getName()))
-                {
-                    Expression expression = 
headersAndValue.getValueExpressionForHeader(orderByExpression.getName());
-                    orderByExpression = new OrderByExpression(expression, 
orderByExpression.getOrder());
-                    iterator.set(orderByExpression);
-                }
             }
         }
 
@@ -343,19 +336,35 @@ public final class ConfiguredObjectQuery
                                                    final String orderByClause,
                                                    final 
HeadersAndValueExpressions headersAndValue)
     {
-        List<OrderByExpression> orderByExpressions = 
parseOrderByClause(orderByClause);
+        List<OrderByExpression> orderByExpressions = 
parseOrderByClause(orderByClause, headersAndValue);
         List<ConfiguredObject<?>> orderedObjects = new 
ArrayList<>(unorderedResults.size());
         orderedObjects.addAll(unorderedResults);
-        Comparator<Object> comparator = new 
OrderByComparator(orderByExpressions, headersAndValue);
+        Comparator<Object> comparator = new 
OrderByComparator(orderByExpressions, headersAndValue.getValueExpressions());
         Collections.sort(orderedObjects, comparator);
         return orderedObjects;
     }
 
-    private List<OrderByExpression> parseOrderByClause(final String 
orderByClause)
+    private List<OrderByExpression> parseOrderByClause(final String 
orderByClause,
+                                                       final 
HeadersAndValueExpressions headersAndValue)
     {
         final List<OrderByExpression> orderByExpressions;
         ConfiguredObjectFilterParser parser = new 
ConfiguredObjectFilterParser();
-        parser.setConfiguredObjectExpressionFactory(_expressionFactory);
+        parser.setConfiguredObjectExpressionFactory(new 
ConfiguredObjectExpressionFactory()
+        {
+            @Override
+            public ConfiguredObjectExpression 
createConfiguredObjectExpression(final String propertyName)
+            {
+                if (headersAndValue.hasHeader(propertyName))
+                {
+                    Expression expression = 
headersAndValue.getValueExpressionForHeader(propertyName);
+                    return object -> expression.evaluate(object);
+                }
+                else
+                {
+                    return 
super.createConfiguredObjectExpression(propertyName);
+                }
+            }
+        });
         try
         {
             orderByExpressions = parser.parseOrderBy(orderByClause);

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/38819bca/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQueryTest.java
----------------------------------------------------------------------
diff --git 
a/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQueryTest.java
 
b/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQueryTest.java
index b903a41..a660ec7 100644
--- 
a/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQueryTest.java
+++ 
b/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/query/ConfiguredObjectQueryTest.java
@@ -568,6 +568,24 @@ public class ConfiguredObjectQueryTest extends QpidTestCase
         assertQueryResults(new Object[][]{{1}, {2}, {4}}, _query.getResults());
     }
 
+    public void testExpressionToTermsOfAliasInOrderByClause()
+    {
+        _objects.add(createCO(new HashMap<String, Object>()
+        {{
+            put("foo1", "A");
+            put("foo2", "B");
+        }}));
+
+        _objects.add(createCO(new HashMap<String, Object>()
+        {{
+            put("foo1", "A");
+            put("foo2", "A");
+        }}));
+
+        _query = new ConfiguredObjectQuery(_objects, "foo1 AS bar1, foo2", 
null, "CONCAT(bar, foo2) ASC");
+        assertQueryResults(new Object[][]{{"A", "A"}, {"A", "B"}}, 
_query.getResults());
+    }
+
     public void testDelimitedAliasInOrderByClause()
     {
         _objects.add(createCO(new HashMap<String, Object>()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to