Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5258C185BD for ; Fri, 21 Aug 2015 09:05:03 +0000 (UTC) Received: (qmail 68508 invoked by uid 500); 21 Aug 2015 09:05:03 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 68472 invoked by uid 500); 21 Aug 2015 09:05:03 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 68461 invoked by uid 99); 21 Aug 2015 09:05:03 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Aug 2015 09:05:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id B701AC1268 for ; Fri, 21 Aug 2015 09:05:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.775 X-Spam-Level: * X-Spam-Status: No, score=1.775 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.006, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id bSdLXPo1Fn-V for ; Fri, 21 Aug 2015 09:05:01 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 156493693F for ; Fri, 21 Aug 2015 09:04:50 +0000 (UTC) Received: (qmail 66927 invoked by uid 99); 21 Aug 2015 09:04:47 -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; Fri, 21 Aug 2015 09:04:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 784ABE1091; Fri, 21 Aug 2015 09:04:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.incubator.apache.org Date: Fri, 21 Aug 2015 09:05:14 -0000 Message-Id: <7d054397ea9d404ca9b335c5e19c3444@git.apache.org> In-Reply-To: <779fb856b3ed494ea4064fff6d37aa26@git.apache.org> References: <779fb856b3ed494ea4064fff6d37aa26@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [29/44] incubator-ignite git commit: master - added test for group index bug master - added test for group index bug Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/515a8792 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/515a8792 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/515a8792 Branch: refs/heads/ignite-gg-9615-1 Commit: 515a8792bc0b5705d7ef556c0b54aba838fe4938 Parents: e18147d Author: S.Vladykin Authored: Thu Aug 20 15:12:21 2015 +0300 Committer: S.Vladykin Committed: Thu Aug 20 15:12:21 2015 +0300 ---------------------------------------------------------------------- .../query/IgniteSqlSplitterSelfTest.java | 123 ++++++++++++++----- 1 file changed, 93 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/515a8792/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 6ec6bb3..f97e4d2 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 @@ -20,13 +20,16 @@ package org.apache.ignite.internal.processors.query; import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.query.*; +import org.apache.ignite.cache.query.annotations.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.util.*; +import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; import org.apache.ignite.testframework.junits.common.*; +import java.io.*; import java.util.*; /** @@ -101,35 +104,65 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest { String qry = "select _val from Integer order by _val "; - assertEqualsCollections(res, - column(0, c.query(new SqlFieldsQuery(qry)).getAll())); - - assertEqualsCollections(res.subList(0, 0), - column(0, c.query(new SqlFieldsQuery(qry + "limit ?").setArgs(0)).getAll())); - - assertEqualsCollections(res.subList(0, 3), - column(0, c.query(new SqlFieldsQuery(qry + "limit ?").setArgs(3)).getAll())); - - assertEqualsCollections(res.subList(0, 9), - column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset ?").setArgs(9, 0)).getAll())); - - assertEqualsCollections(res.subList(3, 7), - column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset ?").setArgs(4, 3)).getAll())); - - assertEqualsCollections(res.subList(7, 9), - column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset ?").setArgs(2, 7)).getAll())); - - assertEqualsCollections(res.subList(8, 10), - column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset ?").setArgs(2, 8)).getAll())); - - assertEqualsCollections(res.subList(9, 10), - column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset ?").setArgs(1, 9)).getAll())); + assertEqualsCollections(res, columnQuery(c, qry)); + assertEqualsCollections(res.subList(0, 0), columnQuery(c, qry + "limit ?", 0)); + assertEqualsCollections(res.subList(0, 3), columnQuery(c, qry + "limit ?", 3)); + assertEqualsCollections(res.subList(0, 9), columnQuery(c, qry + "limit ? offset ?", 9, 0)); + assertEqualsCollections(res.subList(3, 7), columnQuery(c, qry + "limit ? offset ?", 4, 3)); + assertEqualsCollections(res.subList(7, 9), columnQuery(c, qry + "limit ? offset ?", 2, 7)); + assertEqualsCollections(res.subList(8, 10), columnQuery(c, qry + "limit ? offset ?", 2, 8)); + assertEqualsCollections(res.subList(9, 10), columnQuery(c, qry + "limit ? offset ?", 1, 9)); + assertEqualsCollections(res.subList(10, 10), columnQuery(c, qry + "limit ? offset ?", 1, 10)); + assertEqualsCollections(res.subList(9, 10), columnQuery(c, qry + "limit ? offset abs(-(4 + ?))", 1, 5)); + } + finally { + c.destroy(); + } + } - assertEqualsCollections(res.subList(10, 10), - column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset ?").setArgs(1, 10)).getAll())); + /** + * @throws Exception If failed. + */ + public void testGroupIndexOperations() throws Exception { + IgniteCache c = ignite(0).getOrCreateCache(cacheConfig("grp", false, + Integer.class, GroupIndexTestValue.class)); - assertEqualsCollections(res.subList(9, 10), - column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset abs(-(4 + ?))").setArgs(1, 5)).getAll())); + try { + // Check group index usage. + String qry = "select 1 from GroupIndexTestValue "; + + String plan = columnQuery(c, "explain " + qry + "where a = 1 and b > 0") + .get(0).toString(); + + info("Plan: " + plan); + + assertTrue(plan.contains("grpIdx")); + + // Sorted list + List list = F.asList( + new GroupIndexTestValue(0, 0), + new GroupIndexTestValue(0, 5), + new GroupIndexTestValue(1, 1), + new GroupIndexTestValue(1, 3), + new GroupIndexTestValue(2, -1), + new GroupIndexTestValue(2, 2) + ); + + // Fill cache. + for (int i = 0; i < list.size(); i++) + c.put(i, list.get(i)); + + // Check results. + assertEquals(1, columnQuery(c, qry + "where a = 1 and b = 1").size()); + assertEquals(2, columnQuery(c, qry + "where a = 1 and b < 4").size()); + assertEquals(2, columnQuery(c, qry + "where a = 1 and b <= 3").size()); + assertEquals(1, columnQuery(c, qry + "where a = 1 and b < 3").size()); + assertEquals(2, columnQuery(c, qry + "where a = 1 and b > 0").size()); + assertEquals(1, columnQuery(c, qry + "where a = 1 and b > 1").size()); + assertEquals(2, columnQuery(c, qry + "where a = 1 and b >= 1").size()); + assertEquals(4, columnQuery(c, qry + "where a > 0 and b > 0").size()); + assertEquals(4, columnQuery(c, qry + "where a > 0 and b >= 1").size()); + assertEquals(3, columnQuery(c, qry + "where a > 0 and b > 1").size()); } finally { c.destroy(); @@ -137,16 +170,46 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest { } /** + * @param c Cache. + * @param qry Query. + * @param args Arguments. + * @return Column as list. + */ + private static List columnQuery(IgniteCache c, String qry, Object... args) { + return column(0, c.query(new SqlFieldsQuery(qry).setArgs(args)).getAll()); + } + + /** * @param idx Column index. * @param rows Rows. * @return Column as list. */ - private static List column(int idx, List> rows) { - List res = new ArrayList<>(rows.size()); + private static List column(int idx, List> rows) { + List res = new ArrayList<>(rows.size()); for (List row : rows) - res.add(row.get(idx)); + res.add((X)row.get(idx)); return res; } + + /** + * Test value. + */ + private static class GroupIndexTestValue implements Serializable { + @QuerySqlField(orderedGroups = @QuerySqlField.Group(name = "grpIdx", order = 0)) + private int a; + + @QuerySqlField(orderedGroups = @QuerySqlField.Group(name = "grpIdx", order = 1)) + private int b; + + /** + * @param a A. + * @param b B. + */ + private GroupIndexTestValue(int a, int b) { + this.a = a; + this.b = b; + } + } }