Search in sources :

Example 6 with ExecutionContext

use of org.apache.ignite.internal.sql.engine.exec.ExecutionContext in project ignite-3 by apache.

the class AbstractSetOpExecutionTest method checkSetOp.

/**
 * CheckSetOp.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @param single Single.
 * @param all    All.
 */
protected void checkSetOp(boolean single, boolean all, List<List<Object[]>> dataSets, List<Object[]> expectedResult) {
    ExecutionContext<Object[]> ctx = executionContext();
    IgniteTypeFactory tf = ctx.getTypeFactory();
    RelDataType rowType = TypeUtils.createRowType(tf, String.class, int.class);
    List<Node<Object[]>> inputs = dataSets.stream().map(ds -> new ScanNode<>(ctx, rowType, ds)).collect(Collectors.toList());
    AbstractSetOpNode<Object[]> setOpNode;
    if (single) {
        setOpNode = setOpNodeFactory(ctx, rowType, SINGLE, all, inputs.size());
    } else {
        setOpNode = setOpNodeFactory(ctx, rowType, MAP, all, inputs.size());
    }
    setOpNode.register(inputs);
    if (!single) {
        AbstractSetOpNode<Object[]> reduceNode = setOpNodeFactory(ctx, rowType, REDUCE, all, 1);
        reduceNode.register(Collections.singletonList(setOpNode));
        setOpNode = reduceNode;
    }
    Comparator<Object[]> cmp = ctx.expressionFactory().comparator(RelCollations.of(ImmutableIntList.of(0, 1)));
    // Create sort node on the top to check sorted results.
    SortNode<Object[]> sortNode = new SortNode<>(ctx, rowType, cmp);
    sortNode.register(setOpNode);
    RootNode<Object[]> root = new RootNode<>(ctx, rowType);
    root.register(sortNode);
    assertTrue(nullOrEmpty(expectedResult) || root.hasNext());
    for (Object[] row : expectedResult) {
        assertArrayEquals(row, root.next());
    }
    assertFalse(root.hasNext());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) RelCollations(org.apache.calcite.rel.RelCollations) RelDataType(org.apache.calcite.rel.type.RelDataType) Arrays(java.util.Arrays) CollectionUtils.nullOrEmpty(org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) AggregateType(org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType) TypeUtils(org.apache.ignite.internal.sql.engine.util.TypeUtils) SINGLE(org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType.SINGLE) Collectors(java.util.stream.Collectors) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) MAP(org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType.MAP) Comparator(java.util.Comparator) Collections(java.util.Collections) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) REDUCE(org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType.REDUCE) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) 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