ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [1/2] incubator-ignite git commit: ignite-sprint-3 - map query sort limit fix (IGNITE-682)
Date Mon, 06 Apr 2015 14:41:41 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-sprint-3 888cff5fd -> 7e6d1934d


ignite-sprint-3 - map query sort limit fix (IGNITE-682)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2f34c46a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2f34c46a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2f34c46a

Branch: refs/heads/ignite-sprint-3
Commit: 2f34c46a695ed93f39cbc9f32b790f443fe0596b
Parents: 88268bf
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Mon Apr 6 17:41:17 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Mon Apr 6 17:41:17 2015 +0300

----------------------------------------------------------------------
 .../query/h2/sql/GridSqlQuerySplitter.java      | 22 ++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f34c46a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
index 77e0cc8..b3deea3 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
@@ -77,8 +77,10 @@ public class GridSqlQuerySplitter {
 
         Set<String> colNames = new HashSet<>();
 
+        boolean aggregateFound = false;
+
         for (int i = 0, len = mapExps.size(); i < len; i++) // Remember len because mapExps
list can grow.
-            splitSelectExpression(mapExps, rdcExps, colNames, i);
+            aggregateFound |= splitSelectExpression(mapExps, rdcExps, colNames, i);
 
         // Fill select expressions.
         mapQry.clearSelect();
@@ -110,15 +112,20 @@ public class GridSqlQuerySplitter {
 
         // -- ORDER BY
         if (!srcQry.sort().isEmpty()) {
-            mapQry.clearSort();
+            if (aggregateFound) // Ordering over aggregates does not make sense.
+                mapQry.clearSort(); // Otherwise map sort will be used by offset-limit.
 
             for (GridSqlSortColumn sortCol : srcQry.sort().values())
                 rdcQry.addSort(column(((GridSqlAlias)mapExps.get(sortCol.column())).alias()),
sortCol);
         }
 
         // -- LIMIT
-        if (srcQry.limit() != null)
+        if (srcQry.limit() != null) {
+            if (aggregateFound)
+                mapQry.limit(null);
+
             rdcQry.limit(srcQry.limit());
+        }
 
         // -- OFFSET
         if (srcQry.offset() != null) {
@@ -209,19 +216,24 @@ public class GridSqlQuerySplitter {
      * @param rdcSelect Selects for reduce query.
      * @param colNames Set of unique top level column names.
      * @param idx Index.
+     * @return {@code true} If aggregate was found.
      */
-    private static void splitSelectExpression(List<GridSqlElement> mapSelect, GridSqlElement[]
rdcSelect,
+    private static boolean splitSelectExpression(List<GridSqlElement> mapSelect, GridSqlElement[]
rdcSelect,
         Set<String> colNames, int idx) {
         GridSqlElement el = mapSelect.get(idx);
 
         GridSqlAlias alias = null;
 
+        boolean aggregateFound = false;
+
         if (el instanceof GridSqlAlias) { // Unwrap from alias.
             alias = (GridSqlAlias)el;
             el = alias.child();
         }
 
         if (el instanceof GridSqlAggregateFunction) {
+            aggregateFound = true;
+
             GridSqlAggregateFunction agg = (GridSqlAggregateFunction)el;
 
             GridSqlElement mapAgg, rdcAgg;
@@ -322,6 +334,8 @@ public class GridSqlQuerySplitter {
                 rdcSelect[idx] = rdcEl;
             }
         }
+
+        return aggregateFound;
     }
 
     /**


Mime
View raw message