Search in sources :

Example 1 with MAP

use of org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType.MAP 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

Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RelCollations (org.apache.calcite.rel.RelCollations)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 ImmutableIntList (org.apache.calcite.util.ImmutableIntList)1 ExecutionContext (org.apache.ignite.internal.sql.engine.exec.ExecutionContext)1 AggregateType (org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType)1 MAP (org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType.MAP)1 REDUCE (org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType.REDUCE)1 SINGLE (org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType.SINGLE)1 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)1 TypeUtils (org.apache.ignite.internal.sql.engine.util.TypeUtils)1 CollectionUtils.nullOrEmpty (org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty)1 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 Assertions.fail (org.junit.jupiter.api.Assertions.fail)1