Search in sources :

Example 66 with ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.

the class HashAggregateSingleGroupExecutionTest method mapReduceSum.

@Test
public void mapReduceSum() {
    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.SUM, false, false, false, ImmutableIntList.of(1), -1, RelCollations.EMPTY, tf.createJavaType(int.class), null);
    List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of());
    RelDataType mapType = IgniteMapHashAggregate.rowType(tf, true);
    HashAggregateNode<Object[]> map = new HashAggregateNode<>(ctx, mapType, MAP, grpSets, accFactory(ctx, call, MAP, rowType), rowFactory());
    map.register(scan);
    RelDataType reduceType = TypeUtils.createRowType(tf, int.class);
    HashAggregateNode<Object[]> reduce = new HashAggregateNode<>(ctx, reduceType, REDUCE, grpSets, accFactory(ctx, call, REDUCE, null), rowFactory());
    reduce.register(map);
    RootNode<Object[]> root = new RootNode<>(ctx, reduceType);
    root.register(reduce);
    assertTrue(root.hasNext());
    assertEquals(2900, 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 ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.

the class HashAggregateSingleGroupExecutionTest method mapReduceMax.

@Test
public void mapReduceMax() {
    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 mapType = IgniteMapHashAggregate.rowType(tf, true);
    HashAggregateNode<Object[]> map = new HashAggregateNode<>(ctx, mapType, MAP, grpSets, accFactory(ctx, call, MAP, rowType), rowFactory());
    map.register(scan);
    RelDataType reduceType = TypeUtils.createRowType(tf, int.class);
    HashAggregateNode<Object[]> reduce = new HashAggregateNode<>(ctx, reduceType, REDUCE, grpSets, accFactory(ctx, call, REDUCE, null), rowFactory());
    reduce.register(map);
    RootNode<Object[]> root = new RootNode<>(ctx, reduceType);
    root.register(reduce);
    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 ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.

the class HashAggregateSingleGroupExecutionTest method mapReduceCount.

@Test
public void mapReduceCount() {
    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, RelCollations.EMPTY, tf.createJavaType(int.class), null);
    List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of());
    RelDataType mapType = IgniteMapHashAggregate.rowType(tf, true);
    HashAggregateNode<Object[]> map = new HashAggregateNode<>(ctx, mapType, MAP, grpSets, accFactory(ctx, call, MAP, rowType), rowFactory());
    map.register(scan);
    RelDataType reduceType = TypeUtils.createRowType(tf, int.class);
    HashAggregateNode<Object[]> reduce = new HashAggregateNode<>(ctx, reduceType, REDUCE, grpSets, accFactory(ctx, call, REDUCE, null), rowFactory());
    reduce.register(map);
    RootNode<Object[]> root = new RootNode<>(ctx, reduceType);
    root.register(reduce);
    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 ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.

the class HashAggregateSingleGroupExecutionTest method singleMin.

@Test
public void singleMin() {
    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.MIN, 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(200, 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 70 with ImmutableBitSet

use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.

the class HashAggregateSingleGroupExecutionTest method mapReduceAvg.

@Test
public void mapReduceAvg() {
    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, null, RelCollations.EMPTY, tf.createJavaType(double.class), null);
    List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of());
    RelDataType mapType = IgniteMapHashAggregate.rowType(tf, true);
    HashAggregateNode<Object[]> map = new HashAggregateNode<>(ctx, mapType, MAP, grpSets, accFactory(ctx, call, MAP, rowType), rowFactory());
    map.register(scan);
    RelDataType reduceType = TypeUtils.createRowType(tf, double.class);
    HashAggregateNode<Object[]> reduce = new HashAggregateNode<>(ctx, reduceType, REDUCE, grpSets, accFactory(ctx, call, REDUCE, null), rowFactory());
    reduce.register(map);
    RootNode<Object[]> root = new RootNode<>(ctx, reduceType);
    root.register(reduce);
    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)

Aggregations

ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)365 RexNode (org.apache.calcite.rex.RexNode)196 RelNode (org.apache.calcite.rel.RelNode)183 ArrayList (java.util.ArrayList)179 AggregateCall (org.apache.calcite.rel.core.AggregateCall)116 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)98 RexBuilder (org.apache.calcite.rex.RexBuilder)92 RelDataType (org.apache.calcite.rel.type.RelDataType)89 RexInputRef (org.apache.calcite.rex.RexInputRef)79 HashMap (java.util.HashMap)68 Aggregate (org.apache.calcite.rel.core.Aggregate)62 RelBuilder (org.apache.calcite.tools.RelBuilder)59 Pair (org.apache.calcite.util.Pair)57 List (java.util.List)49 ImmutableList (com.google.common.collect.ImmutableList)48 HashSet (java.util.HashSet)45 LinkedHashSet (java.util.LinkedHashSet)45 Join (org.apache.calcite.rel.core.Join)45 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)45 Nullable (org.checkerframework.checker.nullness.qual.Nullable)43