Search in sources :

Example 1 with RexExecutorImpl

use of org.apache.calcite.rex.RexExecutorImpl in project calcite by apache.

the class SubstitutionVisitor method isWeaker.

/**
 * Returns if one rel is weaker than another.
 */
protected boolean isWeaker(MutableRel rel0, MutableRel rel) {
    if (rel0 == rel || equivalents.get(rel0).contains(rel)) {
        return false;
    }
    if (!(rel0 instanceof MutableFilter) || !(rel instanceof MutableFilter)) {
        return false;
    }
    if (!rel.rowType.equals(rel0.rowType)) {
        return false;
    }
    final MutableRel rel0input = ((MutableFilter) rel0).getInput();
    final MutableRel relinput = ((MutableFilter) rel).getInput();
    if (rel0input != relinput && !equivalents.get(rel0input).contains(relinput)) {
        return false;
    }
    RexExecutorImpl rexImpl = (RexExecutorImpl) (rel.cluster.getPlanner().getExecutor());
    RexImplicationChecker rexImplicationChecker = new RexImplicationChecker(rel.cluster.getRexBuilder(), rexImpl, rel.rowType);
    return rexImplicationChecker.implies(((MutableFilter) rel0).condition, ((MutableFilter) rel).condition);
}
Also used : RexExecutorImpl(org.apache.calcite.rex.RexExecutorImpl) MutableFilter(org.apache.calcite.rel.mutable.MutableFilter) MutableRel(org.apache.calcite.rel.mutable.MutableRel)

Example 2 with RexExecutorImpl

use of org.apache.calcite.rex.RexExecutorImpl in project calcite by apache.

the class RexProgramTest method setUp.

@Before
public void setUp() {
    typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    rexBuilder = new RexBuilder(typeFactory);
    RexExecutor executor = new RexExecutorImpl(new DummyTestDataContext());
    simplify = new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, false, executor);
    trueLiteral = rexBuilder.makeLiteral(true);
    falseLiteral = rexBuilder.makeLiteral(false);
    final RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);
    nullLiteral = rexBuilder.makeNullLiteral(intType);
    unknownLiteral = rexBuilder.makeNullLiteral(trueLiteral.getType());
}
Also used : RexExecutorImpl(org.apache.calcite.rex.RexExecutorImpl) RexSimplify(org.apache.calcite.rex.RexSimplify) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) RexExecutor(org.apache.calcite.rex.RexExecutor) RexBuilder(org.apache.calcite.rex.RexBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) Before(org.junit.Before)

Example 3 with RexExecutorImpl

use of org.apache.calcite.rex.RexExecutorImpl in project hive by apache.

the class SubstitutionVisitor method isWeaker.

/** Returns if one rel is weaker than another. */
protected boolean isWeaker(MutableRel rel0, MutableRel rel) {
    if (rel0 == rel || equivalents.get(rel0).contains(rel)) {
        return false;
    }
    if (!(rel0 instanceof MutableFilter) || !(rel instanceof MutableFilter)) {
        return false;
    }
    if (!rel.getRowType().equals(rel0.getRowType())) {
        return false;
    }
    final MutableRel rel0input = ((MutableFilter) rel0).getInput();
    final MutableRel relinput = ((MutableFilter) rel).getInput();
    if (rel0input != relinput && !equivalents.get(rel0input).contains(relinput)) {
        return false;
    }
    RexExecutorImpl rexImpl = (RexExecutorImpl) (rel.cluster.getPlanner().getExecutor());
    RexImplicationChecker rexImplicationChecker = new RexImplicationChecker(rel.cluster.getRexBuilder(), rexImpl, rel.getRowType());
    return rexImplicationChecker.implies(((MutableFilter) rel0).getCondition(), ((MutableFilter) rel).getCondition());
}
Also used : RexExecutorImpl(org.apache.calcite.rex.RexExecutorImpl) RexImplicationChecker(org.apache.calcite.plan.RexImplicationChecker)

Example 4 with RexExecutorImpl

use of org.apache.calcite.rex.RexExecutorImpl in project druid by druid-io.

the class PlannerFactory method createPlanner.

