ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [34/50] incubator-ignite git commit: ignite-1015 - fixes
Date Fri, 24 Jul 2015 02:19:02 GMT
ignite-1015 - fixes


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

Branch: refs/heads/ignite-gg-10576
Commit: 301f573dd05788eb6e154c16ad2403700a5b1e9e
Parents: 0871a7a
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Wed Jul 22 09:04:41 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Wed Jul 22 09:04:41 2015 +0300

----------------------------------------------------------------------
 .../query/h2/sql/GridSqlQuerySplitter.java      | 56 ++++++++++++++++++--
 .../cache/GridCacheCrossCacheQuerySelfTest.java |  5 +-
 2 files changed, 55 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/301f573d/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 536f72d..056aafe 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
@@ -395,15 +395,17 @@ public class GridSqlQuerySplitter {
             el = alias.child();
         }
 
-        if (!collocated && el instanceof GridSqlAggregateFunction) {
+        if (!collocated && hasAggregates(el)) {
             aggregateFound = true;
 
             if (alias == null)
                 alias = alias(columnName(idx), el);
 
-            splitAggregate(alias, 0, mapSelect, idx, true);
+            // We can update original alias here as well since it will be dropped from mapSelect.
+            splitAggregates(alias, 0, mapSelect, idx, true);
 
-            rdcSelect[idx] = alias;
+            if (idx < rdcSelect.length)
+                rdcSelect[idx] = alias;
         }
         else {
             String mapColAlias = columnName(idx);
@@ -417,7 +419,7 @@ public class GridSqlQuerySplitter {
             // Always wrap map column into generated alias.
             mapSelect.set(idx, alias(mapColAlias, el)); // `el` is known not to be an alias.
 
-            if (idx < rdcSelect.length) { // SELECT __C0 AS orginal_alias
+            if (idx < rdcSelect.length) { // SELECT __C0 AS original_alias
                 GridSqlElement rdcEl = column(mapColAlias);
 
                 GridSqlType type = el.expressionResultType();
@@ -436,6 +438,52 @@ public class GridSqlQuerySplitter {
     }
 
     /**
+     * @param el Expression.
+     * @return {@code true} If expression contains aggregates.
+     */
+    private static boolean hasAggregates(GridSqlElement el) {
+        if (el instanceof GridSqlAggregateFunction)
+            return true;
+
+        for (GridSqlElement child : el) {
+            if (hasAggregates(child))
+                return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * @param parentExpr Parent expression.
+     * @param childIdx Child index to try to split.
+     * @param mapSelect List of expressions in map SELECT clause.
+     * @param exprIdx Index of the original expression in map SELECT clause.
+     * @param first If the first aggregate is already found in this expression.
+     * @return {@code true} If the first aggregate is already found.
+     */
+    private static boolean splitAggregates(
+        final GridSqlElement parentExpr,
+        final int childIdx,
+        final List<GridSqlElement> mapSelect,
+        final int exprIdx,
+        boolean first) {
+        GridSqlElement el = parentExpr.child(childIdx);
+
+        if (el instanceof GridSqlAggregateFunction) {
+            splitAggregate(parentExpr, childIdx, mapSelect, exprIdx, first);
+
+            return true;
+        }
+
+        for (int i = 0; i < el.size(); i++) {
+            if (splitAggregates(el, i, mapSelect, exprIdx, first))
+                first = false;
+        }
+
+        return !first;
+    }
+
+    /**
      * @param parentExpr Parent expression.
      * @param aggIdx Index of the aggregate to split in this expression.
      * @param mapSelect List of expressions in map SELECT clause.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/301f573d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
index f94d695..a393991 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
@@ -145,12 +145,12 @@ public class GridCacheCrossCacheQuerySelfTest extends GridCommonAbstractTest
{
 
         assertEquals(set0, set1);
 
-        X.println("___ GROUP BY AVG MIN MAX SUM COUNT(*) COUNT(x)");
+        X.println("___ GROUP BY AVG MIN MAX SUM COUNT(*) COUNT(x) (MAX - MIN) * 2 as");
 
         Set<String> names = new HashSet<>();
 
         qry = new SqlFieldsQuery("select p.name, avg(f.price), min(f.price), max(f.price),
sum(f.price), count(*), " +
-            "count(nullif(f.price, 5)) " +
+            "count(nullif(f.price, 5)), (max(f.price) - min(f.price)) * 3 as nn " +
             "from FactPurchase f, \"replicated\".DimProduct p " +
             "where p.id = f.productId " +
             "group by f.productId, p.name");
@@ -160,6 +160,7 @@ public class GridCacheCrossCacheQuerySelfTest extends GridCommonAbstractTest
{
 
             assertTrue(names.add((String)o.get(0)));
             assertEquals(i(o, 4), i(o, 2) + i(o, 3));
+            assertEquals(i(o, 7), (i(o, 3) - i(o, 2)) * 3);
         }
 
         X.println("___ SUM HAVING");


Mime
View raw message