Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CE078200C7E for ; Tue, 23 May 2017 22:58:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CCABF160BC3; Tue, 23 May 2017 20:58:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6F8C9160BA4 for ; Tue, 23 May 2017 22:58:36 +0200 (CEST) Received: (qmail 93985 invoked by uid 500); 23 May 2017 20:58:35 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 93976 invoked by uid 99); 23 May 2017 20:58:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 May 2017 20:58:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 72CC1DFAEB; Tue, 23 May 2017 20:58:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: nnag@apache.org To: commits@geode.apache.org Message-Id: <0b0c5ca7ee884e09adc463e9b7d1622c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: geode git commit: GEODE-2967: ResultCollection instead of StructCollection Date: Tue, 23 May 2017 20:58:35 +0000 (UTC) archived-at: Tue, 23 May 2017 20:58:38 -0000 Repository: geode Updated Branches: refs/heads/develop db81d9280 -> 9c4086813 GEODE-2967: ResultCollection instead of StructCollection * If we have one runtime iterator which is in case of self joins, ResultSet or ResultBags are created * Otherwise StructBag or StructSets are used Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/9c408681 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/9c408681 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/9c408681 Branch: refs/heads/develop Commit: 9c408681364973096cf4192255ec3f40d86b70bd Parents: db81d92 Author: nabarun Authored: Mon May 22 11:34:52 2017 -0700 Committer: nabarun Committed: Tue May 23 13:50:49 2017 -0700 ---------------------------------------------------------------------- .../geode/cache/query/internal/QueryUtils.java | 21 +++++---- .../query/internal/index/IndexUseJUnitTest.java | 47 +++++++++++++++++++- 2 files changed, 58 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/9c408681/geode-core/src/main/java/org/apache/geode/cache/query/internal/QueryUtils.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/QueryUtils.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/QueryUtils.java index bb0cbea..4d43729 100644 --- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/QueryUtils.java +++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/QueryUtils.java @@ -23,6 +23,7 @@ import java.util.ListIterator; import java.util.Map; import java.util.Set; +import org.apache.geode.cache.query.internal.types.ObjectTypeImpl; import org.apache.logging.log4j.Logger; import org.apache.geode.cache.query.AmbiguousNameException; @@ -806,8 +807,6 @@ public class QueryUtils { * */ static StructType createStructTypeForRuntimeIterators(List runTimeIterators) { - Support.Assert(runTimeIterators.size() > 1, - "The number of Iterators passed should be greater than 1 to create a structSet"); int len = runTimeIterators.size(); String[] fieldNames = new String[len]; String[] indexAlternativeFieldNames = new String[len]; @@ -886,10 +885,9 @@ public class QueryUtils { } return null; } - - Index lhsIndx = lhsIndxData.getIndex(); - Index rhsIndx = rhsIndxData.getIndex(); - if (((IndexProtocol) lhsIndx).isValid() && ((IndexProtocol) rhsIndx).isValid()) { + IndexProtocol lhsIndx = lhsIndxData.getIndex(); + IndexProtocol rhsIndx = rhsIndxData.getIndex(); + if (lhsIndx.isValid() && rhsIndx.isValid()) { return new IndexData[] {lhsIndxData, rhsIndxData}; } return null; @@ -1463,10 +1461,15 @@ public class QueryUtils { } } } - Support.Assert(totalFinalList.size() > 1, - " Since we are in relationship index this itself means that we have atleast two RuntimeIterators"); + SelectResults returnSet; StructType stype = createStructTypeForRuntimeIterators(totalFinalList); - SelectResults returnSet = QueryUtils.createStructCollection(context, stype); + if (totalFinalList.size() == 1) { + returnSet = QueryUtils.createResultCollection(context, new ObjectTypeImpl(stype.getClass())); + } else { + returnSet = QueryUtils.createStructCollection(context, stype); + } + + RuntimeIterator[][] mappings = new RuntimeIterator[2][]; mappings[0] = ich1.indexFieldToItrsMapping; mappings[1] = ich2.indexFieldToItrsMapping; http://git-wip-us.apache.org/repos/asf/geode/blob/9c408681/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/IndexUseJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/IndexUseJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/IndexUseJUnitTest.java index c865347..c55f3f3 100644 --- a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/IndexUseJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/IndexUseJUnitTest.java @@ -1367,7 +1367,7 @@ public class IndexUseJUnitTest { @Test public void testIndexUseSelfJoin() throws Exception { - String[] queries = {"SELECT DISTINCT * FROM /pos p1, /pos p2 where p1.status = p2.status", + String[] queries = {"SELECT DISTINCT * FROM /pos p1, /pos p2 where p1.status = p1.status", "SELECT DISTINCT * FROM /pos p1, /pos p2 where p1.ID = p2.ID", "SELECT DISTINCT * FROM /pos p1, /pos p2 where p1.P1.secId = p2.P1.secId", "SELECT DISTINCT * FROM /pos p1, /pos p2 where p1.status = p2.status and p1.status = 'active'", @@ -1407,6 +1407,51 @@ public class IndexUseJUnitTest { } @Test + public void testIndexUseSelfJoinUsingOneRegion() throws Exception { + String[] queries = {"SELECT DISTINCT * FROM /pos p1 where p1.status = p1.status", + "SELECT DISTINCT * FROM /pos p1 where p1.ID = p1.ID", + "SELECT DISTINCT * FROM /pos p1 where p1.P1.secId = p1.P1.secId", + "SELECT DISTINCT * FROM /pos p1 where p1.status = p1.status and p1.status = 'active'", + "SELECT DISTINCT * FROM /pos p1 where p1.ID = p1.ID and p1.ID < 2", + "SELECT * FROM /pos p1 where p1.ID = p1.ID", + "SELECT * FROM /pos p1 where p1.P1.secId = p1.P1.secId", + "SELECT * FROM /pos p1 where p1.status = p1.status and p1.status = 'active'", + "SELECT * FROM /pos p1 where p1.ID = p1.ID and p1.ID < 2", + "SELECT DISTINCT * FROM /pos p1 WHERE p1.ID IN (SELECT DISTINCT p1.ID FROM /pos p1)", + "SELECT * FROM /pos p1 WHERE p1.ID IN (SELECT DISTINCT p1.ID FROM /pos p1)", + "SELECT DISTINCT * FROM /pos p1 WHERE p1.ID IN (SELECT DISTINCT p2.ID FROM /pos p2)", + "SELECT * FROM /pos p1 WHERE p1.ID IN (SELECT DISTINCT p2.ID FROM /pos p2)"}; + + SelectResults[][] sr = new SelectResults[queries.length][2]; + for (int j = 0; j < queries.length; j++) { + Query q = qs.newQuery(queries[j]); + QueryObserverImpl observer = new QueryObserverImpl(); + QueryObserverHolder.setInstance(observer); + sr[j][0] = (SelectResults) q.execute(); + if (sr[j][0].size() == 0) { + fail("Query " + q.getQueryString() + " should have returned results"); + } + if (!observer.isIndexesUsed) { + fail("Index should have been used for query '" + q.getQueryString() + "'"); + } + } + qs.removeIndexes(); + for (int j = 0; j < queries.length; j++) { + Query q = qs.newQuery(queries[j]); + QueryObserverImpl observer = new QueryObserverImpl(); + QueryObserverHolder.setInstance(observer); + sr[j][1] = (SelectResults) q.execute(); + if (sr[j][1].size() == 0) { + fail("Query " + q.getQueryString() + " should have returned results"); + } + if (observer.isIndexesUsed) { + fail("Index should not be used for query '" + q.getQueryString() + "'"); + } + } + CacheUtils.compareResultsOfWithAndWithoutIndex(sr); + } + + @Test public void testUndefinedResultsAreReturnedWhenANotEqualsQueryIsExecuted() throws Exception { Portfolio p1 = new Portfolio(0); p1.position1 = null;