ignite-gg9499 - avg

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

Branch: refs/heads/ignite-gg9499
Commit: 7aa4d37a606d68bbb3c9f9805e20cbd13ed99d3d
Parents: c35b1ff
Author: S.Vladykin <svlady...@gridgain.com>
Authored: Fri Jan 16 19:24:49 2015 +0300
Committer: S.Vladykin <svlady...@gridgain.com>
Committed: Fri Jan 16 19:24:49 2015 +0300

----------------------------------------------------------------------
 .../query/h2/sql/GridSqlQuerySplitter.java      | 38 +++++--------------
 .../cache/GridCacheCrossCacheQuerySelfTest.java | 39 ++++++++++++++------
 2 files changed, 36 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7aa4d37a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlQuerySplitter.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlQuerySplitter.java
 
b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlQuerySplitter.java
index 2348bc9..6105b2b 100644
--- 
a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlQuerySplitter.java
+++ 
b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/sql/GridSqlQuerySplitter.java
@@ -11,6 +11,7 @@ package org.gridgain.grid.kernal.processors.query.h2.sql;
 
 import org.apache.ignite.*;
 import org.gridgain.grid.kernal.processors.cache.query.*;
+import org.gridgain.grid.util.typedef.*;
 
 import java.sql.*;
 import java.util.*;
