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/feature/GEODE-2632-17
Commit: 9c408681364973096cf4192255ec3f40d86b70bd
Parents: db81d92
Author: nabarun <[email protected]>
Authored: Mon May 22 11:34:52 2017 -0700
Committer: nabarun <[email protected]>
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;