Search in sources :

Example 56 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class TableSpoolPlannerTest method tableSpoolDistributed.

/**
 * TableSpoolDistributed.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@Test
public void tableSpoolDistributed() throws Exception {
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    TestTable t0 = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "T0", "hash");
        }
    };
    TestTable t1 = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "T1", "hash");
        }
    };
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("T0", t0);
    publicSchema.addTable("T1", t1);
    String sql = "select * " + "from t0 " + "join t1 on t0.jid > t1.jid";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeRule");
    assertNotNull(phys);
    IgniteTableSpool tblSpool = findFirstNode(phys, byClass(IgniteTableSpool.class));
    assertNotNull(tblSpool, "Invalid plan:\n" + RelOptUtil.toString(phys));
    checkSplitAndSerialization(phys, publicSchema);
}
Also used : IgniteTableSpool(org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 57 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class BaseAggregateTest method min.

/**
 * Min.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@ParameterizedTest
@EnumSource
public void min(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, 300), row(1, 1400), row(0, 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(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, 200), root.next());
    assertArrayEquals(row(1, 300), 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 58 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class BaseAggregateTest method max.

/**
 * Max.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@ParameterizedTest
@EnumSource
public void max(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, 300), row(1, 1400), row(0, 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(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, 1000), root.next());
    assertArrayEquals(row(1, 1400), 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 59 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class BaseAggregateTest method avg.

/**
 * Avg.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@ParameterizedTest
@EnumSource
public void avg(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, 300), row(1, 1300), row(0, 1000)));
    AggregateCall call = AggregateCall.create(SqlStdOperatorTable.AVG, false, 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, 600), root.next());
    assertArrayEquals(row(1, 800), 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 60 with IgniteTypeFactory

use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.

the class BaseAggregateTest method sumOnDifferentRowsCount.

/**
 * SumOnDifferentRowsCount.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@ParameterizedTest
@EnumSource
public void sumOnDifferentRowsCount(TestAggregateType testAgg) {
    int bufSize = Commons.IN_BUFFER_SIZE;
    int[] grpsCount = { 1, bufSize / 2, bufSize, bufSize + 1, bufSize * 4 };
    int[] rowsInGroups = { 1, 5, bufSize };
    for (int grps : grpsCount) {
        for (int rowsInGroup : rowsInGroups) {
            log.info("Check: [grps=" + grps + ", rowsInGroup=" + rowsInGroup + ']');
            ExecutionContext<Object[]> ctx = executionContext();
            IgniteTypeFactory tf = ctx.getTypeFactory();
            RelDataType rowType = TypeUtils.createRowType(tf, int.class, int.class);
            ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, new TestTable(grps * rowsInGroup, rowType, (r) -> r / rowsInGroup, (r) -> r % rowsInGroup));
            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(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);
            IntSet grpId = new IntOpenHashSet(IntStream.range(0, grps).toArray());
            while (root.hasNext()) {
                Object[] row = root.next();
                grpId.remove(((Integer) row[0]).intValue());
                assertEquals((rowsInGroup - 1) * rowsInGroup / 2, row[1]);
            }
            assertTrue(grpId.isEmpty());
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) ArrayUtils.asList(org.apache.ignite.internal.util.ArrayUtils.asList) Arrays(java.util.Arrays) Accumulators(org.apache.ignite.internal.sql.engine.exec.exp.agg.Accumulators) EnumSource(org.junit.jupiter.params.provider.EnumSource) Supplier(java.util.function.Supplier) IgniteTestUtils.assertThrowsWithCause(org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RelCollations(org.apache.calcite.rel.RelCollations) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) RelDataType(org.apache.calcite.rel.type.RelDataType) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) RowHandler(org.apache.ignite.internal.sql.engine.exec.RowHandler) AggregateType(org.apache.ignite.internal.sql.engine.exec.exp.agg.AggregateType) AccumulatorWrapper(org.apache.ignite.internal.sql.engine.exec.exp.agg.AccumulatorWrapper) TypeUtils(org.apache.ignite.internal.sql.engine.util.TypeUtils) Commons(org.apache.ignite.internal.sql.engine.util.Commons) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IntSet(it.unimi.dsi.fastutil.ints.IntSet) AggregateCall(org.apache.calcite.rel.core.AggregateCall) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) AggregateCall(org.apache.calcite.rel.core.AggregateCall) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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