@@ -75,31 +76,26 @@ public class GridSqlQuerySplitter {
 
         mapQry.clearSelect();
 
-        int idx = 0;
-
-        for (GridSqlElement exp : mapExps) { // Add all expressions to select 
clause.
+        for (GridSqlElement exp : mapExps)
             mapQry.addSelectExpression(exp);
 
-            idx++;
-        }
-
         mapQry.clearGroups();
 
         for (int col : srcQry.groupColumns())
-            mapQry.addGroupExpression(column(aliases.get(col).alias()));
+            
mapQry.addGroupExpression(column(((GridSqlAlias)mapExps.get(col)).alias()));
 
-        mapQry.clearSort(); // TODO sort support
+        // TODO sort support
 
         // Reduce query.
         GridSqlSelect rdcQry = new GridSqlSelect();
 
-        for (int i = 0; i < srcQry.select().size(); i++)
-            rdcQry.addSelectExpression(column(aliases.get(i).alias()));
+        for (GridSqlElement rdcExp : rdcExps)
+            rdcQry.addSelectExpression(rdcExp);
 
         rdcQry.from(new GridSqlTable(null, table(0)));
 
         for (int col : srcQry.groupColumns())
-            rdcQry.addGroupExpression(column(aliases.get(col).alias()));
+            
rdcQry.addGroupExpression(column(((GridSqlAlias)mapExps.get(col)).alias()));
 
         GridCacheTwoStepQuery res = new GridCacheTwoStepQuery(rdcQry.getSQL());
 
@@ -109,28 +105,11 @@ public class GridSqlQuerySplitter {
     }
 
     /**
-     * @param exp Expression.
-     * @param idx Index in select.
-     * @return Natural or generated alias.
-     */
-    private static String alias(GridSqlElement exp, int idx) {
-        if (exp instanceof GridSqlColumn)
-            return ((GridSqlColumn)exp).columnName();
-
-        if (exp instanceof GridSqlAlias)
-            return ((GridSqlAlias)exp).alias();
-
-        return columnName(idx);
-    }
-
-    /**
      * @param mapSelect Selects for map query.
      * @param rdcSelect Selects for reduce query.
      * @param idx Index.
      */
     private static void splitSelectExpression(List<GridSqlElement> mapSelect, 
GridSqlElement[] rdcSelect, int idx) {
-        assert idx < rdcSelect.length;
-
         GridSqlElement el = mapSelect.get(idx);
 
         GridSqlAlias alias = null;
@@ -196,7 +175,8 @@ public class GridSqlQuerySplitter {
                 mapSelect.set(idx, alias);
             }
 
-            rdcSelect[idx] = column(alias.alias());
+            if (idx < rdcSelect.length)
+                rdcSelect[idx] = column(alias.alias());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7aa4d37a/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
 
b/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
index f5423da..1cf2178 100644
--- 
a/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
+++ 
b/modules/indexing/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
@@ -124,34 +124,44 @@ public class GridCacheCrossCacheQuerySelfTest extends 
GridCommonAbstractTest {
     /**
      * @throws Exception If failed.
      */
-    public void testTwoStepGroup() throws Exception {
+    public void testTwoStepGroupAndAggregates() throws Exception {
         fillCaches();
 
         GridCacheQueriesEx<Integer, FactPurchase> qx =
             (GridCacheQueriesEx<Integer, FactPurchase>)ignite.<Integer, 
FactPurchase>cache("partitioned").queries();
 
-        Set<Integer> set0 = new HashSet<>();
+        Set<Integer> set1 = new HashSet<>();
 
-        for (List<?> o : qx.executeTwoStepQuery("partitioned", "select 
productId from FactPurchase group by productId")
-            .get()) {
+        X.println("___ simple");
+
+        for (List<?> o : qx.executeTwoStepQuery("partitioned", "select 
f.productId, p.name, f.price " +
+            "from FactPurchase f, \"replicated\".DimProduct p where p.id = 
f.productId ").get()) {
             X.println("___ -> " + o);
 
-            assertTrue(set0.add((Integer) o.get(0)));
+            set1.add((Integer)o.get(0));
         }
 
-        X.println("___ ");
+        Set<Integer> set0 = new HashSet<>();
 
-        Set<Integer> set1 = new HashSet<>();
+        X.println("___ GROUP BY");
 
-        for (List<?> o : qx.executeTwoStepQuery("partitioned", "select 
productId from FactPurchase")
+        for (List<?> o : qx.executeTwoStepQuery("partitioned", "select 
productId from FactPurchase group by productId")
             .get()) {
             X.println("___ -> " + o);
 
-            set1.add((Integer)o.get(0));
+            assertTrue(set0.add((Integer) o.get(0)));
         }
 
         assertFalse(set1.isEmpty());
         assertEquals(set0, set1);
+
+        X.println("___ AVG");
+
+        for (List<?> o : qx.executeTwoStepQuery("partitioned",
+            "select p.name, avg(f.price) from FactPurchase f, 
\"replicated\".DimProduct p where p.id = f.productId " +
+                "group by f.productId, p.name").get()) {
+            X.println("___ -> " + o);
+        }
     }
 
     /** @throws Exception If failed. */
@@ -217,7 +227,7 @@ public class GridCacheCrossCacheQuerySelfTest extends 
GridCommonAbstractTest {
             DimStore store = dimStores.get(i % dimStores.size());
             DimProduct prod = dimProds.get(i % dimProds.size());
 
-            factCache.put(id, new FactPurchase(id, prod.getId(), 
store.getId()));
+            factCache.put(id, new FactPurchase(id, prod.getId(), 
store.getId(), i + 5));
         }
     }
 
@@ -279,10 +289,11 @@ public class GridCacheCrossCacheQuerySelfTest extends 
GridCommonAbstractTest {
      */
     private static class DimProduct {
         /** Primary key. */
-        @GridCacheQuerySqlField(unique = true)
+        @GridCacheQuerySqlField
         private int id;
 
         /** Product name. */
+        @GridCacheQuerySqlField
         private String name;
 
         /**
@@ -375,6 +386,9 @@ public class GridCacheCrossCacheQuerySelfTest extends 
GridCommonAbstractTest {
         @GridCacheQuerySqlField
         private int productId;
 
+        @GridCacheQuerySqlField
+        private int price;
+
         /**
          * Constructs a purchase record.
          *
@@ -382,10 +396,11 @@ public class GridCacheCrossCacheQuerySelfTest extends 
GridCommonAbstractTest {
          * @param productId Purchased product ID.
          * @param storeId Store ID.
          */
-        FactPurchase(int id, int productId, int storeId) {
+        FactPurchase(int id, int productId, int storeId, int price) {
             this.id = id;
             this.productId = productId;
             this.storeId = storeId;
+            this.price = price;
         }
 
         /**

Reply via email to