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 4670A1040E for ; Tue, 18 Aug 2015 16:12:01 +0000 (UTC) Received: (qmail 10707 invoked by uid 500); 18 Aug 2015 16:12:01 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 10671 invoked by uid 500); 18 Aug 2015 16:12:01 -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 10658 invoked by uid 99); 18 Aug 2015 16:12:01 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Aug 2015 16:12:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 9AE911AA6A4 for ; Tue, 18 Aug 2015 16:12:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-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-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 7xNlgS4AFVdw for ; Tue, 18 Aug 2015 16:11:58 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id DDB3A42F39 for ; Tue, 18 Aug 2015 16:11:51 +0000 (UTC) Received: (qmail 10076 invoked by uid 99); 18 Aug 2015 16:11:51 -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, 18 Aug 2015 16:11:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 47041DFFED; Tue, 18 Aug 2015 16:11:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.incubator.apache.org Date: Tue, 18 Aug 2015 16:12:32 -0000 Message-Id: In-Reply-To: <11b7bbb6ec4243d1b23d9ecb93a60749@git.apache.org> References: <11b7bbb6ec4243d1b23d9ecb93a60749@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [43/46] incubator-ignite git commit: master - OFFSET clause fix IGNITE-1259 master - OFFSET clause fix IGNITE-1259 Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/d31c8c64 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d31c8c64 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d31c8c64 Branch: refs/heads/ignite-843 Commit: d31c8c6477e03563bf73db3cf216250b9c22b562 Parents: 9c939be Author: S.Vladykin Authored: Mon Aug 17 21:25:25 2015 +0300 Committer: S.Vladykin Committed: Mon Aug 17 21:25:25 2015 +0300 ---------------------------------------------------------------------- .../query/h2/sql/GridSqlQuerySplitter.java | 3 + .../query/IgniteSqlSplitterSelfTest.java | 152 +++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite.java | 2 + 3 files changed, 157 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d31c8c64/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java index 2f8bcdd..34aef87 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java @@ -205,6 +205,9 @@ public class GridSqlQuerySplitter { if (mapQry.offset() != null) { rdcQry.offset(mapQry.offset()); + if (mapQry.limit() != null) // LIMIT off + lim + mapQry.limit(op(GridSqlOperationType.PLUS, mapQry.offset(), mapQry.limit())); + mapQry.offset(null); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d31c8c64/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 new file mode 100644 index 0000000..6ec6bb3 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java @@ -0,0 +1,152 @@ +/* + * 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; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.util.*; +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.util.*; + +/** + * Tests for correct distributed partitioned queries. + */ +@SuppressWarnings("unchecked") +public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration() throws Exception { + IgniteConfiguration cfg = super.getConfiguration(); + + cfg.setPeerClassLoadingEnabled(false); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGridsMultiThreaded(3, false); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** + * @param name Cache name. + * @param partitioned Partition or replicated cache. + * @param idxTypes Indexed types. + * @return Cache configuration. + */ + private static CacheConfiguration cacheConfig(String name, boolean partitioned, Class... idxTypes) { + return new CacheConfiguration() + .setName(name) + .setCacheMode(partitioned ? CacheMode.PARTITIONED : CacheMode.REPLICATED) + .setAtomicityMode(CacheAtomicityMode.ATOMIC) + .setBackups(1) + .setIndexedTypes(idxTypes); + } + + /** + * Tests offset and limit clauses for query. + * @throws Exception If failed. + */ + public void testOffsetLimit() throws Exception { + IgniteCache c = ignite(0).getOrCreateCache(cacheConfig("ints", true, + Integer.class, Integer.class)); + + try { + List res = new ArrayList<>(); + + Random rnd = new GridRandom(); + + for (int i = 0; i < 10; i++) { + int val = rnd.nextInt(100); + + c.put(i, val); + res.add(val); + } + + Collections.sort(res); + + 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.subList(10, 10), + column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset ?").setArgs(1, 10)).getAll())); + + assertEqualsCollections(res.subList(9, 10), + column(0, c.query(new SqlFieldsQuery(qry + "limit ? offset abs(-(4 + ?))").setArgs(1, 5)).getAll())); + } + finally { + c.destroy(); + } + } + + /** + * @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()); + + for (List row : rows) + res.add(row.get(idx)); + + return res; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d31c8c64/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 a3849d7..730c79f 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 @@ -25,6 +25,7 @@ import org.apache.ignite.internal.processors.cache.local.*; import org.apache.ignite.internal.processors.cache.query.*; import org.apache.ignite.internal.processors.cache.query.continuous.*; import org.apache.ignite.internal.processors.cache.reducefields.*; +import org.apache.ignite.internal.processors.query.*; import org.apache.ignite.internal.processors.query.h2.sql.*; import org.apache.ignite.spi.communication.tcp.*; @@ -43,6 +44,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite { suite.addTestSuite(GridQueryParsingTest.class); // Queries tests. + suite.addTestSuite(IgniteSqlSplitterSelfTest.class); suite.addTestSuite(GridCacheQueryIndexDisabledSelfTest.class); suite.addTestSuite(IgniteCacheQueryLoadSelfTest.class); suite.addTestSuite(IgniteCacheLocalQuerySelfTest.class);