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