Search in sources :

Example 1 with ExecutionContext

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());
}
Also used : StripedThreadPoolExecutor(org.apache.ignite.internal.thread.StripedThreadPoolExecutor) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) FragmentDescription(org.apache.ignite.internal.sql.engine.metadata.FragmentDescription)

Example 2 with ExecutionContext

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();
        }
    }
}
Also used : ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) RelDataType(org.apache.calcite.rel.type.RelDataType) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) TypeUtils(org.apache.ignite.internal.sql.engine.util.TypeUtils) Commons(org.apache.ignite.internal.sql.engine.util.Commons) Collections.singletonList(java.util.Collections.singletonList) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NotNull(org.jetbrains.annotations.NotNull) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) NotNull(org.jetbrains.annotations.NotNull) Iterator(java.util.Iterator) Test(org.junit.jupiter.api.Test)

Example 3 with ExecutionContext

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());
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) ArrayUtils.asList(org.apache.ignite.internal.util.ArrayUtils.asList) Arrays(java.util.Arrays) Accumulators(org.apache.ignite.internal.sql.engine.exec.exp.agg.Accumulators) EnumSource(org.junit.jupiter.params.provider.EnumSource) Supplier(java.util.function.Supplier) IgniteTestUtils.assertThrowsWithCause(org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RelCollations(org.apache.calcite.rel.RelCollations) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) RelDataType(org.apache.calcite.rel.type.RelDataType) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) RowHandler(org.apache.ignite.internal.sql.engine.exec.RowHandler) AggregateType(org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType) AccumulatorWrapper(org.apache.ignite.internal.sql.engine.exec.exp.agg.AccumulatorWrapper) TypeUtils(org.apache.ignite.internal.sql.engine.util.TypeUtils) Commons(org.apache.ignite.internal.sql.engine.util.Commons) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IntSet(it.unimi.dsi.fastutil.ints.IntSet) AggregateCall(org.apache.calcite.rel.core.AggregateCall) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) AggregateCall(org.apache.calcite.rel.core.AggregateCall) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ExecutionContext

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));
}
Also used : ArrayUtils.asList(org.apache.ignite.internal.util.ArrayUtils.asList) RelDataType(org.apache.calcite.rel.type.RelDataType) LEFT(org.apache.calcite.rel.core.JoinRelType.LEFT) Arrays(java.util.Arrays) ANTI(org.apache.calcite.rel.core.JoinRelType.ANTI) INNER(org.apache.calcite.rel.core.JoinRelType.INNER) SEMI(org.apache.calcite.rel.core.JoinRelType.SEMI) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Set(java.util.Set) TypeUtils(org.apache.ignite.internal.sql.engine.util.TypeUtils) FULL(org.apache.calcite.rel.core.JoinRelType.FULL) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) RIGHT(org.apache.calcite.rel.core.JoinRelType.RIGHT) JoinRelType(org.apache.calcite.rel.core.JoinRelType) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 5 with ExecutionContext

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));
}
Also used : ArrayUtils.asList(org.apache.ignite.internal.util.ArrayUtils.asList) RelDataType(org.apache.calcite.rel.type.RelDataType) LEFT(org.apache.calcite.rel.core.JoinRelType.LEFT) Arrays(java.util.Arrays) ANTI(org.apache.calcite.rel.core.JoinRelType.ANTI) INNER(org.apache.calcite.rel.core.JoinRelType.INNER) RowHandler(org.apache.ignite.internal.sql.engine.exec.RowHandler) SEMI(org.apache.calcite.rel.core.JoinRelType.SEMI) Set(java.util.Set) TypeUtils(org.apache.ignite.internal.sql.engine.util.TypeUtils) FULL(org.apache.calcite.rel.core.JoinRelType.FULL) ArrayList(java.util.ArrayList) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) RIGHT(org.apache.calcite.rel.core.JoinRelType.RIGHT) Commons.getFieldFromBiRows(org.apache.ignite.internal.sql.engine.util.Commons.getFieldFromBiRows) JoinRelType(org.apache.calcite.rel.core.JoinRelType) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

ExecutionContext (org.apache.ignite.internal.sql.engine.exec.ExecutionContext)6 RelDataType (org.apache.calcite.rel.type.RelDataType)5 TypeUtils (org.apache.ignite.internal.sql.engine.util.TypeUtils)5 Arrays (java.util.Arrays)4 Test (org.junit.jupiter.api.Test)4 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)3 ArrayUtils.asList (org.apache.ignite.internal.util.ArrayUtils.asList)3 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 RelCollations (org.apache.calcite.rel.RelCollations)2 JoinRelType (org.apache.calcite.rel.core.JoinRelType)2 ANTI (org.apache.calcite.rel.core.JoinRelType.ANTI)2 FULL (org.apache.calcite.rel.core.JoinRelType.FULL)2 INNER (org.apache.calcite.rel.core.JoinRelType.INNER)2 LEFT (org.apache.calcite.rel.core.JoinRelType.LEFT)2 RIGHT (org.apache.calcite.rel.core.JoinRelType.RIGHT)2