Search in sources :

Example 61 with IgniteTypeFactory

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());
}
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) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with IgniteTypeFactory

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));
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with IgniteTypeFactory

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));
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with IgniteTypeFactory

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());
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with IgniteTypeFactory

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

IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)80 Test (org.junit.jupiter.api.Test)48 RelDataType (org.apache.calcite.rel.type.RelDataType)47 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)27 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)22 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)21 AggregateCall (org.apache.calcite.rel.core.AggregateCall)19 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 RexNode (org.apache.calcite.rex.RexNode)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 ArrayList (java.util.ArrayList)10 SchemaPlus (org.apache.calcite.schema.SchemaPlus)8 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)8 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)7 List (java.util.List)6 MappingQueryContext (org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext)6 MultiStepPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan)6 MultiStepQueryPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan)6 QueryTemplate (org.apache.ignite.internal.sql.engine.prepare.QueryTemplate)6