use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.
the class SortAggregateExecutionTest method createSingleAggregateNodesChain.
/**
* {@inheritDoc}
*/
@Override
protected SingleNode<Object[]> createSingleAggregateNodesChain(ExecutionContext<Object[]> ctx, List<ImmutableBitSet> grpSets, AggregateCall call, RelDataType inRowType, RelDataType aggRowType, RowHandler.RowFactory<Object[]> rowFactory, ScanNode<Object[]> scan) {
assert grpSets.size() == 1;
ImmutableBitSet grpSet = first(grpSets);
assert !grpSet.isEmpty() : "Not applicable for sort aggregate";
RelCollation collation = RelCollations.of(ImmutableIntList.copyOf(grpSet.asList()));
Comparator<Object[]> cmp = ctx.expressionFactory().comparator(collation);
SortNode<Object[]> sort = new SortNode<>(ctx, inRowType, cmp);
sort.register(scan);
SortAggregateNode<Object[]> agg = new SortAggregateNode<>(ctx, aggRowType, SINGLE, grpSet, accFactory(ctx, call, SINGLE, inRowType), rowFactory, cmp);
agg.register(sort);
return agg;
}
use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.
the class SortAggregateExecutionTest method createMapReduceAggregateNodesChain.
/**
* {@inheritDoc}
*/
@Override
protected SingleNode<Object[]> createMapReduceAggregateNodesChain(ExecutionContext<Object[]> ctx, List<ImmutableBitSet> grpSets, AggregateCall call, RelDataType inRowType, RelDataType aggRowType, RowHandler.RowFactory<Object[]> rowFactory, ScanNode<Object[]> scan) {
assert grpSets.size() == 1;
ImmutableBitSet grpSet = first(grpSets);
assert !grpSet.isEmpty() : "Not applicable for sort aggregate";
RelCollation collation = RelCollations.of(ImmutableIntList.copyOf(grpSet.asList()));
Comparator<Object[]> cmp = ctx.expressionFactory().comparator(collation);
SortNode<Object[]> sort = new SortNode<>(ctx, inRowType, cmp);
sort.register(scan);
SortAggregateNode<Object[]> aggMap = new SortAggregateNode<>(ctx, aggRowType, MAP, grpSet, accFactory(ctx, call, MAP, inRowType), rowFactory, cmp);
aggMap.register(sort);
// The group's fields placed on the begin of the output row (planner
// does this by Projection node for aggregate input).
// Hash aggregate doesn't use groups set on reducer because send GroupKey as object.
ImmutableIntList reduceGrpFields = ImmutableIntList.copyOf(IntStream.range(0, grpSet.cardinality()).boxed().collect(Collectors.toList()));
RelCollation rdcCollation = RelCollations.of(reduceGrpFields);
Comparator<Object[]> rdcCmp = ctx.expressionFactory().comparator(rdcCollation);
SortAggregateNode<Object[]> aggRdc = new SortAggregateNode<>(ctx, aggRowType, REDUCE, ImmutableBitSet.of(reduceGrpFields), accFactory(ctx, call, REDUCE, aggRowType), rowFactory, rdcCmp);
aggRdc.register(aggMap);
return aggRdc;
}
use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.
the class BaseAggregateTest method count.
/**
* Count.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@ParameterizedTest
@EnumSource
public void count(TestAggregateType testAgg) {
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, int.class);
ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, Arrays.asList(row(0, 200), row(1, 300), row(1, 1400), row(0, 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(0));
RelDataType aggRowType = TypeUtils.createRowType(tf, int.class);
SingleNode<Object[]> aggChain = createAggregateNodesChain(testAgg, ctx, grpSets, call, rowType, aggRowType, rowFactory(), scan);
RootNode<Object[]> root = new RootNode<>(ctx, aggRowType);
root.register(aggChain);
assertTrue(root.hasNext());
assertArrayEquals(row(0, 2), root.next());
assertArrayEquals(row(1, 2), root.next());
assertFalse(root.hasNext());
}
use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.
the class BaseAggregateTest method singleAggr.
/**
* Checks single aggregate and appropriate {@link Accumulators.SingleVal} implementation.
*
* @param scanInput Input data.
* @param output Expectation result.
* @param mustFail {@code true} If expression must throw exception.
*/
@SuppressWarnings("ThrowableNotThrown")
public void singleAggr(TestAggregateType testAgg, List<Object[]> scanInput, Object[] output, boolean mustFail) {
ExecutionContext<Object[]> ctx = executionContext();
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, int.class);
ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, scanInput);
AggregateCall call = AggregateCall.create(SqlStdOperatorTable.SINGLE_VALUE, false, false, false, ImmutableIntList.of(1), -1, RelCollations.EMPTY, tf.createJavaType(Integer.class), null);
List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of(0));
RelDataType aggRowType = TypeUtils.createRowType(tf, int.class);
SingleNode<Object[]> aggChain = createAggregateNodesChain(testAgg, ctx, grpSets, call, rowType, aggRowType, rowFactory(), scan);
RootNode<Object[]> root = new RootNode<>(ctx, aggRowType);
root.register(aggChain);
Runnable r = () -> {
assertTrue(root.hasNext());
assertArrayEquals(row(0, output[0]), root.next());
assertArrayEquals(row(1, output[1]), root.next());
assertFalse(root.hasNext());
};
if (mustFail) {
assertThrowsWithCause(r::run, IllegalArgumentException.class);
} else {
r.run();
}
}
use of org.apache.calcite.util.ImmutableBitSet in project ignite-3 by apache.
the class HashAggregateExecutionTest method countOfEmptyWithRewind.
/**
* Test verifies that after rewind all groups are properly initialized.
*/
@ParameterizedTest
@EnumSource
public void countOfEmptyWithRewind(TestAggregateType testAgg) {
ExecutionContext<Object[]> ctx = executionContext();
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, int.class);
ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, Collections.emptyList());
AggregateCall call = AggregateCall.create(SqlStdOperatorTable.COUNT, false, false, false, ImmutableIntList.of(), -1, null, RelCollations.EMPTY, tf.createJavaType(int.class), null);
ImmutableList<ImmutableBitSet> grpSets = ImmutableList.of(ImmutableBitSet.of());
RelDataType aggRowType = TypeUtils.createRowType(tf, int.class);
SingleNode<Object[]> aggChain = createAggregateNodesChain(testAgg, ctx, grpSets, call, rowType, aggRowType, rowFactory(), scan);
for (int i = 0; i < 2; i++) {
RootNode<Object[]> root = new RootNode<>(ctx, aggRowType) {
/**
* {@inheritDoc}
*/
@Override
public void close() {
// NO-OP
}
};
root.register(aggChain);
assertTrue(root.hasNext());
assertArrayEquals(row(0), root.next());
assertFalse(root.hasNext());
aggChain.rewind();
}
}
Aggregations