use of org.apache.ignite.internal.sql.engine.exec.ExecutionContext in project ignite-3 by apache.
the class AbstractExecutionTest method executionContext.
protected ExecutionContext<Object[]> executionContext(boolean withDelays) {
if (withDelays) {
StripedThreadPoolExecutor testExecutor = new IgniteTestStripedThreadPoolExecutor(8, NamedThreadFactory.threadPrefix("fake-test-node", "sqlTestExec"), null, false, 0);
IgniteTestUtils.setFieldValue(taskExecutor, "stripedThreadPoolExecutor", testExecutor);
}
FragmentDescription fragmentDesc = new FragmentDescription(0, null, null, Long2ObjectMaps.emptyMap());
return new ExecutionContext<>(BaseQueryContext.builder().logger(log).build(), taskExecutor, UUID.randomUUID(), "fake-test-node", "fake-test-node", 0, fragmentDesc, ArrayRowHandler.INSTANCE, ImmutableMap.of());
}
use of org.apache.ignite.internal.sql.engine.exec.ExecutionContext in project ignite-3 by apache.
the class HashIndexSpoolExecutionTest method testIndexSpool.
@Test
public void testIndexSpool() {
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, String.class, int.class);
int inBufSize = Commons.IN_BUFFER_SIZE;
int[] sizes = { 1, inBufSize / 2 - 1, inBufSize / 2, inBufSize / 2 + 1, inBufSize, inBufSize + 1, inBufSize * 4 };
int[] eqCnts = { 1, 10 };
for (int size : sizes) {
for (int eqCnt : eqCnts) {
TestParams[] params;
if (size == 1) {
params = new TestParams[] { new TestParams(null, new Object[] { 0, null, null }, eqCnt) };
} else {
params = new TestParams[] { new TestParams(null, new Object[] { size / 2, null, null }, eqCnt), new TestParams(null, new Object[] { size / 2 + 1, null, null }, eqCnt), new TestParams(r -> ((int) r[2]) == 0, new Object[] { size / 2 + 1, null, null }, 1) };
}
log.info("Check: size=" + size);
ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, new TestTable(size * eqCnt, rowType, (rowId) -> rowId / eqCnt, (rowId) -> "val_" + (rowId % eqCnt), (rowId) -> rowId % eqCnt) {
boolean first = true;
@Override
@NotNull
public Iterator<Object[]> iterator() {
assertTrue(first, "Rewind right");
first = false;
return super.iterator();
}
});
Object[] searchRow = new Object[3];
TestPredicate testFilter = new TestPredicate();
IndexSpoolNode<Object[]> spool = IndexSpoolNode.createHashSpool(ctx, rowType, ImmutableBitSet.of(0), testFilter, () -> searchRow);
spool.register(singletonList(scan));
RootRewindable<Object[]> root = new RootRewindable<>(ctx, rowType);
root.register(spool);
for (TestParams param : params) {
log.info("Check: param=" + param);
// Set up bounds
testFilter.delegate = param.pred;
System.arraycopy(param.bounds, 0, searchRow, 0, searchRow.length);
int cnt = 0;
while (root.hasNext()) {
root.next();
cnt++;
}
assertEquals(param.expectedResultSize, cnt, "Invalid result size");
root.rewind();
}
root.closeRewindableRoot();
}
}
}
use of org.apache.ignite.internal.sql.engine.exec.ExecutionContext in project ignite-3 by apache.
the class BaseAggregateTest method sumOnDifferentRowsCount.
/**
* SumOnDifferentRowsCount.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@ParameterizedTest
@EnumSource
public void sumOnDifferentRowsCount(TestAggregateType testAgg) {
int bufSize = Commons.IN_BUFFER_SIZE;
int[] grpsCount = { 1, bufSize / 2, bufSize, bufSize + 1, bufSize * 4 };
int[] rowsInGroups = { 1, 5, bufSize };
for (int grps : grpsCount) {
for (int rowsInGroup : rowsInGroups) {
log.info("Check: [grps=" + grps + ", rowsInGroup=" + rowsInGroup + ']');
ExecutionContext<Object[]> ctx = executionContext();
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, int.class);
ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, new TestTable(grps * rowsInGroup, rowType, (r) -> r / rowsInGroup, (r) -> r % rowsInGroup));
AggregateCall call = AggregateCall.create(SqlStdOperatorTable.SUM, false, false, false, ImmutableIntList.of(1), -1, RelCollations.EMPTY, tf.createJavaType(int.class), null);
List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of(0));
RelDataType aggRowType = TypeUtils.createRowType(tf, int.class);
SingleNode<Object[]> aggChain = createAggregateNodesChain(testAgg, ctx, grpSets, call, rowType, aggRowType, rowFactory(), scan);
RootNode<Object[]> root = new RootNode<>(ctx, aggRowType);
root.register(aggChain);
IntSet grpId = new IntOpenHashSet(IntStream.range(0, grps).toArray());
while (root.hasNext()) {
Object[] row = root.next();
grpId.remove(((Integer) row[0]).intValue());
assertEquals((rowsInGroup - 1) * rowsInGroup / 2, row[1]);
}
assertTrue(grpId.isEmpty());
}
}
}
use of org.apache.ignite.internal.sql.engine.exec.ExecutionContext in project ignite-3 by apache.
the class MergeJoinExecutionTest method verifyJoin.
/**
* Creates execution tree and executes it. Then compares the result of the execution with the given one.
*
* @param left Data for left table.
* @param right Data for right table.
* @param joinType Join type.
* @param expRes Expected result.
*/
private void verifyJoin(Object[][] left, Object[][] right, JoinRelType joinType, Object[][] expRes) {
ExecutionContext<Object[]> ctx = executionContext(true);
RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
ScanNode<Object[]> leftNode = new ScanNode<>(ctx, leftType, Arrays.asList(left));
RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
ScanNode<Object[]> rightNode = new ScanNode<>(ctx, rightType, Arrays.asList(right));
RelDataType outType;
if (setOf(SEMI, ANTI).contains(joinType)) {
outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
} else {
outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class, int.class, String.class);
}
MergeJoinNode<Object[]> join = MergeJoinNode.create(ctx, outType, leftType, rightType, joinType, (r1, r2) -> {
Object o1 = r1[2];
Object o2 = r2[0];
if (o1 == null || o2 == null) {
if (o1 != null) {
return 1;
} else if (o2 != null) {
return -1;
} else {
return 0;
}
}
return Integer.compare((Integer) o1, (Integer) o2);
});
join.register(asList(leftNode, rightNode));
RelDataType rowType;
ProjectNode<Object[]> project;
if (setOf(SEMI, ANTI).contains(joinType)) {
rowType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
project = new ProjectNode<>(ctx, rowType, r -> new Object[] { r[0], r[1] });
} else {
rowType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, String.class);
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);
ArrayList<Object[]> rows = new ArrayList<>();
while (node.hasNext()) {
rows.add(node.next());
}
assertThat(rows.toArray(EMPTY), equalTo(expRes));
}
use of org.apache.ignite.internal.sql.engine.exec.ExecutionContext in project ignite-3 by apache.
the class NestedLoopJoinExecutionTest method verifyJoin.
/**
* Creates execution tree and executes it. Then compares the result of the execution with the given one.
*
* @param left Data for left table.
* @param right Data for right table.
* @param joinType Join type.
* @param expRes Expected result.
*/
private void verifyJoin(Object[][] left, Object[][] right, JoinRelType joinType, Object[][] expRes) {
ExecutionContext<Object[]> ctx = executionContext(true);
RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
ScanNode<Object[]> leftNode = new ScanNode<>(ctx, leftType, Arrays.asList(left));
RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
ScanNode<Object[]> rightNode = new ScanNode<>(ctx, rightType, Arrays.asList(right));
RelDataType outType;
if (setOf(SEMI, ANTI).contains(joinType)) {
outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
} else {
outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class, int.class, String.class);
}
RowHandler<Object[]> hnd = ctx.rowHandler();
NestedLoopJoinNode<Object[]> join = NestedLoopJoinNode.create(ctx, outType, leftType, rightType, joinType, (r1, r2) -> getFieldFromBiRows(hnd, 2, r1, r2) == getFieldFromBiRows(hnd, 3, r1, r2));
join.register(asList(leftNode, rightNode));
RelDataType rowType;
ProjectNode<Object[]> project;
if (setOf(SEMI, ANTI).contains(joinType)) {
rowType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
project = new ProjectNode<>(ctx, rowType, r -> new Object[] { r[0], r[1] });
} else {
rowType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, String.class);
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);
ArrayList<Object[]> rows = new ArrayList<>();
while (node.hasNext()) {
rows.add(node.next());
}
assertArrayEquals(expRes, rows.toArray(EMPTY));
}
Aggregations