use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class BaseAggregateTest method distinctSum.
/**
* Distinct sum.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@ParameterizedTest
@EnumSource
public void distinctSum(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, Arrays.asList(row(0, 200), row(1, 200), row(1, 300), row(1, 300), row(0, 1000), row(0, 1000), row(0, 1000), row(0, 1000), row(0, 200)));
AggregateCall call = AggregateCall.create(SqlStdOperatorTable.SUM, true, false, false, ImmutableIntList.of(1), -1, 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, 1200), root.next());
assertArrayEquals(row(1, 500), root.next());
assertFalse(root.hasNext());
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ExecutionTest method testAntiJoin.
@Test
public void testAntiJoin() {
// select d.name as dep_name
// from dep d
// anti join emp e
// on e.depno = d.depno
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, String.class, Integer.class);
ScanNode<Object[]> persons = new ScanNode<>(ctx, rowType, Arrays.asList(new Object[] { 0, "Igor", 1 }, new Object[] { 1, "Roman", 2 }, new Object[] { 2, "Ivan", null }, new Object[] { 3, "Alexey", 1 }));
rowType = TypeUtils.createRowType(tf, int.class, String.class);
ScanNode<Object[]> deps = new ScanNode<>(ctx, rowType, Arrays.asList(new Object[] { 1, "Core" }, new Object[] { 2, "SQL" }, new Object[] { 3, "QA" }));
RelDataType outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
RowHandler<Object[]> hnd = ctx.rowHandler();
NestedLoopJoinNode<Object[]> join = NestedLoopJoinNode.create(ctx, outType, leftType, rightType, ANTI, (r1, r2) -> getFieldFromBiRows(hnd, 0, r1, r2) == getFieldFromBiRows(hnd, 4, r1, r2));
join.register(asList(deps, persons));
rowType = TypeUtils.createRowType(tf, String.class);
ProjectNode<Object[]> project = new ProjectNode<>(ctx, rowType, r -> new Object[] { r[1] });
project.register(join);
RootNode<Object[]> node = new RootNode<>(ctx, rowType);
node.register(project);
assert node.hasNext();
ArrayList<Object[]> rows = new ArrayList<>();
while (node.hasNext()) {
rows.add(node.next());
}
assertEquals(1, rows.size());
assertArrayEquals(new Object[] { "QA" }, rows.get(0));
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ExecutionTest method testRightJoin.
@Test
public void testRightJoin() {
// select e.id, e.name, d.name as dep_name
// from dep d
// right join emp e
// on e.depno = d.depno
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, String.class, Integer.class);
ScanNode<Object[]> persons = new ScanNode<>(ctx, rowType, Arrays.asList(new Object[] { 0, "Igor", 1 }, new Object[] { 1, "Roman", 2 }, new Object[] { 2, "Ivan", null }, new Object[] { 3, "Alexey", 1 }));
rowType = TypeUtils.createRowType(tf, int.class, String.class);
ScanNode<Object[]> deps = new ScanNode<>(ctx, rowType, Arrays.asList(new Object[] { 1, "Core" }, new Object[] { 2, "SQL" }, new Object[] { 3, "QA" }));
RelDataType outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, int.class, String.class, Integer.class);
RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
RowHandler<Object[]> hnd = ctx.rowHandler();
NestedLoopJoinNode<Object[]> join = NestedLoopJoinNode.create(ctx, outType, leftType, rightType, RIGHT, (r1, r2) -> getFieldFromBiRows(hnd, 0, r1, r2) == getFieldFromBiRows(hnd, 4, r1, r2));
join.register(asList(deps, persons));
rowType = TypeUtils.createRowType(tf, int.class, String.class, String.class);
ProjectNode<Object[]> project = new ProjectNode<>(ctx, rowType, r -> new Object[] { r[2], r[3], r[1] });
project.register(join);
RootNode<Object[]> node = new RootNode<>(ctx, rowType);
node.register(project);
assert node.hasNext();
ArrayList<Object[]> rows = new ArrayList<>();
while (node.hasNext()) {
rows.add(node.next());
}
assertEquals(4, rows.size());
assertArrayEquals(new Object[] { 0, "Igor", "Core" }, rows.get(0));
assertArrayEquals(new Object[] { 3, "Alexey", "Core" }, rows.get(1));
assertArrayEquals(new Object[] { 1, "Roman", "SQL" }, rows.get(2));
assertArrayEquals(new Object[] { 2, "Ivan", null }, rows.get(3));
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ExecutionTest method testUnionAll.
@Test
public void testUnionAll() {
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, String.class, int.class);
ScanNode<Object[]> scan1 = new ScanNode<>(ctx, rowType, Arrays.asList(row("Igor", 200), row("Roman", 300), row("Ivan", 1400), row("Alexey", 1000)));
ScanNode<Object[]> scan2 = new ScanNode<>(ctx, rowType, Arrays.asList(row("Igor", 200), row("Roman", 300), row("Ivan", 1400), row("Alexey", 1000)));
ScanNode<Object[]> scan3 = new ScanNode<>(ctx, rowType, Arrays.asList(row("Igor", 200), row("Roman", 300), row("Ivan", 1400), row("Alexey", 1000)));
UnionAllNode<Object[]> union = new UnionAllNode<>(ctx, rowType);
union.register(asList(scan1, scan2, scan3));
RootNode<Object[]> root = new RootNode<>(ctx, rowType);
root.register(union);
assertTrue(root.hasNext());
List<Object[]> res = new ArrayList<>();
while (root.hasNext()) {
res.add(root.next());
}
assertEquals(12, res.size());
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class HashAggregateSingleGroupExecutionTest method singleSum.
@Test
public void singleSum() {
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 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(2900, root.next()[0]);
assertFalse(root.hasNext());
}
Aggregations