Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
IGNITE-16486 Adoption of a bunch of tickets from Ignite-2 - Fixes #637.
IGNITE-13179 Fix traits at the IgniteLimit. IGNITE-15603 NPE on subquery returning multiple results. IGNITE-15982 Correlates passes through table spools. Signed-off-by: zstan <stanilovsky@gmail.com>
- Loading branch information
Showing
8 changed files
with
207 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.sql.engine; | ||
|
||
import static org.apache.ignite.internal.sql.engine.util.QueryChecker.containsSubPlan; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** Tests for correlated queries. */ | ||
public class ItCorrelatesTest extends AbstractBasicIntegrationTest { | ||
private static final String DISABLED_JOIN_RULES = " /*+ DISABLE_RULE('MergeJoinConverter', 'NestedLoopJoinConverter') */ "; | ||
|
||
/** Checks correlates are assigned before access. */ | ||
@Test | ||
public void testCorrelatesAssignedBeforeAccess() { | ||
sql("create table test_tbl(k INTEGER primary key, v INTEGER)"); | ||
sql("INSERT INTO test_tbl VALUES (1, 1)"); | ||
|
||
assertQuery("SELECT " + DISABLED_JOIN_RULES + " t0.v, (SELECT t0.v + t1.v FROM test_tbl t1) AS j FROM test_tbl t0") | ||
.matches(containsSubPlan("IgniteCorrelatedNestedLoopJoin")) | ||
.returns(1, 2) | ||
.check(); | ||
} | ||
|
||
/** Checks that correlates can't be moved under the table spool. */ | ||
@Test | ||
public void testCorrelatesWithTableSpool() { | ||
sql("CREATE TABLE test(k INTEGER primary key, i1 INT, i2 INT)"); | ||
sql("INSERT INTO test VALUES (1, 1, 1), (2, 2, 2)"); | ||
|
||
assertQuery("SELECT " + DISABLED_JOIN_RULES + " (SELECT t1.i1 + t1.i2 + t0.i2 FROM test t1 WHERE i1 = 1) FROM test t0") | ||
.matches(containsSubPlan("IgniteCorrelatedNestedLoopJoin")) | ||
.matches(containsSubPlan("IgniteTableSpool")) | ||
.returns(3) | ||
.returns(4) | ||
.check(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* 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.sql.engine.exec.rel; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.ignite.internal.sql.engine.exec.ExecutionContext; | ||
import org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory; | ||
import org.apache.ignite.internal.sql.engine.util.Commons; | ||
import org.apache.ignite.internal.sql.engine.util.TypeUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test LimitNode execution. | ||
*/ | ||
public class LimitExecutionTest extends AbstractExecutionTest { | ||
/** Tests correct results fetched with Limit node. */ | ||
@Test | ||
public void testLimit() { | ||
int bufSize = Commons.IN_BUFFER_SIZE; | ||
|
||
checkLimit(0, 1); | ||
checkLimit(1, 0); | ||
checkLimit(1, 1); | ||
checkLimit(0, bufSize); | ||
checkLimit(bufSize, 0); | ||
checkLimit(bufSize, bufSize); | ||
checkLimit(bufSize - 1, 1); | ||
checkLimit(2000, 0); | ||
checkLimit(0, 3000); | ||
checkLimit(2000, 3000); | ||
} | ||
|
||
/** | ||
* Check correct result size fetched. | ||
* | ||
* @param offset Rows offset. | ||
* @param fetch Fetch rows count (zero means unlimited). | ||
*/ | ||
private void checkLimit(int offset, int fetch) { | ||
ExecutionContext<Object[]> ctx = executionContext(true); | ||
IgniteTypeFactory tf = ctx.getTypeFactory(); | ||
RelDataType rowType = TypeUtils.createRowType(tf, int.class); | ||
|
||
RootNode<Object[]> rootNode = new RootNode<>(ctx, rowType); | ||
LimitNode<Object[]> limitNode = new LimitNode<>(ctx, rowType, () -> offset, fetch == 0 ? null : () -> fetch); | ||
SourceNode srcNode = new SourceNode(ctx, rowType); | ||
|
||
rootNode.register(limitNode); | ||
limitNode.register(srcNode); | ||
|
||
if (fetch > 0) { | ||
for (int i = offset; i < offset + fetch; i++) { | ||
assertTrue(rootNode.hasNext()); | ||
assertEquals(i, rootNode.next()[0]); | ||
} | ||
|
||
assertFalse(rootNode.hasNext()); | ||
assertEquals(srcNode.requested.get(), offset + fetch); | ||
} else { | ||
assertTrue(rootNode.hasNext()); | ||
assertEquals(offset, rootNode.next()[0]); | ||
assertTrue(srcNode.requested.get() > offset); | ||
} | ||
} | ||
|
||
private static class SourceNode extends AbstractNode<Object[]> { | ||
|
||
AtomicInteger requested = new AtomicInteger(); | ||
|
||
public SourceNode(ExecutionContext<Object[]> ctx, RelDataType rowType) { | ||
super(ctx, rowType); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override protected void rewindInternal() { | ||
// No-op. | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override protected Downstream<Object[]> requestDownstream(int idx) { | ||
return null; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void request(int rowsCnt) { | ||
int r = requested.getAndAdd(rowsCnt); | ||
|
||
context().execute(() -> { | ||
for (int i = 0; i < rowsCnt; i++) { | ||
downstream().push(new Object[]{r + i}); | ||
} | ||
}, this::onError); | ||
} | ||
} | ||
} |