You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2017/05/09 03:11:44 UTC
ignite git commit: master - fixed SELECT (SELECT COUNT(1)) FROM
Repository: ignite
Updated Branches:
refs/heads/master 5dc989624 -> d10091d6f
master - fixed SELECT (SELECT COUNT(1)) FROM
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d10091d6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d10091d6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d10091d6
Branch: refs/heads/master
Commit: d10091d6f23e648d413e478b69e9da0f62c18413
Parents: 5dc9896
Author: Sergi Vladykin <se...@gmail.com>
Authored: Tue May 9 06:11:34 2017 +0300
Committer: Sergi Vladykin <se...@gmail.com>
Committed: Tue May 9 06:11:34 2017 +0300
----------------------------------------------------------------------
.../query/h2/sql/GridSqlQuerySplitter.java | 7 ++++-
.../query/IgniteSqlSplitterSelfTest.java | 30 ++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/d10091d6/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 b3d54e1..2bac505 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
@@ -1734,13 +1734,18 @@ public class GridSqlQuerySplitter {
}
/**
- * @param el Expression.
+ * @param el Expression part in SELECT clause.
* @return {@code true} If expression contains aggregates.
*/
private static boolean hasAggregates(GridSqlAst el) {
if (el instanceof GridSqlAggregateFunction)
return true;
+ // If in SELECT clause we have a subquery expression with aggregate,
+ // we should not split it. Run the whole subquery on MAP stage.
+ if (el instanceof GridSqlQuery)
+ return false;
+
for (int i = 0; i < el.size(); i++) {
if (hasAggregates(el.child(i)))
return true;
http://git-wip-us.apache.org/repos/asf/ignite/blob/d10091d6/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
index 8e56d36..34101d2 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
@@ -37,6 +37,7 @@ import org.apache.ignite.cache.CacheKeyConfiguration;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cache.affinity.AffinityKey;
import org.apache.ignite.cache.affinity.AffinityKeyMapped;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlFieldsQuery;
@@ -291,6 +292,35 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest {
}
/**
+ */
+ public void testSubQueryWithAggregate() {
+ CacheConfiguration ccfg1 = cacheConfig("pers", true,
+ AffinityKey.class, Person2.class);
+
+ IgniteCache<AffinityKey<Integer>, Person2> c1 = ignite(0).getOrCreateCache(ccfg1);
+
+ try {
+ int orgId = 100500;
+
+ c1.put(new AffinityKey<>(1, orgId), new Person2(orgId, "Vasya"));
+ c1.put(new AffinityKey<>(2, orgId), new Person2(orgId, "Another Vasya"));
+
+ List<List<?>> rs = c1.query(new SqlFieldsQuery("select name, " +
+ "(select count(1) from Person2 q where q.orgId = p.orgId) " +
+ "from Person2 p order by name desc")).getAll();
+
+ assertEquals(2, rs.size());
+ assertEquals("Vasya", rs.get(0).get(0));
+ assertEquals(2L, rs.get(0).get(1));
+ assertEquals("Another Vasya", rs.get(1).get(0));
+ assertEquals(2L, rs.get(1).get(1));
+ }
+ finally {
+ c1.destroy();
+ }
+ }
+
+ /**
* @throws InterruptedException If failed.
*/
public void testDistributedJoinFromReplicatedCache() throws InterruptedException {