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 2019/03/15 07:50:34 UTC
[ignite] branch master updated: IGNITE-7139: SQL: Lazy execution
support for local queries. This closes #6262.
This is an automated email from the ASF dual-hosted git repository.
vozerov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 54a7983 IGNITE-7139: SQL: Lazy execution support for local queries. This closes #6262.
54a7983 is described below
commit 54a7983d8656e35a3d39ed35affdd647380e114d
Author: tledkov <tl...@gridgain.com>
AuthorDate: Fri Mar 15 10:50:24 2019 +0300
IGNITE-7139: SQL: Lazy execution support for local queries. This closes #6262.
---
.../processors/query/h2/IgniteH2Indexing.java | 3 +
.../processors/query/LocalQueryLazyTest.java | 108 +++++++++++++++++++++
.../IgniteBinaryCacheQueryTestSuite2.java | 3 +
3 files changed, 114 insertions(+)
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 5d912aa..467dd15 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -533,6 +533,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
try {
Connection conn0 = conn.object().connection(qryDesc.schemaName());
+ H2Utils.setupConnection(conn0,
+ qryDesc.distributedJoins(), qryDesc.enforceJoinOrder(), qryParams.lazy());
+
List<Object> args = F.asList(qryParams.arguments());
PreparedStatement stmt = preparedStatementWithParams(
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/LocalQueryLazyTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/LocalQueryLazyTest.java
new file mode 100644
index 0000000..1818d9e
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/LocalQueryLazyTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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 java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cache.query.FieldsQueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.h2.result.LazyResult;
+import org.h2.result.ResultInterface;
+import org.junit.Test;
+
+/**
+ * Tests for local query execution in lazy mode.
+ */
+public class LocalQueryLazyTest extends AbstractIndexingCommonTest {
+ /** Keys count. */
+ private static final int KEY_CNT = 10;
+
+ /** Queries count. */
+ private static final int QRY_CNT = 10;
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ startGrid();
+
+ IgniteCache<Long, Long> c = grid().createCache(new CacheConfiguration<Long, Long>()
+ .setName("test")
+ .setSqlSchema("TEST")
+ .setQueryEntities(Collections.singleton(new QueryEntity(Long.class, Long.class)
+ .setTableName("test")
+ .addQueryField("id", Long.class.getName(), null)
+ .addQueryField("val", Long.class.getName(), null)
+ .setKeyFieldName("id")
+ .setValueFieldName("val")
+ ))
+ .setAffinity(new RendezvousAffinityFunction(false, 10)));
+
+ for (long i = 0; i < KEY_CNT; ++i)
+ c.put(i, i);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /**
+ * Test local query execution.
+ */
+ @Test
+ public void testLocalLazyQuery() {
+ Iterator[] iters = new Iterator[QRY_CNT];
+
+ for (int i = 0; i < QRY_CNT; ++i) {
+ iters[i] = sql("SELECT * FROM test").iterator();
+
+ ResultInterface res = GridTestUtils.getFieldValueHierarchy(iters[i], "iter", "iter", "res");
+
+ assertTrue("Unexpected result type " + res.getClass(), res instanceof LazyResult);
+ }
+
+ // Scan and close iterator in reverse order.
+ for (int i = QRY_CNT - 1; i >= 0; --i) {
+ while (iters[i].hasNext())
+ iters[i].next();
+ }
+ }
+
+ /**
+ * @param sql SQL query.
+ * @param args Query parameters.
+ * @return Results cursor.
+ */
+ private FieldsQueryCursor<List<?>> sql(String sql, Object ... args) {
+ return grid().context().query().querySqlFields(new SqlFieldsQuery(sql)
+ .setLocal(true)
+ .setLazy(true)
+ .setSchema("TEST")
+ .setArgs(args), false);
+ }
+}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite2.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite2.java
index 0476f47..a6278d0 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite2.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite2.java
@@ -51,6 +51,7 @@ import org.apache.ignite.internal.processors.query.IgniteCacheGroupsSqlDistribut
import org.apache.ignite.internal.processors.query.IgniteCacheGroupsSqlSegmentedIndexMultiNodeSelfTest;
import org.apache.ignite.internal.processors.query.IgniteCacheGroupsSqlSegmentedIndexSelfTest;
import org.apache.ignite.internal.processors.query.IgniteSqlCreateTableTemplateTest;
+import org.apache.ignite.internal.processors.query.LocalQueryLazyTest;
import org.apache.ignite.internal.processors.query.SqlLocalQueryConnectionAndStatementTest;
import org.apache.ignite.internal.processors.query.h2.CacheQueryEntityWithDateTimeApiFieldsTest;
import org.apache.ignite.internal.processors.query.h2.twostep.CacheQueryMemoryLeakTest;
@@ -133,6 +134,8 @@ import org.junit.runners.Suite;
NoneOrSinglePartitionsQueryOptimizationsTest.class,
IgniteSqlCreateTableTemplateTest.class,
+
+ LocalQueryLazyTest.class,
})
public class IgniteBinaryCacheQueryTestSuite2 {
}