public DruidPlanner createPlanner(final Map<String, Object> queryContext) {
    final PlannerContext plannerContext = PlannerContext.create(plannerConfig, queryContext);
    final QueryMaker queryMaker = new QueryMaker(walker, plannerContext);
    final FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setCaseSensitive(true).setUnquotedCasing(Casing.UNCHANGED).setQuotedCasing(Casing.UNCHANGED).setQuoting(Quoting.DOUBLE_QUOTE).build()).defaultSchema(rootSchema).traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE).convertletTable(new DruidConvertletTable(plannerContext)).operatorTable(operatorTable).programs(Rules.programs(queryMaker, operatorTable)).executor(new RexExecutorImpl(Schemas.createDataContext(null))).context(Contexts.EMPTY_CONTEXT).typeSystem(RelDataTypeSystem.DEFAULT).defaultSchema(rootSchema.getSubSchema(DruidSchema.NAME)).build();
    return new DruidPlanner(Frameworks.getPlanner(frameworkConfig), plannerContext);
}
Also used : RexExecutorImpl(org.apache.calcite.rex.RexExecutorImpl) QueryMaker(io.druid.sql.calcite.rel.QueryMaker) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig)

Example 5 with RexExecutorImpl

use of org.apache.calcite.rex.RexExecutorImpl in project calcite by apache.

the class RelOptUtil method containsNullableFields.

/**
 * Determines whether any of the fields in a given relational expression may
 * contain null values, taking into account constraints on the field types and
 * also deduced predicates.
 *
 * <p>The method is cautious: It may sometimes return {@code true} when the
 * actual answer is {@code false}. In particular, it does this when there
 * is no executor, or the executor is not a sub-class of
 * {@link RexExecutorImpl}.
 */
private static boolean containsNullableFields(RelNode r) {
    final RexBuilder rexBuilder = r.getCluster().getRexBuilder();
    final RelDataType rowType = r.getRowType();
    final List<RexNode> list = new ArrayList<>();
    final RelMetadataQuery mq = r.getCluster().getMetadataQuery();
    for (RelDataTypeField field : rowType.getFieldList()) {
        if (field.getType().isNullable()) {
            list.add(rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, rexBuilder.makeInputRef(field.getType(), field.getIndex())));
        }
    }
    if (list.isEmpty()) {
        // All columns are declared NOT NULL.
        return false;
    }
    final RelOptPredicateList predicates = mq.getPulledUpPredicates(r);
    if (predicates.pulledUpPredicates.isEmpty()) {
        // declared NULL are really NOT NULL.
        return true;
    }
    final RexExecutor executor = r.getCluster().getPlanner().getExecutor();
    if (!(executor instanceof RexExecutorImpl)) {
        // Cannot proceed without an executor.
        return true;
    }
    final RexImplicationChecker checker = new RexImplicationChecker(rexBuilder, (RexExecutorImpl) executor, rowType);
    final RexNode first = RexUtil.composeConjunction(rexBuilder, predicates.pulledUpPredicates, false);
    final RexNode second = RexUtil.composeConjunction(rexBuilder, list, false);
    // It does, so we have no nullable columns.
    return !checker.implies(first, second);
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RexExecutorImpl(org.apache.calcite.rex.RexExecutorImpl) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RexExecutor(org.apache.calcite.rex.RexExecutor) ArrayList(java.util.ArrayList) RexBuilder(org.apache.calcite.rex.RexBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

RexExecutorImpl (org.apache.calcite.rex.RexExecutorImpl)6 ArrayList (java.util.ArrayList)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 RexBuilder (org.apache.calcite.rex.RexBuilder)2 RexExecutor (org.apache.calcite.rex.RexExecutor)2 QueryMaker (io.druid.sql.calcite.rel.QueryMaker)1 DataContext (org.apache.calcite.DataContext)1 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)1 CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)1 LatticeEntry (org.apache.calcite.jdbc.CalciteSchema.LatticeEntry)1 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelOptLattice (org.apache.calcite.plan.RelOptLattice)1 RelOptMaterialization (org.apache.calcite.plan.RelOptMaterialization)1 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RexImplicationChecker (org.apache.calcite.plan.RexImplicationChecker)1 RelNode (org.apache.calcite.rel.RelNode)1 RelVisitor (org.apache.calcite.rel.RelVisitor)1