You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2022/01/11 12:36:41 UTC
[ignite] 01/02: Add test
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch ignite-16261
in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 068a15921f654481de41f23cbd5c38ede9c1dc51
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Tue Jan 11 15:34:50 2022 +0300
Add test
---
...gniteCacheJoinPartitionedAndReplicatedTest.java | 101 +++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java
index c607e64..fc1b8750 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheJoinPartitionedAndReplicatedTest.java
@@ -207,6 +207,107 @@ public class IgniteCacheJoinPartitionedAndReplicatedTest extends GridCommonAbstr
}
/**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testSubquery() {
+ Ignite client = grid(2);
+
+ IgniteCache<Object, Object> personCache = client.cache(PERSON_CACHE);
+ IgniteCache<Object, Object> orgCache = client.cache(ORG_CACHE);
+ IgniteCache<Object, Object> orgCacheRepl = client.cache(ORG_CACHE_REPLICATED);
+
+ List<Integer> keys = primaryKeys(ignite(0).cache(PERSON_CACHE), 4, 200_000);
+
+ orgCache.put(keys.get(0), new Organization(0, "org1"));
+ orgCacheRepl.put(keys.get(0), new Organization(0, "org1"));
+
+ personCache.put(keys.get(1), new Person(0, "p1"));
+ personCache.put(keys.get(2), new Person(0, "p2"));
+ personCache.put(keys.get(3), new Person(0, "p3"));
+
+ // Subquery in `WHERE` clause
+ checkQuery("select p._key, p.name " +
+ "from \"person\".Person p where " +
+ "p.orgId in (select o.id from \"org\".Organization o)", orgCache, 3);
+
+ checkQuery("select o.name " +
+ "from \"org\".Organization o where " +
+ "o.id in (select p.orgId from \"person\".Person p)", orgCache, 1);
+
+ checkQuery("select p._key, p.name " +
+ "from \"person\".Person p where " +
+ "p.orgId in (select o.id from \"org\".Organization o)", orgCacheRepl, 3);
+
+ checkQuery("select o.name " +
+ "from \"org\".Organization o where " +
+ "o.id in (select p.orgId from \"person\".Person p)", orgCacheRepl, 1);
+
+ // Prevent `IN` optimization.
+ checkQuery("select p._key, p.name " +
+ "from \"person\".Person p where " +
+ "p.orgId < 10 or p.orgId in (select o.id from \"org\".Organization o)", orgCache, 3);
+
+ checkQuery("select o.name " +
+ "from \"org\".Organization o where " +
+ "o.id < 10 or o.id in (select p.orgId from \"person\".Person p)", orgCache, 1);
+
+ checkQuery("select p._key, p.name " +
+ "from \"person\".Person p where " +
+ "p.orgId < 10 or p.orgId in (select o.id from \"org\".Organization o)", orgCacheRepl, 3);
+
+ checkQuery("select o.name " +
+ "from \"org\".Organization o where " +
+ "o.id < 10 or o.id in (select p.orgId from \"person\".Person p)", orgCacheRepl, 1);
+
+ // Subquery in `FROM` clause
+ checkQuery("select p1._key, p1.name " +
+ "from (select p._key, p.name, p.orgId from \"person\".Person p " +
+ " where p.orgId < 10 or p.orgId in (select o.id from \"org\".Organization o)) p1 " +
+ "where p1.orgId > -1", orgCache, 3);
+
+ checkQuery("select o1.name " +
+ "from (select o.id, o.name from \"org\".Organization o " +
+ " where o.id < 10 or o.id in (select p.orgId from \"person\".Person p)) o1 " +
+ "where o1.id > -1", orgCache, 1);
+
+ checkQuery("select p1._key, p1.name " +
+ "from (select p._key, p.name, p.orgId from \"person\".Person p " +
+ " where p.orgId < 10 or p.orgId in (select o.id from \"org\".Organization o)) p1 " +
+ "where p1.orgId > -1", orgCacheRepl, 3);
+
+ checkQuery("select o1.name " +
+ "from (select o.id, o.name from \"org\".Organization o " +
+ " where o.id < 10 or o.id in (select p.orgId from \"person\".Person p)) o1 " +
+ "where o1.id > -1", orgCacheRepl, 1);
+
+ // Join with subquery
+ checkQuery("select o1.name, p._key, p.name " +
+ "from \"person\".Person p " +
+ "join (select o.id, o.name from \"org\".Organization o " +
+ " where o.id < 10 or o.id in (select p.orgId from \"person\".Person p)) o1 " +
+ "on (p.orgId = o1.id)", orgCache, 3);
+
+ checkQuery("select o.name, p1._key, p1.name " +
+ "from \"org\".Organization o " +
+ "join (select p._key, p.name, p.orgId from \"person\".Person p " +
+ " where p.orgId < 10 or p.orgId in (select o.id from \"org\".Organization o)) p1 " +
+ "on (p1.orgId = o.id)", orgCache, 3);
+
+ checkQuery("select o1.name, p._key, p.name " +
+ "from \"person\".Person p " +
+ "join (select o.id, o.name from \"org\".Organization o " +
+ " where o.id < 10 or o.id in (select p.orgId from \"person\".Person p)) o1 " +
+ "on (p.orgId = o1.id)", orgCacheRepl, 3);
+
+ checkQuery("select o.name, p1._key, p1.name " +
+ "from \"org\".Organization o " +
+ "join (select p._key, p.name, p.orgId from \"person\".Person p " +
+ " where p.orgId < 10 or p.orgId in (select o.id from \"org\".Organization o)) p1 " +
+ "on (p1.orgId = o.id)", orgCacheRepl, 3);
+ }
+
+ /**
* @param sql SQL.
* @param cache Cache.
* @param expSize Expected results size.