From b8312c14d4c63e1471504d1c152344114f01387b Mon Sep 17 00:00:00 2001 From: SGrimstad Date: Tue, 18 Sep 2018 11:51:26 +0300 Subject: [PATCH] IGNITE-9162 fixing condition is added --- .../query/h2/sql/GridSqlQuerySplitter.java | 6 +- .../h2/twostep/TableViewSubquerySelfTest.java | 120 ++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite2.java | 3 + 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/twostep/TableViewSubquerySelfTest.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 3e3b449ecc7..73e55c72a6b 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 @@ -2261,8 +2261,10 @@ private static boolean isFractionalType(int type) { GridSqlSelect select = (GridSqlSelect)qry; - // no joins support yet - if (select.from() == null || select.from().size() != 1) + // no joins and sub-queries support yet + if (select.from() == null + || select.from().size() != 1 + || GridSqlSubquery.class.isAssignableFrom(select.from().child().getClass())) return null; return extractPartition(select.where(), ctx); diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/twostep/TableViewSubquerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/twostep/TableViewSubquerySelfTest.java new file mode 100644 index 00000000000..eaf4243018f --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/twostep/TableViewSubquerySelfTest.java @@ -0,0 +1,120 @@ +/* + * 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.twostep; + +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class TableViewSubquerySelfTest extends GridCommonAbstractTest { + /** */ + private static final int NODES_COUNT = 1; + + /** */ + private static Ignite ignite; + + /** */ + private static IgniteCache initCache; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + ignite = startGridsMultiThreaded(NODES_COUNT, false); + initCache = ignite.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME) + .setSqlSchema("PUBLIC") + ); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** */ + public void testSubqueryTableView() { + final String cacheName = "a1"; + + final String creationQry = "CREATE TABLE t1 ( id INT NOT NULL, int_col1 INT NOT NULL, PRIMARY KEY (id)) " + + "WITH \"TEMPLATE=partitioned, cache_name=%s\""; //, WRAP_VALUE=false + + try (FieldsQueryCursor> cur = initCache.query( + new SqlFieldsQuery(String.format(creationQry,cacheName)))) { + assertNotNull(cur); + + List> rows = cur.getAll(); + + assertEquals(1, rows.size()); + + assertEquals(0L, rows.get(0).get(0)); + } + + final IgniteCache cache = ignite.getOrCreateCache(cacheName); + + try (FieldsQueryCursor> cur = cache.query(new SqlFieldsQuery( + "INSERT INTO t1 (id,int_col1) VALUES (1,0),(2,2),(3,0),(4,2)"))) { + assertNotNull(cur); + + List> rows = cur.getAll(); + + assertEquals(1, rows.size()); + + assertEquals(4L, rows.get(0).get(0)); + } + + try (FieldsQueryCursor> cur = cache.query(new SqlFieldsQuery( + "SELECT * FROM ( SELECT * FROM t1 WHERE int_col1 > 0 ORDER BY id ) WHERE int_col1 = 1"))) { + assertNotNull(cur); + + List> rows = cur.getAll(); + + assertEquals(0, rows.size()); + } + + try (FieldsQueryCursor> cur = cache.query(new SqlFieldsQuery( + "SELECT * FROM ( SELECT * FROM t1 WHERE int_col1 < 0 ORDER BY id ) WHERE int_col1 = 1"))) { + assertNotNull(cur); + + List> rows = cur.getAll(); + + assertEquals(0, rows.size()); + } + + try (FieldsQueryCursor> cur = cache.query(new SqlFieldsQuery( + "SELECT * FROM ( SELECT * FROM t1 WHERE int_col1 > 0 ORDER BY id ) WHERE int_col1 = 2"))) { + assertNotNull(cur); + + List> rows = cur.getAll(); + + assertEquals(2, rows.size()); + + assertEquals(2, rows.get(0).get(0)); + + assertEquals(2, rows.get(0).get(1)); + + assertEquals(4, rows.get(1).get(0)); + + assertEquals(2, rows.get(1).get(1)); + } + } +} 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 536834cda93..4b91b430786 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 @@ -55,6 +55,7 @@ import org.apache.ignite.internal.processors.query.h2.twostep.DisappearedCacheWasNotFoundMessageSelfTest; import org.apache.ignite.internal.processors.query.h2.twostep.NonCollocatedRetryMessageSelfTest; import org.apache.ignite.internal.processors.query.h2.twostep.RetryCauseMessageSelfTest; +import org.apache.ignite.internal.processors.query.h2.twostep.TableViewSubquerySelfTest; import org.apache.ignite.testframework.IgniteTestSuite; /** @@ -119,6 +120,8 @@ public static TestSuite suite() throws Exception { suite.addTestSuite(DisappearedCacheCauseRetryMessageSelfTest.class); suite.addTestSuite(DisappearedCacheWasNotFoundMessageSelfTest.class); + suite.addTestSuite(TableViewSubquerySelfTest.class); + return suite; } }