You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/08/19 09:40:41 UTC
[47/50] 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-gg-9615-1
Commit: d31c8c6477e03563bf73db3cf216250b9c22b562
Parents: 9c939be
Author: S.Vladykin <sv...@gridgain.com>
Authored: Mon Aug 17 21:25:25 2015 +0300
Committer: S.Vladykin <sv...@gridgain.com>
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<Integer, Integer> c = ignite(0).getOrCreateCache(cacheConfig("ints", true,
+ Integer.class, Integer.class));
+
+ try {
+ List<Integer> 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<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);