ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [28/50] [abbrv] incubator-ignite git commit: ignite-624 - fix for reduce invisible columns
Date Thu, 09 Apr 2015 10:13:26 GMT
ignite-624 - fix for reduce invisible columns


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

Branch: refs/heads/ignite-673
Commit: d9e2a648136b00cb688789a8216f0ae02c73bc93
Parents: bef34cd
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Wed Apr 8 13:12:23 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Wed Apr 8 13:12:23 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/internal/util/lang/GridFunc.java   |  9 +++++++++
 .../query/h2/sql/GridSqlQuerySplitter.java           | 15 +++++++++++----
 .../processors/query/h2/sql/GridSqlSelect.java       |  9 ++++++++-
 .../processors/query/h2/sql/GridSqlUnion.java        |  2 +-
 4 files changed, 29 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d9e2a648/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index 773b9ee..fee53ef 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -5430,6 +5430,15 @@ public class GridFunc {
 
     /**
      * @param c Target collection.
+     * @param it Iterable to fetch.
+     * @return Modified target collection.
+     */
+    public static <T, C extends Collection<T>> C addAll(C c, Iterable<? extends
T> it) {
+        return it == null ? c : addAll(c, it.iterator());
+    }
+
+    /**
+     * @param c Target collection.
      * @param it Iterator to fetch.
      * @return Modified target collection.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d9e2a648/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 b84084b..79c73f0 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
@@ -83,7 +83,7 @@ public class GridSqlQuerySplitter {
 
         if (qry0 instanceof GridSqlSelect)
             srcQry = (GridSqlSelect)qry0;
-        else {
+        else { // Handle UNION.
             srcQry = new GridSqlSelect().from(new GridSqlSubquery(qry0));
 
             GridSqlSelect left = leftest(qry0);
@@ -124,11 +124,15 @@ public class GridSqlQuerySplitter {
 
         final String mergeTable = TABLE_FUNC_NAME + "()"; // table(0); TODO
 
+        // Create map and reduce queries.
         GridSqlSelect mapQry = srcQry.clone();
         GridSqlSelect rdcQry = new GridSqlSelect().from(new GridSqlFunction("PUBLIC", TABLE_FUNC_NAME));
// table(mergeTable)); TODO
 
         // Split all select expressions into map-reduce parts.
-        List<GridSqlElement> mapExps = F.addAll(new ArrayList<GridSqlElement>(),
srcQry.select(false).iterator());
+        List<GridSqlElement> mapExps = F.addAll(
+            new ArrayList<GridSqlElement>(srcQry.allColumns()),
+            srcQry.select(false));
+
         GridSqlElement[] rdcExps = new GridSqlElement[srcQry.visibleColumns()];
 
         Set<String> colNames = new HashSet<>();
@@ -141,12 +145,15 @@ public class GridSqlQuerySplitter {
         // Fill select expressions.
         mapQry.clearSelect();
 
-        for (GridSqlElement exp : mapExps)
+        for (GridSqlElement exp : mapExps) // Add all map expressions as visible.
             mapQry.addSelectExpression(exp, true);
 
-        for (GridSqlElement rdcExp : rdcExps)
+        for (GridSqlElement rdcExp : rdcExps) // Add corresponding visible reduce columns.
             rdcQry.addSelectExpression(rdcExp, true);
 
+        for (int i = rdcExps.length; i < mapExps.size(); i++)  // Add all extra map columns
as invisible reduce columns.
+            rdcQry.addSelectExpression(column(((GridSqlAlias)mapExps.get(i)).alias()), false);
+
         // -- GROUP BY
         if (srcQry.hasGroupBy()) {
             mapQry.clearGroups();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d9e2a648/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
index 398ae10..dadba7c 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
@@ -22,7 +22,7 @@ import org.h2.util.*;
 import java.util.*;
 
 /**
- *
+ * Plain SELECT query.
  */
 public class GridSqlSelect extends GridSqlQuery {
     /** */
@@ -54,6 +54,13 @@ public class GridSqlSelect extends GridSqlQuery {
         return select.size();
     }
 
+    /**
+     * @return Number of columns is select including invisible ones.
+     */
+    public int allColumns() {
+        return allExprs.size();
+    }
+
     /** {@inheritDoc} */
     @Override protected GridSqlElement expression(int col) {
         return allExprs.get(col);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d9e2a648/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
index 90d9e41..dcc2c84 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
@@ -23,7 +23,7 @@ import org.h2.util.*;
 import javax.cache.*;
 
 /**
- *
+ * Select query with UNION.
  */
 public class GridSqlUnion extends GridSqlQuery {
     /** */


Mime
View raw message