http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java index 0da71c8..fae3188 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java @@ -44,7 +44,7 @@ import org.apache.ignite.spi.IgniteSpiException; import org.apache.ignite.testframework.GridStringLogger; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.h2.util.Utils; +import org.h2.util.JdbcUtils; import org.jetbrains.annotations.Nullable; /** @@ -101,8 +101,8 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract protected void startIndexing(IgniteH2Indexing spi) throws Exception { spi.start(null, null); - spi.registerCache(cacheCfg("A")); - spi.registerCache(cacheCfg("B")); + spi.registerCache(null, cacheCfg("A")); + spi.registerCache(null, cacheCfg("B")); } private CacheConfiguration cacheCfg(String name) { @@ -199,38 +199,38 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract public void testSpi() throws Exception { IgniteH2Indexing spi = getIndexing(); - assertEquals(-1, spi.size(typeAA.space(), typeAA, null)); - assertEquals(-1, spi.size(typeAB.space(), typeAB, null)); - assertEquals(-1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(-1, spi.size(typeAA.space(), typeAA)); + assertEquals(-1, spi.size(typeAB.space(), typeAB)); + assertEquals(-1, spi.size(typeBA.space(), typeBA)); spi.registerType(typeAA.space(), typeAA); - assertEquals(0, spi.size(typeAA.space(), typeAA, null)); - assertEquals(-1, spi.size(typeAB.space(), typeAB, null)); - assertEquals(-1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(0, spi.size(typeAA.space(), typeAA)); + assertEquals(-1, spi.size(typeAB.space(), typeAB)); + assertEquals(-1, spi.size(typeBA.space(), typeBA)); spi.registerType(typeAB.space(), typeAB); - assertEquals(0, spi.size(typeAA.space(), typeAA, null)); - assertEquals(0, spi.size(typeAB.space(), typeAB, null)); - assertEquals(-1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(0, spi.size(typeAA.space(), typeAA)); + assertEquals(0, spi.size(typeAB.space(), typeAB)); + assertEquals(-1, spi.size(typeBA.space(), typeBA)); spi.registerType(typeBA.space(), typeBA); // Initially all is empty. - assertEquals(0, spi.size(typeAA.space(), typeAA, null)); - assertEquals(0, spi.size(typeAB.space(), typeAB, null)); - assertEquals(0, spi.size(typeBA.space(), typeBA, null)); + assertEquals(0, spi.size(typeAA.space(), typeAA)); + assertEquals(0, spi.size(typeAB.space(), typeAB)); + assertEquals(0, spi.size(typeBA.space(), typeBA)); - assertFalse(spi.query(typeAA.space(), "select * from A.A", Collections.emptySet(), typeAA, null).hasNext()); - assertFalse(spi.query(typeAB.space(), "select * from A.B", Collections.emptySet(), typeAB, null).hasNext()); - assertFalse(spi.query(typeBA.space(), "select * from B.A", Collections.emptySet(), typeBA, null).hasNext()); + assertFalse(spi.queryLocalSql(typeAA.space(), "select * from A.A", Collections.emptySet(), typeAA, null).hasNext()); + assertFalse(spi.queryLocalSql(typeAB.space(), "select * from A.B", Collections.emptySet(), typeAB, null).hasNext()); + assertFalse(spi.queryLocalSql(typeBA.space(), "select * from B.A", Collections.emptySet(), typeBA, null).hasNext()); - assertFalse(spi.query(typeBA.space(), "select * from B.A, A.B, A.A", + assertFalse(spi.queryLocalSql(typeBA.space(), "select * from B.A, A.B, A.A", Collections.emptySet(), typeBA, null).hasNext()); try { - spi.query(typeBA.space(), "select aa.*, ab.*, ba.* from A.A aa, A.B ab, B.A ba", + spi.queryLocalSql(typeBA.space(), "select aa.*, ab.*, ba.* from A.A aa, A.B ab, B.A ba", Collections.emptySet(), typeBA, null).hasNext(); fail("Enumerations of aliases in select block must be prohibited"); @@ -239,10 +239,10 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract // all fine } - assertFalse(spi.query(typeAB.space(), "select ab.* from A.B ab", + assertFalse(spi.queryLocalSql(typeAB.space(), "select ab.* from A.B ab", Collections.emptySet(), typeAB, null).hasNext()); - assertFalse(spi.query(typeBA.space(), "select ba.* from B.A as ba", + assertFalse(spi.queryLocalSql(typeBA.space(), "select ba.* from B.A as ba", Collections.emptySet(), typeBA, null).hasNext()); // Nothing to remove. @@ -251,53 +251,53 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract spi.store(typeAA.space(), typeAA, key(1), aa(1, "Vasya", 10), "v1".getBytes(), 0); - assertEquals(1, spi.size(typeAA.space(), typeAA, null)); - assertEquals(0, spi.size(typeAB.space(), typeAB, null)); - assertEquals(0, spi.size(typeBA.space(), typeBA, null)); + assertEquals(1, spi.size(typeAA.space(), typeAA)); + assertEquals(0, spi.size(typeAB.space(), typeAB)); + assertEquals(0, spi.size(typeBA.space(), typeBA)); spi.store(typeAB.space(), typeAB, key(1), ab(1, "Vasya", 20, "Some text about Vasya goes here."), "v2".getBytes(), 0); // In one space all keys must be unique. - assertEquals(0, spi.size(typeAA.space(), typeAA, null)); - assertEquals(1, spi.size(typeAB.space(), typeAB, null)); - assertEquals(0, spi.size(typeBA.space(), typeBA, null)); + assertEquals(0, spi.size(typeAA.space(), typeAA)); + assertEquals(1, spi.size(typeAB.space(), typeAB)); + assertEquals(0, spi.size(typeBA.space(), typeBA)); spi.store(typeBA.space(), typeBA, key(1), ba(2, "Petya", 25, true), "v3".getBytes(), 0); // No replacement because of different space. - assertEquals(0, spi.size(typeAA.space(), typeAA, null)); - assertEquals(1, spi.size(typeAB.space(), typeAB, null)); - assertEquals(1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(0, spi.size(typeAA.space(), typeAA)); + assertEquals(1, spi.size(typeAB.space(), typeAB)); + assertEquals(1, spi.size(typeBA.space(), typeBA)); spi.store(typeBA.space(), typeBA, key(1), ba(2, "Kolya", 25, true), "v4".getBytes(), 0); // Replacement in the same table. - assertEquals(0, spi.size(typeAA.space(), typeAA, null)); - assertEquals(1, spi.size(typeAB.space(), typeAB, null)); - assertEquals(1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(0, spi.size(typeAA.space(), typeAA)); + assertEquals(1, spi.size(typeAB.space(), typeAB)); + assertEquals(1, spi.size(typeBA.space(), typeBA)); spi.store(typeAA.space(), typeAA, key(2), aa(2, "Valera", 19), "v5".getBytes(), 0); - assertEquals(1, spi.size(typeAA.space(), typeAA, null)); - assertEquals(1, spi.size(typeAB.space(), typeAB, null)); - assertEquals(1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(1, spi.size(typeAA.space(), typeAA)); + assertEquals(1, spi.size(typeAB.space(), typeAB)); + assertEquals(1, spi.size(typeBA.space(), typeBA)); spi.store(typeAA.space(), typeAA, key(3), aa(3, "Borya", 18), "v6".getBytes(), 0); - assertEquals(2, spi.size(typeAA.space(), typeAA, null)); - assertEquals(1, spi.size(typeAB.space(), typeAB, null)); - assertEquals(1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(2, spi.size(typeAA.space(), typeAA)); + assertEquals(1, spi.size(typeAB.space(), typeAB)); + assertEquals(1, spi.size(typeBA.space(), typeBA)); spi.store(typeAB.space(), typeAB, key(4), ab(4, "Vitalya", 20, "Very Good guy"), "v7".getBytes(), 0); - assertEquals(2, spi.size(typeAA.space(), typeAA, null)); - assertEquals(2, spi.size(typeAB.space(), typeAB, null)); - assertEquals(1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(2, spi.size(typeAA.space(), typeAA)); + assertEquals(2, spi.size(typeAB.space(), typeAB)); + assertEquals(1, spi.size(typeBA.space(), typeBA)); // Query data. Iterator<IgniteBiTuple<Integer, Map<String, Object>>> res = - spi.query(typeAA.space(), "from a order by age", Collections.emptySet(), typeAA, null); + spi.queryLocalSql(typeAA.space(), "from a order by age", Collections.emptySet(), typeAA, null); assertTrue(res.hasNext()); assertEquals(aa(3, "Borya", 18).value(null, false), value(res.next())); @@ -305,7 +305,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract assertEquals(aa(2, "Valera", 19).value(null, false), value(res.next())); assertFalse(res.hasNext()); - res = spi.query(typeAA.space(), "select aa.* from a aa order by aa.age", + res = spi.queryLocalSql(typeAA.space(), "select aa.* from a aa order by aa.age", Collections.emptySet(), typeAA, null); assertTrue(res.hasNext()); @@ -314,7 +314,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract assertEquals(aa(2, "Valera", 19).value(null, false), value(res.next())); assertFalse(res.hasNext()); - res = spi.query(typeAB.space(), "from b order by name", Collections.emptySet(), typeAB, null); + res = spi.queryLocalSql(typeAB.space(), "from b order by name", Collections.emptySet(), typeAB, null); assertTrue(res.hasNext()); assertEquals(ab(1, "Vasya", 20, "Some text about Vasya goes here.").value(null, false), value(res.next())); @@ -322,7 +322,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract assertEquals(ab(4, "Vitalya", 20, "Very Good guy").value(null, false), value(res.next())); assertFalse(res.hasNext()); - res = spi.query(typeAB.space(), "select bb.* from b as bb order by bb.name", + res = spi.queryLocalSql(typeAB.space(), "select bb.* from b as bb order by bb.name", Collections.emptySet(), typeAB, null); assertTrue(res.hasNext()); @@ -331,14 +331,15 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract assertEquals(ab(4, "Vitalya", 20, "Very Good guy").value(null, false), value(res.next())); assertFalse(res.hasNext()); - res = spi.query(typeBA.space(), "from a", Collections.emptySet(), typeBA, null); + + res = spi.queryLocalSql(typeBA.space(), "from a", Collections.emptySet(), typeBA, null); assertTrue(res.hasNext()); assertEquals(ba(2, "Kolya", 25, true).value(null, false), value(res.next())); assertFalse(res.hasNext()); // Text queries - Iterator<IgniteBiTuple<Integer, Map<String, Object>>> txtRes = spi.queryText(typeAB.space(), "good", + Iterator<IgniteBiTuple<Integer, Map<String, Object>>> txtRes = spi.queryLocalText(typeAB.space(), "good", typeAB, null); assertTrue(txtRes.hasNext()); @@ -347,8 +348,8 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract // Fields query GridQueryFieldsResult fieldsRes = - spi.queryFields("A", "select a.a.name n1, a.a.age a1, b.a.name n2, " + - "b.a.age a2 from a.a, b.a where a.a.id = b.a.id ", Collections.emptySet(), null); + spi.queryLocalSqlFields("A", "select a.a.name n1, a.a.age a1, b.a.name n2, " + + "b.a.age a2 from a.a, b.a where a.a.id = b.a.id ", Collections.emptySet(), null, false); String[] aliases = {"N1", "A1", "N2", "A2"}; Object[] vals = { "Valera", 19, "Kolya", 25}; @@ -371,15 +372,15 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract // Remove spi.remove(typeAA.space(), key(2), aa(2, "Valera", 19)); - assertEquals(1, spi.size(typeAA.space(), typeAA, null)); - assertEquals(2, spi.size(typeAB.space(), typeAB, null)); - assertEquals(1, spi.size(typeBA.space(), typeBA, null)); + assertEquals(1, spi.size(typeAA.space(), typeAA)); + assertEquals(2, spi.size(typeAB.space(), typeAB)); + assertEquals(1, spi.size(typeBA.space(), typeBA)); spi.remove(typeBA.space(), key(1), ba(2, "Kolya", 25, true)); - assertEquals(1, spi.size(typeAA.space(), typeAA, null)); - assertEquals(2, spi.size(typeAB.space(), typeAB, null)); - assertEquals(0, spi.size(typeBA.space(), typeBA, null)); + assertEquals(1, spi.size(typeAA.space(), typeAA)); + assertEquals(2, spi.size(typeAB.space(), typeAB)); + assertEquals(0, spi.size(typeBA.space(), typeBA)); boolean h2IdxOffheap = offheap(); @@ -389,9 +390,9 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract spi.rebuildIndexes(typeAB.space(), typeAB); - assertEquals(1, spi.size(typeAA.space(), typeAA, null)); - assertEquals(2, spi.size(typeAB.space(), typeAB, null)); - assertEquals(0, spi.size(typeBA.space(), typeBA, null)); + assertEquals(1, spi.size(typeAA.space(), typeAA)); + assertEquals(2, spi.size(typeAB.space(), typeAB)); + assertEquals(0, spi.size(typeBA.space(), typeBA)); // For invalid space name/type should not fail. spi.rebuildIndexes("not_existing_space", typeAA); @@ -401,22 +402,22 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract // Unregister. spi.unregisterType(typeAA.space(), typeAA); - assertEquals(-1, spi.size(typeAA.space(), typeAA, null)); - assertEquals(2, spi.size(typeAB.space(), typeAB, null)); - assertEquals(0, spi.size(typeBA.space(), typeBA, null)); + assertEquals(-1, spi.size(typeAA.space(), typeAA)); + assertEquals(2, spi.size(typeAB.space(), typeAB)); + assertEquals(0, spi.size(typeBA.space(), typeBA)); spi.unregisterType(typeAB.space(), typeAB); - assertEquals(-1, spi.size(typeAA.space(), typeAA, null)); - assertEquals(-1, spi.size(typeAB.space(), typeAB, null)); - assertEquals(0, spi.size(typeBA.space(), typeBA, null)); + assertEquals(-1, spi.size(typeAA.space(), typeAA)); + assertEquals(-1, spi.size(typeAB.space(), typeAB)); + assertEquals(0, spi.size(typeBA.space(), typeBA)); spi.unregisterType(typeBA.space(), typeBA); // Should not store but should not fail as well. spi.store(typeAA.space(), typeAA, key(10), aa(1, "Fail", 100500), "v220".getBytes(), 0); - assertEquals(-1, spi.size(typeAA.space(), typeAA, null)); + assertEquals(-1, spi.size(typeAA.space(), typeAA)); } /** @@ -447,7 +448,8 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract time = now; range *= 3; - GridQueryFieldsResult res = spi.queryFields("A", sql, Arrays.<Object>asList(1, range), null); + GridQueryFieldsResult res = spi.queryLocalSqlFields("A", sql, Arrays.<Object>asList(1, range), null, + false); assert res.iterator().hasNext(); @@ -525,6 +527,11 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract } /** {@inheritDoc} */ + @Override public String affinityKey() { + return null; + } + + /** {@inheritDoc} */ @Override public String name() { return name; } @@ -621,7 +628,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract /** {@inheritDoc} */ @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException { - return Utils.serialize(val, null); + return JdbcUtils.serialize(val, null); } /** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java index e70ee8d..8408ba0 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TableSelfTest.java @@ -33,6 +33,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.h2.Driver; import org.h2.index.Index; @@ -95,9 +96,9 @@ public class GridH2TableSelfTest extends GridCommonAbstractTest { IndexColumn str = tbl.indexColumn(2, SortOrder.DESCENDING); IndexColumn x = tbl.indexColumn(3, SortOrder.DESCENDING); - idxs.add(new GridH2TreeIndex(PK_NAME, tbl, true, 0, 1, id)); - idxs.add(new GridH2TreeIndex(NON_UNIQUE_IDX_NAME, tbl, false, 0, 1, x, t)); - idxs.add(new GridH2TreeIndex(STR_IDX_NAME, tbl, false, 0, 1, str)); + idxs.add(new GridH2TreeIndex(PK_NAME, tbl, true, F.asList(id))); + idxs.add(new GridH2TreeIndex(NON_UNIQUE_IDX_NAME, tbl, false, F.asList(x, t, id))); + idxs.add(new GridH2TreeIndex(STR_IDX_NAME, tbl, false, F.asList(str, id))); return idxs; } @@ -120,7 +121,8 @@ public class GridH2TableSelfTest extends GridCommonAbstractTest { * @return New row. */ private GridH2Row row(UUID id, long t, String str, long x) { - return new GridH2Row(ValueUuid.get(id.getMostSignificantBits(), id.getLeastSignificantBits()), + return GridH2RowFactory.create( + ValueUuid.get(id.getMostSignificantBits(), id.getLeastSignificantBits()), ValueTimestamp.get(new Timestamp(t)), ValueString.get(str), ValueLong.get(x)); http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java index ffe137f..f0ab123 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java @@ -30,6 +30,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; +import junit.framework.AssertionFailedError; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.CacheAtomicityMode; @@ -49,18 +50,21 @@ import org.jetbrains.annotations.Nullable; /** * Abstract test framework to compare query results from h2 database instance and mixed ignite caches (replicated and partitioned) - * which have the same data models and data content. + * which have the same data models and data content. */ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + /** */ + protected static final int SRVS = 4; + /** Partitioned cache. */ protected static IgniteCache pCache; /** Replicated cache. */ protected static IgniteCache rCache; - + /** H2 db connection. */ protected static Connection conn; @@ -77,14 +81,21 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest c.setMarshaller(new OptimizedMarshaller(true)); - c.setCacheConfiguration(createCache("part", CacheMode.PARTITIONED), - createCache("repl", CacheMode.REPLICATED) - ); + c.setCacheConfiguration(cacheConfigurations()); return c; } /** + * @return Cache configurations. + */ + protected CacheConfiguration[] cacheConfigurations() { + return new CacheConfiguration[] { + createCache("part", CacheMode.PARTITIONED), + createCache("repl", CacheMode.REPLICATED)}; + } + + /** * Creates new cache configuration. * * @param name Cache name. @@ -114,14 +125,14 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); - Ignite ignite = startGrids(4); + Ignite ignite = startGrids(SRVS); pCache = ignite.cache("part"); - + rCache = ignite.cache("repl"); awaitPartitionMapExchange(); - + conn = openH2Connection(false); initializeH2Schema(); @@ -130,22 +141,23 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest checkAllDataEquals(); } - + /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { super.afterTestsStopped(); Statement st = conn.createStatement(); - + st.execute("DROP ALL OBJECTS"); conn.close(); - + stopAllGrids(); } /** * Populate cache and h2 database with test data. + * @throws SQLException If failed. */ protected abstract void initCacheAndDbData() throws Exception; @@ -158,6 +170,7 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest * Initialize h2 database schema. * * @throws SQLException If exception. + * @return Statement. */ protected Statement initializeH2Schema() throws SQLException { Statement st = conn.createStatement(); @@ -175,11 +188,11 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest * @return Pooled connection. * @throws SQLException In case of error. */ - private Connection openH2Connection(boolean autocommit) throws SQLException { + protected Connection openH2Connection(boolean autocommit) throws SQLException { System.setProperty("h2.serializeJavaObject", "false"); - + String dbName = "test"; - + Connection conn = DriverManager.getConnection("jdbc:h2:mem:" + dbName + ";DB_CLOSE_DELAY=-1"); conn.setAutoCommit(autocommit); @@ -193,7 +206,7 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest * @param sql SQL query. * @param args SQL arguments. * then results will compare as ordered queries. - * @return Result set after SQL query execution. + * @return Result set after SQL query execution. * @throws SQLException If exception. */ protected final List<List<?>> compareQueryRes0(String sql, @Nullable Object... args) throws SQLException { @@ -201,14 +214,14 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest } /** - * Execute given sql query on h2 database and on ignite cache and compare results. + * Execute given sql query on h2 database and on ignite cache and compare results. * Expected that results are not ordered. * * @param cache Ignite cache. * @param sql SQL query. * @param args SQL arguments. * then results will compare as ordered queries. - * @return Result set after SQL query execution. + * @return Result set after SQL query execution. * @throws SQLException If exception. */ protected final List<List<?>> compareQueryRes0(IgniteCache cache, String sql, @Nullable Object... args) throws SQLException { @@ -239,20 +252,80 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest * then results will compare as ordered queries. * @return Result set after SQL query execution. * @throws SQLException If exception. - */ + */ + @SuppressWarnings("unchecked") + protected static List<List<?>> compareQueryRes0(IgniteCache cache, String sql, @Nullable Object[] args, + Ordering ordering) throws SQLException { + return compareQueryRes0(cache, sql, false, args, ordering); + } + + /** + * Execute given sql query on h2 database and on ignite cache and compare results. + * + * @param cache Ignite cache. + * @param sql SQL query. + * @param distrib Distributed SQL Join flag. + * @param args SQL arguments. + * @param ordering Expected ordering of SQL results. If {@link Ordering#ORDERED} + * then results will compare as ordered queries. + * @return Result set after SQL query execution. + * @throws SQLException If exception. + */ + protected static List<List<?>> compareQueryRes0(IgniteCache cache, + String sql, + boolean distrib, + @Nullable Object[] args, + Ordering ordering) throws SQLException { + return compareQueryRes0(cache, sql, distrib, false, args, ordering); + } + + /** + * Execute given sql query on h2 database and on ignite cache and compare results. + * + * @param cache Ignite cache. + * @param sql SQL query. + * @param distrib Distributed SQL Join flag. + * @param enforceJoinOrder Enforce join order flag. + * @param args SQL arguments. + * @param ordering Expected ordering of SQL results. If {@link Ordering#ORDERED} + * then results will compare as ordered queries. + * @return Result set after SQL query execution. + * @throws SQLException If exception. + */ @SuppressWarnings("unchecked") - protected final List<List<?>> compareQueryRes0(IgniteCache cache, String sql, @Nullable Object[] args, Ordering ordering) throws SQLException { + protected static List<List<?>> compareQueryRes0(IgniteCache cache, + String sql, + boolean distrib, + boolean enforceJoinOrder, + @Nullable Object[] args, + Ordering ordering) throws SQLException { if (args == null) args = new Object[] {null}; - - info("Sql query:\n" + sql + "\nargs=" + Arrays.toString(args)); List<List<?>> h2Res = executeH2Query(sql, args); - List<List<?>> cacheRes = cache.query(new SqlFieldsQuery(sql).setArgs(args)).getAll(); +// String plan = (String)((IgniteCache<Object, Object>)cache).query(new SqlFieldsQuery("explain " + sql) +// .setArgs(args) +// .setDistributedJoins(distrib)) +// .getAll().get(0).get(0); +// +// X.println("Plan : " + plan); + + List<List<?>> cacheRes = cache.query(new SqlFieldsQuery(sql). + setArgs(args). + setDistributedJoins(distrib). + setEnforceJoinOrder(enforceJoinOrder)).getAll(); + + try { + assertRsEquals(h2Res, cacheRes, ordering); + } + catch (AssertionFailedError e) { + X.println("Sql query:\n" + sql + "\nargs=" + Arrays.toString(args)); + X.println("[h2Res=" + h2Res + ", cacheRes=" + cacheRes + "]"); + + throw e; + } - assertRsEquals(h2Res, cacheRes, ordering); - return h2Res; } @@ -264,11 +337,11 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest * @return Result of SQL query on h2 database. * @throws SQLException If exception. */ - private List<List<?>> executeH2Query(String sql, Object[] args) throws SQLException { + private static List<List<?>> executeH2Query(String sql, Object[] args) throws SQLException { List<List<?>> res = new ArrayList<>(); ResultSet rs = null; - try(PreparedStatement st = conn.prepareStatement(sql)) { + try (PreparedStatement st = conn.prepareStatement(sql)) { for (int idx = 0; idx < args.length; idx++) st.setObject(idx + 1, args[idx]); @@ -278,17 +351,17 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest int colCnt = meta.getColumnCount(); - for (int i = 1; i <= colCnt; i++) - X.print(meta.getColumnLabel(i) + " "); - - X.println(); +// for (int i = 1; i <= colCnt; i++) +// X.print(meta.getColumnLabel(i) + " "); +// +// X.println(); while (rs.next()) { List<Object> row = new ArrayList<>(colCnt); - + for (int i = 1; i <= colCnt; i++) row.add(rs.getObject(i)); - + res.add(row); } } @@ -307,9 +380,9 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest * @param ordering Expected ordering of SQL results. If {@link Ordering#ORDERED} * then results will compare as ordered queries. */ - private void assertRsEquals(List<List<?>> rs1, List<List<?>> rs2, Ordering ordering) { + private static void assertRsEquals(List<List<?>> rs1, List<List<?>> rs2, Ordering ordering) { assertEquals("Rows count has to be equal.", rs1.size(), rs2.size()); - + switch (ordering){ case ORDERED: for (int rowNum = 0; rowNum < rs1.size(); rowNum++) { @@ -329,7 +402,7 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest assertEquals("Unique rows count has to be equal.", rowsWithCnt1.size(), rowsWithCnt2.size()); - X.println("Result size: " + rowsWithCnt1.size()); + // X.println("Result size: " + rowsWithCnt1.size()); Iterator<Map.Entry<String,Integer>> iter1 = rowsWithCnt1.entrySet().iterator(); Iterator<Map.Entry<String,Integer>> iter2 = rowsWithCnt2.entrySet().iterator(); @@ -343,15 +416,15 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest assertTrue(iter2.hasNext()); - Map.Entry<String,Integer> e1 = iter1.next(); - Map.Entry<String,Integer> e2 = iter2.next(); + Map.Entry<String, Integer> e1 = iter1.next(); + Map.Entry<String, Integer> e2 = iter2.next(); assertEquals(e1.getKey(), e2.getKey()); assertEquals(e1.getValue(), e2.getValue()); } - + break; - default: + default: throw new IllegalStateException(); } } @@ -360,30 +433,30 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest * @param rs Result set. * @return Map of unique rows at the result set to number of occuriances at the result set. */ - private TreeMap<String, Integer> extractUniqueRowsWithCounts(Iterable<List<?>> rs) { + private static TreeMap<String, Integer> extractUniqueRowsWithCounts(Iterable<List<?>> rs) { TreeMap<String, Integer> res = new TreeMap<>(); for (List<?> row : rs) { String rowStr = row.toString(); Integer cnt = res.get(rowStr); - + if (cnt == null) cnt = 0; - + res.put(rowStr, cnt + 1); } return res; } - + /** * Ordering type. */ protected enum Ordering { /** Random. */ - RANDOM, + RANDOM, /** Ordered. */ ORDERED } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java index 9fb5765..d6ee511 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java @@ -147,6 +147,8 @@ public class GridQueryParsingTest extends GridCommonAbstractTest { checkQuery("select avg(old) from Person left join Address where Person.addrId = Address.id " + "and lower(Address.street) = lower(?)"); + checkQuery("select avg(old) from Person right join Address where Person.addrId = Address.id " + + "and lower(Address.street) = lower(?)"); checkQuery("select avg(old) from Person, Address where Person.addrId = Address.id " + "and lower(Address.street) = lower(?)"); @@ -164,6 +166,7 @@ public class GridQueryParsingTest extends GridCommonAbstractTest { checkQuery("select person.* from Person, Address a"); checkQuery("select p.*, street from Person p, Address a"); checkQuery("select p.name, a.street from Person p, Address a"); + checkQuery("select p.name, a.street from Address a, Person p"); checkQuery("select distinct p.name, a.street from Person p, Address a"); checkQuery("select distinct name, street from Person, Address group by old"); checkQuery("select distinct name, street from Person, Address"); @@ -254,20 +257,6 @@ public class GridQueryParsingTest extends GridCommonAbstractTest { /** * */ - public void testExample1() throws Exception { - Query select = parse("select p.name n, max(p.old) maxOld, min(p.old) minOld from Person p group by p.name having maxOld > 10 and min(p.old) < 1"); - - GridSqlQueryParser ses = new GridSqlQueryParser(); - - GridSqlQuery gridSelect = ses.parse(select); - - //System.out.println(select.getPlanSQL()); - System.out.println(gridSelect.getSQL()); - } - - /** - * - */ private JdbcConnection connection() throws Exception { GridKernalContext ctx = ((IgniteEx)ignite).context(); http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryDistributedJoinsTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryDistributedJoinsTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryDistributedJoinsTest.java new file mode 100644 index 0000000..267778f --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryDistributedJoinsTest.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.query.h2.sql; + +/** + * Executes SQL big query test using distributed joins mode. + */ +public class H2CompareBigQueryDistributedJoinsTest extends H2CompareBigQueryTest { + /** {@inheritDoc} */ + @Override protected boolean distributedJoins() { + return true; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java index 255ac44..dc73e96 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java @@ -35,11 +35,11 @@ import org.apache.ignite.cache.query.annotations.QuerySqlField; import org.apache.ignite.configuration.CacheConfiguration; /** - * Executes one big query (and subqueries of the big query) to compare query results from h2 database instance and + * Executes one big query (and subqueries of the big query) to compare query results from h2 database instance and * mixed ignite caches (replicated and partitioned) which have the same data models and data content. - * - * - * <pre> + * + * + * <pre> * * -------------------------------------> rootOrderId (virtual) <-------------------------- * | | | @@ -75,20 +75,20 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { /** Dates count. */ private static final int DATES_CNT = 5; - + /** Full the big query. */ private String bigQry = getBigQry(); /** * Extracts the big query from file. - * + * * @return Big query. */ private String getBigQry() { String res = ""; Reader isr = new InputStreamReader(getClass().getResourceAsStream("bigQuery.sql")); - + try(BufferedReader reader = new BufferedReader(isr)) { for(String line; (line = reader.readLine()) != null; ) if (!line.startsWith("--")) // Skip commented lines. @@ -96,21 +96,35 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { } catch (Throwable e) { e.printStackTrace(); - + fail(); } return res; } + /** + * @return Use colocated data. + */ + private boolean useColocatedData() { + return !distributedJoins(); + } + + /** + * @return Whehter to use distrubutedJoins or not. + */ + protected boolean distributedJoins() { + return false; + } + /** {@inheritDoc} */ @Override protected void setIndexedTypes(CacheConfiguration<?, ?> cc, CacheMode mode) { if (mode == CacheMode.PARTITIONED) cc.setIndexedTypes( Integer.class, CustOrder.class, - AffinityKey.class, ReplaceOrder.class, - AffinityKey.class, OrderParams.class, - AffinityKey.class, Cancel.class + useColocatedData() ? AffinityKey.class : Integer.class, ReplaceOrder.class, + useColocatedData() ? AffinityKey.class : Integer.class, OrderParams.class, + useColocatedData() ? AffinityKey.class : Integer.class, Cancel.class ); else if (mode == CacheMode.REPLICATED) cc.setIndexedTypes( @@ -142,8 +156,8 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { // Generate 1 - 5 orders for 1 root order. for (int i = 0; i < rootOrderId % 5; i++) { int orderId = idGen.incrementAndGet(); - - CustOrder order = new CustOrder(orderId, rootOrderId, dates.get(orderId % dates.size()) , + + CustOrder order = new CustOrder(orderId, rootOrderId, dates.get(orderId % dates.size()) , orderId % 2 == 0 ? "CUSTOM" : "OTHER", orderId); add(order); @@ -151,23 +165,23 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { pCache.put(order.orderId, order); insertInDb(order); - } + } } }}; final Collection<OrderParams> params = new ArrayList<OrderParams>(){{ for (CustOrder o : orders) { - OrderParams op = new OrderParams(idGen.incrementAndGet(), o.orderId, o.date, + OrderParams op = new OrderParams(idGen.incrementAndGet(), o.orderId, o.date, o.orderId % 2 == 0 ? "Algo 1" : "Algo 2"); add(op); - pCache.put(op.key(), op); + pCache.put(op.key(useColocatedData()), op); insertInDb(op); } }}; - + final Collection<ReplaceOrder> replaces = new ArrayList<ReplaceOrder>(){{ for (CustOrder o : orders) { if (o.orderId % 7 == 0) { @@ -176,7 +190,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { add(replace); - pCache.put(replace.key(), replace); + pCache.put(replace.key(useColocatedData()), replace); insertInDb(replace); } @@ -186,12 +200,12 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { final Collection<Cancel> cancels = new ArrayList<Cancel>(){{ for (CustOrder o : orders) { if (o.orderId % 9 == 0) { - Cancel c = new Cancel(idGen.incrementAndGet(), o.orderId, + Cancel c = new Cancel(idGen.incrementAndGet(), o.orderId, new Date(o.date.getTime() + 12 * 60 * 60 * 1000));// Plus a half of day. add(c); - pCache.put(c.key(), c); + pCache.put(c.key(useColocatedData()), c); insertInDb(c); } @@ -203,7 +217,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { int execShares = 10000 + rootOrderId; int price = 1000 + rootOrderId; int latsMkt = 3000 + rootOrderId; - + Exec exec = new Exec(rootOrderId, dates.get(rootOrderId % dates.size()), execShares, price, latsMkt); add(exec); @@ -232,8 +246,8 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { * @throws Exception If failed. */ public void testBigQuery() throws Exception { - List<List<?>> res = compareQueryRes0(bigQry); - + List<List<?>> res = compareQueryRes0(pCache, bigQry, distributedJoins(), new Object[0], Ordering.RANDOM); + assertTrue(!res.isEmpty()); // Ensure we set good testing data at database. } @@ -241,6 +255,8 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { @Override protected Statement initializeH2Schema() throws SQLException { Statement st = super.initializeH2Schema(); + final String keyType = useColocatedData() ? "other" : "int"; + st.execute("create table \"part\".CustOrder" + " (" + " _key int not null," + @@ -255,7 +271,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { st.execute("create table \"part\".ReplaceOrder" + " (" + - " _key other not null," + + " _key " + keyType + " not null," + " _val other not null," + " id int unique," + " orderId int ," + @@ -268,7 +284,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { st.execute("create table \"part\".OrderParams" + " (" + - " _key other not null," + + " _key " + keyType + " not null," + " _val other not null," + " id int unique," + " orderId int ," + @@ -278,7 +294,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { st.execute("create table \"part\".Cancel" + " (" + - " _key other not null," + + " _key " + keyType + " not null," + " _val other not null," + " id int unique," + " date Date, " + @@ -295,15 +311,15 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { " price int," + " lastMkt int" + " )"); - + conn.commit(); - + return st; } /** * Insert {@link CustOrder} at h2 database. - * + * * @param o CustOrder. */ private void insertInDb(CustOrder o) throws SQLException { @@ -311,7 +327,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { "insert into \"part\".CustOrder (_key, _val, orderId, rootOrderId, date, alias, archSeq, origOrderId) " + "values(?, ?, ?, ?, ?, ?, ?, ?)")) { int i = 0; - + st.setObject(++i, o.orderId); st.setObject(++i, o); st.setObject(++i, o.orderId); @@ -335,8 +351,8 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { "insert into \"part\".ReplaceOrder (_key, _val, id, orderId, rootOrderId, date, alias, archSeq, refOrderId) " + "values(?, ?, ?, ?, ?, ?, ?, ?, ?)")) { int i = 0; - - st.setObject(++i, o.key()); + + st.setObject(++i, o.key(useColocatedData())); st.setObject(++i, o); st.setObject(++i, o.id); st.setObject(++i, o.orderId); @@ -359,15 +375,15 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { try(PreparedStatement st = conn.prepareStatement( "insert into \"part\".OrderParams (_key, _val, id, date, orderId, parentAlgo) values(?, ?, ?, ?, ?, ?)")) { int i = 0; - - st.setObject(++i, o.key()); + + st.setObject(++i, o.key(useColocatedData())); st.setObject(++i, o); st.setObject(++i, o.id); st.setObject(++i, o.date); st.setObject(++i, o.orderId); st.setObject(++i, o.parentAlgo); - st.executeUpdate(); + st.executeUpdate(); } } @@ -380,8 +396,8 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { try(PreparedStatement st = conn.prepareStatement( "insert into \"part\".Cancel (_key, _val, id, date, refOrderId) values(?, ?, ?, ?, ?)")) { int i = 0; - - st.setObject(++i, o.key()); + + st.setObject(++i, o.key(useColocatedData())); st.setObject(++i, o); st.setObject(++i, o.id); st.setObject(++i, o.date); @@ -401,7 +417,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { "insert into \"repl\".Exec (_key, _val, date, rootOrderId, execShares, price, lastMkt) " + "values(?, ?, ?, ?, ?, ?, ?)")) { int i = 0; - + st.setObject(++i, o.rootOrderId); st.setObject(++i, o); st.setObject(++i, o.date); @@ -475,7 +491,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { /** Primary key. */ @QuerySqlField(index = true) private int id; - + /** Order id. */ @QuerySqlField(index = true) private int orderId; @@ -518,10 +534,11 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { } /** - * @return Afinity key. + * @param useColocatedData Use colocated data. + * @return Key. */ - public AffinityKey<Integer> key() { - return new AffinityKey<>(id, orderId); + public Object key(boolean useColocatedData) { + return useColocatedData ? new AffinityKey<>(id, orderId) : id; } /** {@inheritDoc} */ @@ -569,10 +586,11 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { } /** - * @return Afinity key. + * @param useColocatedData Use colocated data.* + * @return Key. */ - public AffinityKey<Integer> key() { - return new AffinityKey<>(id, orderId); + public Object key(boolean useColocatedData) { + return useColocatedData ? new AffinityKey<>(id, orderId) : id; } /** {@inheritDoc} */ @@ -603,7 +621,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { private Date date; /** - * @param id + * @param id ID. * @param refOrderId Reference order id. * @param date Date. */ @@ -614,10 +632,11 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { } /** - * @return Afinity key. + * @param useColocatedData Use colocated data. + * @return Key. */ - public AffinityKey<Integer> key() { - return new AffinityKey<>(id, refOrderId); + public Object key(boolean useColocatedData) { + return useColocatedData ? new AffinityKey<>(id, refOrderId) : id; } /** {@inheritDoc} */ @@ -680,4 +699,4 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest { return rootOrderId; } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java index 1b1908d..65a94dd 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java @@ -22,11 +22,19 @@ import org.apache.ignite.internal.processors.cache.GridCacheCrossCacheQuerySelfT import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexDisabledSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheQueryInternalKeysSelfTest; import org.apache.ignite.internal.processors.cache.GridCacheQuerySerializationSelfTest; -import org.apache.ignite.internal.processors.cache.GridCacheReduceQueryMultithreadedSelfTest; import org.apache.ignite.internal.processors.cache.IgniteBinaryObjectFieldsQuerySelfTest; import org.apache.ignite.internal.processors.cache.IgniteBinaryWrappedObjectFieldsQuerySelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheCollocatedQuerySelfTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheCrossCacheJoinRandomTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheDistributedJoinCollocatedAndNotTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheDistributedJoinCustomAffinityMapper; +import org.apache.ignite.internal.processors.cache.IgniteCacheDistributedJoinPartitionedAndReplicatedTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheDistributedJoinQueryConditionsTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheDistributedJoinTest; import org.apache.ignite.internal.processors.cache.IgniteCacheDuplicateEntityConfigurationSelfTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheDistributedJoinNoIndexTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheJoinPartitionedAndReplicatedTest; +import org.apache.ignite.internal.processors.cache.IgniteCacheJoinQueryWithAffinityKeyTest; import org.apache.ignite.internal.processors.cache.IgniteCacheLargeResultSelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapEvictQueryTest; import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapIndexScanTest; @@ -41,6 +49,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheQueryMultiThreaded import org.apache.ignite.internal.processors.cache.IgniteCacheQueryOffheapEvictsMultiThreadedSelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheQueryOffheapMultiThreadedSelfTest; import org.apache.ignite.internal.processors.cache.IgniteCacheSqlQueryMultiThreadedSelfTest; +import org.apache.ignite.internal.processors.cache.IgniteCrossCachesJoinsQueryTest; import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheAtomicNearEnabledQuerySelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheAtomicQuerySelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheClientQueryReplicatedNodeRestartSelfTest; @@ -49,6 +58,7 @@ import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheP import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCachePartitionedSnapshotEnabledQuerySelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryNoRebalanceSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryNodeFailTest; +import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryNodeRestartDistributedJoinSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryNodeRestartSelfTest; import org.apache.ignite.internal.processors.cache.distributed.near.IgniteCacheQueryNodeRestartSelfTest2; import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQueryP2PDisabledSelfTest; @@ -106,9 +116,9 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite { suite.addTestSuite(IgniteCacheOffheapIndexScanTest.class); suite.addTestSuite(IgniteCacheQueryNodeRestartSelfTest.class); suite.addTestSuite(IgniteCacheQueryNodeRestartSelfTest2.class); + suite.addTestSuite(IgniteCacheQueryNodeRestartDistributedJoinSelfTest.class); suite.addTestSuite(IgniteCacheQueryNodeFailTest.class); suite.addTestSuite(IgniteCacheClientQueryReplicatedNodeRestartSelfTest.class); - suite.addTestSuite(GridCacheReduceQueryMultithreadedSelfTest.class); suite.addTestSuite(GridCacheCrossCacheQuerySelfTest.class); suite.addTestSuite(GridCacheQuerySerializationSelfTest.class); suite.addTestSuite(IgniteBinaryObjectFieldsQuerySelfTest.class); @@ -116,6 +126,17 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite { suite.addTestSuite(IgniteCacheQueryH2IndexingLeakTest.class); suite.addTestSuite(IgniteCacheQueryNoRebalanceSelfTest.class); + suite.addTestSuite(IgniteCacheJoinQueryWithAffinityKeyTest.class); + suite.addTestSuite(IgniteCacheDistributedJoinCollocatedAndNotTest.class); + suite.addTestSuite(IgniteCacheDistributedJoinPartitionedAndReplicatedTest.class); + suite.addTestSuite(IgniteCacheDistributedJoinQueryConditionsTest.class); + suite.addTestSuite(IgniteCacheDistributedJoinTest.class); + suite.addTestSuite(IgniteCacheJoinPartitionedAndReplicatedTest.class); + suite.addTestSuite(IgniteCacheDistributedJoinNoIndexTest.class); + suite.addTestSuite(IgniteCrossCachesJoinsQueryTest.class); + suite.addTestSuite(IgniteCacheCrossCacheJoinRandomTest.class); + suite.addTestSuite(IgniteCacheDistributedJoinCustomAffinityMapper.class); + return suite; } } http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java index e5f4027..7cb1adb 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite2.java @@ -40,10 +40,6 @@ import org.apache.ignite.internal.processors.cache.distributed.replicated.Ignite import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedFieldsQuerySelfTest; import org.apache.ignite.internal.processors.cache.local.IgniteCacheLocalFieldsQuerySelfTest; import org.apache.ignite.internal.processors.cache.query.GridCacheSwapScanQuerySelfTest; -import org.apache.ignite.internal.processors.cache.reducefields.GridCacheReduceFieldsQueryAtomicSelfTest; -import org.apache.ignite.internal.processors.cache.reducefields.GridCacheReduceFieldsQueryLocalSelfTest; -import org.apache.ignite.internal.processors.cache.reducefields.GridCacheReduceFieldsQueryPartitionedSelfTest; -import org.apache.ignite.internal.processors.cache.reducefields.GridCacheReduceFieldsQueryReplicatedSelfTest; import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest; import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryTest; import org.apache.ignite.spi.communication.tcp.GridOrderedMessageCancelSelfTest; @@ -73,12 +69,6 @@ public class IgniteCacheQuerySelfTestSuite2 extends TestSuite { suite.addTestSuite(IgniteCachePartitionedFieldsQueryP2PEnabledSelfTest.class); suite.addTestSuite(IgniteCacheFieldsQueryNoDataSelfTest.class); - // Reduce fields queries. - suite.addTestSuite(GridCacheReduceFieldsQueryLocalSelfTest.class); - suite.addTestSuite(GridCacheReduceFieldsQueryPartitionedSelfTest.class); - suite.addTestSuite(GridCacheReduceFieldsQueryAtomicSelfTest.class); - suite.addTestSuite(GridCacheReduceFieldsQueryReplicatedSelfTest.class); - suite.addTestSuite(GridCacheQueryIndexingDisabledSelfTest.class); suite.addTestSuite(GridCacheSwapScanQuerySelfTest.class); http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkUtils.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkUtils.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkUtils.java index 0b7568b..af060d4 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkUtils.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/IgniteBenchmarkUtils.java @@ -26,6 +26,10 @@ import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; import org.apache.ignite.transactions.TransactionOptimisticException; import org.apache.ignite.transactions.TransactionRollbackException; +import org.apache.ignite.yardstick.cache.IgniteSqlQueryBenchmark; +import org.apache.ignite.yardstick.cache.IgniteSqlQueryDistributedJoinBenchmark; +import org.yardstickframework.BenchmarkDriverStartUp; +import org.yardstickframework.BenchmarkServerStartUp; /** * Utils. @@ -72,4 +76,45 @@ public class IgniteBenchmarkUtils { } } } + +// /** +// * Starts driver for quick benchmarks testing. +// * +// * @param args Command line arguments. +// * @throws Exception If failed. +// */ +// public static void main(String[] args) throws Exception { +// String[] args0 = { +// "-t", "1", +// "-w", "5", +// "-d", "5", +// "-dn", IgniteSqlQueryDistributedJoinBenchmark.class.getSimpleName(), +// "-r", "100", +// "-sn", "IgniteNode", +// "-bcj", +// "-cfg", "modules/yardstick/config/ignite-localhost-config.xml"}; +// +// BenchmarkDriverStartUp.main(args0); +// } + + /** + * Starts driver for quick benchmarks testing. + * + * @param args Command line arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + String[] args0 = { + "-t", "15", + "-w", "30", + "-d", "60", + "-cl", + "-pr", "ThroughputLatencyProbe", + "-dn", IgniteSqlQueryBenchmark.class.getSimpleName(), + "-r", "100000", + "-sn", "IgniteNode", + "-cfg", "modules/yardstick/config/ignite-localhost-config.xml"}; + + BenchmarkDriverStartUp.main(args0); + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBenchmark.java new file mode 100644 index 0000000..1f009e6 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBenchmark.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.yardstick.cache.model.Organization; +import org.apache.ignite.yardstick.cache.model.Person; +import org.yardstickframework.BenchmarkConfiguration; + +import static org.yardstickframework.BenchmarkUtils.println; + +/** + * Ignite benchmark that performs query operations with joins. + */ +public class IgniteSqlQueryDistributedJoinBenchmark extends IgniteCacheAbstractBenchmark<Integer, Object> { + /** */ + private int orgRange; + + /** */ + private boolean broadcast; + + /** {@inheritDoc} */ + @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { + super.setUp(cfg); + + broadcast = broadcastJoin(); + + println(cfg, "Populating query data..."); + + long start = System.nanoTime(); + + int personCnt = 0; + + try (IgniteDataStreamer<Object, Object> dataLdr = ignite().dataStreamer(cache.getName())) { + orgRange = args.range() / 10; + + if (orgRange <= 0) + throw new IllegalArgumentException(); + + // Populate organizations. + for (int orgId = 0; orgId < orgRange; orgId++) { + dataLdr.addData(orgId, new Organization(orgId, "org" + orgId)); + + if (orgId % 1000 == 0 && Thread.currentThread().isInterrupted()) + return; + } + + dataLdr.flush(); + + // Populate persons. + for (int orgId = 0; orgId < orgRange; orgId++) { + int persons = orgId % 10 + 1; + + for (int j = 0; j < persons; j++) { + int personId = orgRange + personCnt++; + + Person p = new Person(personId, + orgId, + "firstName" + personId, + "lastName" + personId, 1000); + + dataLdr.addData(personId, p); + } + + if (personCnt % 100000 == 0) + println(cfg, "Populated persons: " + personCnt); + + if (orgId % 1000 == 0 && Thread.currentThread().isInterrupted()) + return; + } + + dataLdr.close(); + } + + println(cfg, "Finished populating join query [orgCnt=" + orgRange + + ", personCnt=" + personCnt + + ", broadcastJoin=" + broadcast + + ", time=" + ((System.nanoTime() - start) / 1_000_000) + "ms]"); + + executeQueryJoin(0, broadcast, true); + } + + /** + * @return Broadcast join flag. + */ + protected boolean broadcastJoin() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + int orgId = nextRandom(orgRange); + + Collection<List<?>> res = executeQueryJoin(orgId, broadcast, false); + + int persons = orgId % 10 + 1; + + if (res.size() != persons) + throw new Exception("Invalid join result [orgId=" + orgId + ", resSize=" + res.size() + ']'); + + for (List<?> l : res) { + int orgId0 = (Integer)l.get(1); + + if (orgId != orgId0) + throw new Exception("Invalid join result [orgId=" + orgId + ", res=" + l + ']'); + } + + return true; + } + + /** + * @param orgId Organization ID. + * @param broadcast Broadcast join flag. + * @param planOnly If {@code true} just prints query plan. + * @return Query results. + * @throws Exception If failed. + */ + private Collection<List<?>> executeQueryJoin(int orgId, boolean broadcast, boolean planOnly) throws Exception { + SqlFieldsQuery qry; + + String sql; + + if (broadcast) { + sql = "select p.id, p.orgId, p.firstName, p.lastName, o.name " + + "from Person p " + + "join Organization o " + + "on p.orgId = o.id " + + "where o.id=?"; + } + else { + sql = "select p.id, p.orgId, p.firstName, p.lastName, o.name " + + "from Organization o " + + "join Person p " + + "on p.orgId = o._key " + + "where o._key=?"; + } + + qry = new SqlFieldsQuery(planOnly ? ("explain " + sql) : sql); + qry.setDistributedJoins(true); + qry.setArgs(orgId); + + if (planOnly) { + String plan = (String)cache.query(qry).getAll().get(0).get(0); + + println("Query execution plan:\n" + plan); + + if (broadcast) { + if (plan.contains("batched:unicast") || !plan.contains("batched:broadcast")) + throw new Exception("Unexpected query plan: " + plan); + } + else if (!plan.contains("batched:unicast") || plan.contains("batched:broadcast")) + throw new Exception("Unexpected query plan: " + plan); + + return null; + } + else + return cache.query(qry).getAll(); + } + + /** {@inheritDoc} */ + @Override protected IgniteCache<Integer, Object> cache() { + return ignite().cache("query"); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBroadcastBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBroadcastBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBroadcastBenchmark.java new file mode 100644 index 0000000..8b03e3e --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryDistributedJoinBroadcastBenchmark.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache; + +/** + * + */ +public class IgniteSqlQueryDistributedJoinBroadcastBenchmark extends IgniteSqlQueryDistributedJoinBenchmark { + /** {@inheritDoc} */ + @Override protected boolean broadcastJoin() { + return true; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/68891e89/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 3e9a71c..ebd6bf0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -35,8 +35,9 @@ <properties> <ignite.edition>fabric</ignite.edition> - - <!-- Build parameters. --> + <hadoop.version>2.4.1</hadoop.version> + <spark.version>1.5.2</spark.version> + <spring.version>4.1.0.RELEASE</spring.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.build.timestamp.format>MMMM d yyyy</maven.build.timestamp.format> <doxygen.exec>doxygen</doxygen.exec> @@ -69,7 +70,7 @@ <guava.version>18.0</guava.version> <guava14.version>14.0.1</guava14.version> <guava16.version>16.0.1</guava16.version> - <h2.version>1.3.175</h2.version> + <h2.version>1.4.191</h2.version> <hadoop.version>2.4.1</hadoop.version> <httpclient.version>4.5.1</httpclient.version> <httpcore.version>4.4.3</httpcore.version> @@ -188,6 +189,23 @@ </developer> </developers> + <repositories> + <repository> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + <updatePolicy>always</updatePolicy> + <checksumPolicy>ignore</checksumPolicy> + </snapshots> + <id>h2database.com</id> + <name>Snapshot repository on h2database.com</name> + <url>http://h2database.com/m2-repo</url> + <layout>default</layout> + </repository> + </repositories> + <dependencyManagement> <dependencies> <dependency>
