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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations