Search in sources :

Example 66 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class HashAggregateSingleGroupExecutionTest method singleAvg.

@Test
public void singleAvg() {
    ExecutionContext<Object[]> ctx = executionContext();
    IgniteTypeFactory tf = ctx.getTypeFactory();
    RelDataType rowType = TypeUtils.createRowType(tf, String.class, int.class);
    ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, Arrays.asList(row("Igor", 200), row("Roman", 300), row("Ivan", 1400), row("Alexey", 1000)));
    AggregateCall call = AggregateCall.create(SqlStdOperatorTable.AVG, false, false, false, ImmutableIntList.of(1), -1, RelCollations.EMPTY, tf.createJavaType(double.class), null);
    List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of());
    RelDataType aggType = TypeUtils.createRowType(tf, int.class);
    HashAggregateNode<Object[]> agg = new HashAggregateNode<>(ctx, aggType, SINGLE, grpSets, accFactory(ctx, call, SINGLE, rowType), rowFactory());
    agg.register(scan);
    RootNode<Object[]> root = new RootNode<>(ctx, aggType);
    root.register(agg);
    assertTrue(root.hasNext());
    assertEquals(725d, root.next()[0]);
    assertFalse(root.hasNext());
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.jupiter.api.Test)

Example 67 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class HashAggregateSingleGroupExecutionTest method singleMax.

@Test
public void singleMax() {
    ExecutionContext<Object[]> ctx = executionContext();
    IgniteTypeFactory tf = ctx.getTypeFactory();
    RelDataType rowType = TypeUtils.createRowType(tf, String.class, int.class);
    ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, Arrays.asList(row("Igor", 200), row("Roman", 300), row("Ivan", 1400), row("Alexey", 1000)));
    AggregateCall call = AggregateCall.create(SqlStdOperatorTable.MAX, false, false, false, ImmutableIntList.of(1), -1, RelCollations.EMPTY, tf.createJavaType(int.class), null);
    List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of());
    RelDataType aggType = TypeUtils.createRowType(tf, int.class);
    HashAggregateNode<Object[]> agg = new HashAggregateNode<>(ctx, aggType, SINGLE, grpSets, accFactory(ctx, call, SINGLE, rowType), rowFactory());
    agg.register(scan);
    RootNode<Object[]> root = new RootNode<>(ctx, aggType);
    root.register(agg);
    assertTrue(root.hasNext());
    assertEquals(1400, root.next()[0]);
    assertFalse(root.hasNext());
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.jupiter.api.Test)

Example 68 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class HashAggregateSingleGroupExecutionTest method singleCount.

@Test
public void singleCount() {
    ExecutionContext<Object[]> ctx = executionContext();
    IgniteTypeFactory tf = ctx.getTypeFactory();
    RelDataType rowType = TypeUtils.createRowType(tf, String.class, int.class);
    ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, Arrays.asList(row("Igor", 200), row("Roman", 300), row("Ivan", 1400), row("Alexey", 1000)));
    AggregateCall call = AggregateCall.create(SqlStdOperatorTable.COUNT, false, false, false, ImmutableIntList.of(), -1, null, RelCollations.EMPTY, tf.createJavaType(int.class), null);
    List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of());
    RelDataType aggType = TypeUtils.createRowType(tf, int.class);
    HashAggregateNode<Object[]> agg = new HashAggregateNode<>(ctx, aggType, SINGLE, grpSets, accFactory(ctx, call, SINGLE, rowType), rowFactory());
    agg.register(scan);
    RootNode<Object[]> root = new RootNode<>(ctx, aggType);
    root.register(agg);
    assertTrue(root.hasNext());
    assertEquals(4, root.next()[0]);
    assertFalse(root.hasNext());
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.jupiter.api.Test)

Example 69 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class LimitExecutionTest method checkLimit.

/**
 * Check correct result size fetched.
 *
 * @param offset Rows offset.
 * @param fetch Fetch rows count (zero means unlimited).
 */
private void checkLimit(int offset, int fetch) {
    ExecutionContext<Object[]> ctx = executionContext(true);
    IgniteTypeFactory tf = ctx.getTypeFactory();
    RelDataType rowType = TypeUtils.createRowType(tf, int.class);
    RootNode<Object[]> rootNode = new RootNode<>(ctx, rowType);
    LimitNode<Object[]> limitNode = new LimitNode<>(ctx, rowType, () -> offset, fetch == 0 ? null : () -> fetch);
    SourceNode srcNode = new SourceNode(ctx, rowType);
    rootNode.register(limitNode);
    limitNode.register(srcNode);
    if (fetch > 0) {
        for (int i = offset; i < offset + fetch; i++) {
            assertTrue(rootNode.hasNext());
            assertEquals(i, rootNode.next()[0]);
        }
        assertFalse(rootNode.hasNext());
        assertEquals(srcNode.requested.get(), offset + fetch);
    } else {
        assertTrue(rootNode.hasNext());
        assertEquals(offset, rootNode.next()[0]);
        assertTrue(srcNode.requested.get() > offset);
    }
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 70 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class TableSpoolExecutionTest method checkTableSpool.

/**
 * CheckTableSpool.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
public void checkTableSpool(BiFunction<ExecutionContext<Object[]>, RelDataType, TableSpoolNode<Object[]>> spoolFactory) {
    ExecutionContext<Object[]> ctx = executionContext();
    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 rewindCnts = 32;
    for (int size : sizes) {
        log.info("Check: size=" + size);
        ScanNode<Object[]> right = new ScanNode<>(ctx, rowType, new TestTable(size, rowType) {

            boolean first = true;

            @Override
            @NotNull
            public Iterator<Object[]> iterator() {
                assertTrue(first, "Rewind table");
                first = false;
                return super.iterator();
            }
        });
        TableSpoolNode<Object[]> spool = spoolFactory.apply(ctx, rowType);
        spool.register(singletonList(right));
        RootRewindable<Object[]> root = new RootRewindable<>(ctx, rowType);
        root.register(spool);
        for (int i = 0; i < rewindCnts; ++i) {
            int cnt = 0;
            while (root.hasNext()) {
                root.next();
                cnt++;
            }
            assertEquals(size, cnt, "Invalid result size");
            root.rewind();
        }
    }
}
Also used : 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)

Aggregations

IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)80 Test (org.junit.jupiter.api.Test)48 RelDataType (org.apache.calcite.rel.type.RelDataType)47 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)27 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)22 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)21 AggregateCall (org.apache.calcite.rel.core.AggregateCall)19 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 RexNode (org.apache.calcite.rex.RexNode)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 ArrayList (java.util.ArrayList)10 SchemaPlus (org.apache.calcite.schema.SchemaPlus)8 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)8 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)7 List (java.util.List)6 MappingQueryContext (org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext)6 MultiStepPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan)6 MultiStepQueryPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan)6 QueryTemplate (org.apache.ignite.internal.sql.engine.prepare.QueryTemplate)6