Repository: ignite Updated Branches: refs/heads/master c3462ffff -> 84d329c29
IGNITE-8639: SQL: Fixed NPE in org.h2.util.StringUtils.indent where query has a lot of nested subqueries. This closes #4919. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/84d329c2 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/84d329c2 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/84d329c2 Branch: refs/heads/master Commit: 84d329c29ebc6989793af0778c080429e69c875e Parents: c3462ff Author: tledkov-gridgain <tled...@gridgain.com> Authored: Tue Nov 13 15:26:28 2018 +0300 Committer: devozerov <voze...@gridgain.com> Committed: Tue Nov 13 15:26:28 2018 +0300 ---------------------------------------------------------------------- .../query/h2/opt/GridH2DefaultTableEngine.java | 4 +- .../query/SqlNestedQuerySelfTest.java | 75 ++++++++++++++++++++ .../IgniteBinaryCacheQueryTestSuite.java | 2 + 3 files changed, 80 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/84d329c2/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2DefaultTableEngine.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2DefaultTableEngine.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2DefaultTableEngine.java index f53f1b3..72c1102 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2DefaultTableEngine.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2DefaultTableEngine.java @@ -28,7 +28,9 @@ import org.h2.table.Table; public class GridH2DefaultTableEngine implements TableEngine { /** {@inheritDoc} */ @Override public Table createTable(CreateTableData data) { - assert !data.persistData && !data.persistIndexes; + // Used to create shadow table view used by CTE. + data.persistData = false; + data.persistIndexes = false; if (data.isHidden && data.id == 0 && "SYS".equals(data.tableName)) return new GridH2MetaTable(data); http://git-wip-us.apache.org/repos/asf/ignite/blob/84d329c2/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlNestedQuerySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlNestedQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlNestedQuerySelfTest.java new file mode 100644 index 0000000..f3545f2 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlNestedQuerySelfTest.java @@ -0,0 +1,75 @@ +/* + * 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.List; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Tests for schemas. + */ +public class SqlNestedQuerySelfTest extends GridCommonAbstractTest { + /** Node. */ + private IgniteEx node; + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + node = (IgniteEx)startGrid(); + + startGrid(2); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + */ + public void testNestingQuery() { + sql("CREATE TABLE txs(txId INTEGER PRIMARY KEY, created INTEGER)"); + sql("CREATE TABLE ops(id INTEGER PRIMARY KEY, txId INTEGER, stage VARCHAR, tStamp INTEGER)"); + + sql("INSERT INTO txs(txId, created) VALUES (1, 599000), (2, 599111), (3, 599234)"); + sql("INSERT INTO ops(id, txId, stage, tStamp) VALUES" + + " (1, 1, 'NEW', 599686), (2, 1, 'OLD', 599722), (3, 1, 'OLD', 599736), (4, 2, 'NEW', 599767)"); + + sql("WITH cacheJoin (txId, stage, tStamp)" + + " AS (SELECT t.txId, o.stage, o.tStamp FROM txs t INNER JOIN ops o ON t.txId = o.txId)" + + " SELECT ou.stage, COUNT(*) as cou, SUM(CASE WHEN ou.stage = in.stage THEN 1 ELSE 0 END) AS ttl" + + " FROM (SELECT txId, stage FROM cacheJoin cte GROUP BY txId, stage) ou" + + " INNER JOIN (SELECT mx.txId, mx.stage FROM (SELECT txId, tStamp, stage FROM cacheJoin cte) mx" + + " INNER JOIN (SELECT txId, MAX(tStamp) AS maxTStamp FROM cacheJoin cte GROUP BY txId) mix" + + " ON mx.txId = mix.txId AND mx.tStamp = mix.maxTStamp) in ON ou.txId = in.txId" + + " GROUP BY ou.stage"); + } + + /** + * @param sql SQL query. + * @return Results. + */ + private List<List<?>> sql(String sql) { + GridQueryProcessor qryProc = node.context().query(); + + SqlFieldsQuery qry = new SqlFieldsQuery(sql).setSchema("PUBLIC"); + + return qryProc.querySqlFields(qry, true).getAll(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/84d329c2/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java index aeb49e1..87a0b2e 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java @@ -193,6 +193,7 @@ import org.apache.ignite.internal.processors.query.IgniteSqlSplitterSelfTest; import org.apache.ignite.internal.processors.query.LazyQuerySelfTest; import org.apache.ignite.internal.processors.query.MultipleStatementsSqlQuerySelfTest; import org.apache.ignite.internal.processors.query.SqlIllegalSchemaSelfTest; +import org.apache.ignite.internal.processors.query.SqlNestedQuerySelfTest; import org.apache.ignite.internal.processors.query.SqlPushDownFunctionTest; import org.apache.ignite.internal.processors.query.SqlSchemaSelfTest; import org.apache.ignite.internal.processors.query.SqlSystemViewsSelfTest; @@ -244,6 +245,7 @@ public class IgniteBinaryCacheQueryTestSuite extends TestSuite { suite.addTestSuite(AffinityKeyNameAndValueFieldNameConflictTest.class); suite.addTestSuite(DmlInsideTransactionTest.class); suite.addTestSuite(ComplexPrimaryKeyUnwrapSelfTest.class); + suite.addTestSuite(SqlNestedQuerySelfTest.class); suite.addTestSuite(PartitionedSqlTest.class); suite.addTestSuite(ReplicatedSqlTest.class);