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