use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ExecutionTest method testLeftJoin.
@Test
public void testLeftJoin() {
// select e.id, e.name, d.name as dep_name
// from emp e
// left join dep d
// on e.depno = d.depno
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, String.class, Integer.class);
ScanNode<Object[]> persons = new ScanNode<>(ctx, rowType, Arrays.asList(new Object[] { 0, "Igor", 1 }, new Object[] { 1, "Roman", 2 }, new Object[] { 2, "Ivan", null }, new Object[] { 3, "Alexey", 1 }));
rowType = TypeUtils.createRowType(tf, int.class, String.class);
ScanNode<Object[]> deps = new ScanNode<>(ctx, rowType, Arrays.asList(new Object[] { 1, "Core" }, new Object[] { 2, "SQL" }));
RelDataType outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class, int.class, String.class);
RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
RowHandler<Object[]> hnd = ctx.rowHandler();
NestedLoopJoinNode<Object[]> join = NestedLoopJoinNode.create(ctx, outType, leftType, rightType, LEFT, (r1, r2) -> getFieldFromBiRows(hnd, 2, r1, r2) == getFieldFromBiRows(hnd, 3, r1, r2));
join.register(asList(persons, deps));
rowType = TypeUtils.createRowType(tf, int.class, String.class, String.class);
ProjectNode<Object[]> project = new ProjectNode<>(ctx, rowType, r -> new Object[] { r[0], r[1], r[4] });
project.register(join);
RootNode<Object[]> node = new RootNode<>(ctx, rowType);
node.register(project);
assert node.hasNext();
ArrayList<Object[]> rows = new ArrayList<>();
while (node.hasNext()) {
rows.add(node.next());
}
assertEquals(4, rows.size());
assertArrayEquals(new Object[] { 0, "Igor", "Core" }, rows.get(0));
assertArrayEquals(new Object[] { 1, "Roman", "SQL" }, rows.get(1));
assertArrayEquals(new Object[] { 2, "Ivan", null }, rows.get(2));
assertArrayEquals(new Object[] { 3, "Alexey", "Core" }, rows.get(3));
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ExecutionTest method assertionHandlingTest.
/**
* Test verifies that an AssertionError thrown from an execution node properly handled by a task executor.
*/
@Test
@SuppressWarnings({ "ResultOfMethodCallIgnored", "ThrowableNotThrown" })
public void assertionHandlingTest() {
ExecutionContext<Object[]> ctx = executionContext();
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, String.class);
CorruptedNode<Object[]> node = new CorruptedNode<>();
RootNode<Object[]> root = new RootNode<>(ctx, rowType);
root.register(node);
Thread watchDog = new Thread(() -> {
try {
Thread.sleep(5_000);
} catch (InterruptedException ignored) {
// No-op.
}
if (!root.isClosed()) {
root.close();
}
}, "test-watchdog");
watchDog.start();
assertThrowsWithCause(root::hasNext, AssertionError.class);
watchDog.interrupt();
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ExecutionTest method testCorrelatedNestedLoopJoin.
/**
* TestCorrelatedNestedLoopJoin.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@ParameterizedTest
@MethodSource("provideArgumentsForCnlJtest")
public void testCorrelatedNestedLoopJoin(int leftSize, int rightSize, int rightBufSize, JoinRelType joinType) {
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, String.class, int.class);
ScanNode<Object[]> left = new ScanNode<>(ctx, rowType, new TestTable(leftSize, rowType));
ScanNode<Object[]> right = new ScanNode<>(ctx, rowType, new TestTable(rightSize, rowType));
RelDataType joinRowType = TypeUtils.createRowType(tf, int.class, String.class, int.class, int.class, String.class, int.class);
RowHandler<Object[]> hnd = ctx.rowHandler();
CorrelatedNestedLoopJoinNode<Object[]> join = new CorrelatedNestedLoopJoinNode<>(ctx, joinRowType, (r1, r2) -> getFieldFromBiRows(hnd, 0, r1, r2).equals(getFieldFromBiRows(hnd, 3, r1, r2)), Set.of(new CorrelationId(0)), joinType);
IgniteTestUtils.setFieldValue(join, "rightInBufferSize", rightBufSize);
join.register(Arrays.asList(left, right));
RootNode<Object[]> root = new RootNode<>(ctx, joinRowType);
root.register(join);
int cnt = 0;
while (root.hasNext()) {
root.next();
cnt++;
}
assertEquals(joinType == INNER ? min(leftSize, rightSize) : leftSize, cnt, "Invalid result size. [left=" + leftSize + ", right=" + rightSize + ", results=" + cnt);
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ExecutionTest method testSimpleExecution.
@Test
public void testSimpleExecution() {
// SELECT P.ID, P.NAME, PR.NAME AS PROJECT
// FROM PERSON P
// INNER JOIN PROJECT PR
// ON P.ID = PR.RESP_ID
// WHERE P.ID >= 2
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, String.class, String.class);
ScanNode<Object[]> persons = new ScanNode<>(ctx, rowType, Arrays.asList(new Object[] { 0, "Igor", "Seliverstov" }, new Object[] { 1, "Roman", "Kondakov" }, new Object[] { 2, "Ivan", "Pavlukhin" }, new Object[] { 3, "Alexey", "Goncharuk" }));
rowType = TypeUtils.createRowType(tf, int.class, int.class, String.class);
ScanNode<Object[]> projects = new ScanNode<>(ctx, rowType, Arrays.asList(new Object[] { 0, 2, "Calcite" }, new Object[] { 1, 1, "SQL" }, new Object[] { 2, 2, "Ignite" }, new Object[] { 3, 0, "Core" }));
RelDataType outType = TypeUtils.createRowType(tf, int.class, String.class, String.class, int.class, int.class, String.class);
RelDataType leftType = TypeUtils.createRowType(tf, int.class, String.class, String.class);
RelDataType rightType = TypeUtils.createRowType(tf, int.class, int.class, String.class);
RowHandler<Object[]> hnd = ctx.rowHandler();
NestedLoopJoinNode<Object[]> join = NestedLoopJoinNode.create(ctx, outType, leftType, rightType, INNER, (r1, r2) -> getFieldFromBiRows(hnd, 0, r1, r2) == getFieldFromBiRows(hnd, 4, r1, r2));
join.register(asList(persons, projects));
rowType = TypeUtils.createRowType(tf, int.class, String.class, String.class);
ProjectNode<Object[]> project = new ProjectNode<>(ctx, rowType, r -> new Object[] { r[0], r[1], r[5] });
project.register(join);
FilterNode<Object[]> filter = new FilterNode<>(ctx, rowType, r -> (Integer) r[0] >= 2);
filter.register(project);
RootNode<Object[]> node = new RootNode<>(ctx, rowType);
node.register(filter);
assert node.hasNext();
ArrayList<Object[]> rows = new ArrayList<>();
while (node.hasNext()) {
rows.add(node.next());
}
assertEquals(2, rows.size());
assertArrayEquals(new Object[] { 2, "Ivan", "Calcite" }, rows.get(0));
assertArrayEquals(new Object[] { 2, "Ivan", "Ignite" }, rows.get(1));
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class HashAggregateExecutionTest method countOfEmptyWithRewind.
/**
* Test verifies that after rewind all groups are properly initialized.
*/
@ParameterizedTest
@EnumSource
public void countOfEmptyWithRewind(TestAggregateType testAgg) {
ExecutionContext<Object[]> ctx = executionContext();
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, int.class);
ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, Collections.emptyList());
AggregateCall call = AggregateCall.create(SqlStdOperatorTable.COUNT, false, false, false, ImmutableIntList.of(), -1, null, RelCollations.EMPTY, tf.createJavaType(int.class), null);
ImmutableList<ImmutableBitSet> grpSets = ImmutableList.of(ImmutableBitSet.of());
RelDataType aggRowType = TypeUtils.createRowType(tf, int.class);
SingleNode<Object[]> aggChain = createAggregateNodesChain(testAgg, ctx, grpSets, call, rowType, aggRowType, rowFactory(), scan);
for (int i = 0; i < 2; i++) {
RootNode<Object[]> root = new RootNode<>(ctx, aggRowType) {
/**
* {@inheritDoc}
*/
@Override
public void close() {
// NO-OP
}
};
root.register(aggChain);
assertTrue(root.hasNext());
assertArrayEquals(row(0), root.next());
assertFalse(root.hasNext());
aggChain.rewind();
}
}
Aggregations