Search in sources :

Example 11 with IgniteTypeFactory

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

the class SetOpPlannerTest method setup.

/**
 * Setup.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@BeforeAll
public void setup() {
    publicSchema = new IgniteSchema("PUBLIC");
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    RelDataType type = new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).add("SALARY", f.createJavaType(Double.class)).build();
    createTable(publicSchema, "RANDOM_TBL1", type, IgniteDistributions.random());
    createTable(publicSchema, "RANDOM_TBL2", type, IgniteDistributions.random());
    createTable(publicSchema, "BROADCAST_TBL1", type, IgniteDistributions.broadcast());
    createTable(publicSchema, "BROADCAST_TBL2", type, IgniteDistributions.broadcast());
    createTable(publicSchema, "SINGLE_TBL1", type, IgniteDistributions.single());
    createTable(publicSchema, "SINGLE_TBL2", type, IgniteDistributions.single());
    createTable(publicSchema, "AFFINITY_TBL1", type, IgniteDistributions.affinity(0, "Test1", "hash"));
    createTable(publicSchema, "AFFINITY_TBL2", type, IgniteDistributions.affinity(0, "Test2", "hash"));
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 12 with IgniteTypeFactory

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

the class SortAggregatePlannerTest method collationPermuteSingle.

/**
 * CollationPermuteSingle.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@Test
public void collationPermuteSingle() throws Exception {
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    TestTable tbl = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("VAL0", f.createJavaType(Integer.class)).add("VAL1", f.createJavaType(Integer.class)).add("GRP0", f.createJavaType(Integer.class)).add("GRP1", f.createJavaType(Integer.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.broadcast();
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(3, 4)), "grp0_1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT MIN(val0) FROM test GROUP BY grp1, grp0";
    IgniteRel phys = physicalPlan(sql, publicSchema, "HashSingleAggregateConverterRule", "HashMapReduceAggregateConverterRule");
    IgniteSingleSortAggregate agg = findFirstNode(phys, byClass(IgniteSingleSortAggregate.class));
    assertNotNull(agg, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertNull(findFirstNode(phys, byClass(IgniteSort.class)), "Invalid plan\n" + RelOptUtil.toString(phys));
}
Also used : IgniteSingleSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleSortAggregate) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteDistribution(org.apache.ignite.internal.sql.engine.trait.IgniteDistribution) Test(org.junit.jupiter.api.Test)

Example 13 with IgniteTypeFactory

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

the class LimitOffsetPlannerTest method createSchemaWithTable.

/**
 * Creates PUBLIC schema with one TEST table.
 */
private IgniteSchema createSchemaWithTable(IgniteDistribution distr, int... indexedColumns) {
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    RelDataType type = new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build();
    TestTable table = new TestTable("TEST", type, ROW_CNT) {

        @Override
        public IgniteDistribution distribution() {
            return distr;
        }
    };
    if (!ArrayUtils.nullOrEmpty(indexedColumns)) {
        table.addIndex(RelCollations.of(Arrays.stream(indexedColumns).mapToObj(idx -> new RelFieldCollation(idx, RelFieldCollation.Direction.ASCENDING, RelFieldCollation.NullDirection.FIRST)).collect(toList())), "test_idx");
    }
    return createSchema(table);
}
Also used : RelCollations(org.apache.calcite.rel.RelCollations) IgniteDistributions(org.apache.ignite.internal.sql.engine.trait.IgniteDistributions) RelDataType(org.apache.calcite.rel.type.RelDataType) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) Arrays(java.util.Arrays) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) IgniteLimit(org.apache.ignite.internal.sql.engine.rel.IgniteLimit) IgniteExchange(org.apache.ignite.internal.sql.engine.rel.IgniteExchange) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) ArrayUtils(org.apache.ignite.internal.util.ArrayUtils) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) IgniteTypeSystem(org.apache.ignite.internal.sql.engine.type.IgniteTypeSystem) IgniteDistribution(org.apache.ignite.internal.sql.engine.trait.IgniteDistribution) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteUnionAll(org.apache.ignite.internal.sql.engine.rel.IgniteUnionAll) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 14 with IgniteTypeFactory

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

the class CorrelatedNestedLoopJoinPlannerTest method testValidIndexExpressions.

/**
 * Check equi-join. CorrelatedNestedLoopJoinTest is applicable for it.
 */
@Test
public void testValidIndexExpressions() throws Exception {
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    publicSchema.addTable("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.broadcast();
        }
    });
    publicSchema.addTable("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.broadcast();
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t1_jid_idx"));
    String sql = "select * " + "from t0 " + "join t1 on t0.jid = t1.jid";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter");
    System.out.println("+++ " + RelOptUtil.toString(phys));
    assertNotNull(phys);
    IgniteIndexScan idxScan = findFirstNode(phys, byClass(IgniteIndexScan.class));
    List<RexNode> lowerBound = idxScan.lowerBound();
    assertNotNull(lowerBound, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertEquals(3, lowerBound.size());
    assertTrue(((RexLiteral) lowerBound.get(0)).isNull());
    assertTrue(((RexLiteral) lowerBound.get(2)).isNull());
    assertTrue(lowerBound.get(1) instanceof RexFieldAccess);
    List<RexNode> upperBound = idxScan.upperBound();
    assertNotNull(upperBound, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertEquals(3, upperBound.size());
    assertTrue(((RexLiteral) upperBound.get(0)).isNull());
    assertTrue(((RexLiteral) upperBound.get(2)).isNull());
    assertTrue(upperBound.get(1) instanceof RexFieldAccess);
}
Also used : IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteDistribution(org.apache.ignite.internal.sql.engine.trait.IgniteDistribution) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.jupiter.api.Test)

Example 15 with IgniteTypeFactory

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

the class SortAggregatePlannerTest method collationPermuteMapReduce.

/**
 * CollationPermuteMapReduce.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@Test
public void collationPermuteMapReduce() throws Exception {
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    TestTable tbl = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("VAL0", f.createJavaType(Integer.class)).add("VAL1", f.createJavaType(Integer.class)).add("GRP0", f.createJavaType(Integer.class)).add("GRP1", f.createJavaType(Integer.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "test", "hash");
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(3, 4)), "grp0_1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT MIN(val0) FROM test GROUP BY grp1, grp0";
    IgniteRel phys = physicalPlan(sql, publicSchema, "HashSingleAggregateConverterRule", "HashMapReduceAggregateConverterRule");
    IgniteReduceSortAggregate agg = findFirstNode(phys, byClass(IgniteReduceSortAggregate.class));
    assertNotNull(agg, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertNull(findFirstNode(phys, byClass(IgniteSort.class)), "Invalid plan\n" + RelOptUtil.toString(phys));
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteDistribution(org.apache.ignite.internal.sql.engine.trait.IgniteDistribution) IgniteReduceSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceSortAggregate) 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