Java Code Examples for org.apache.calcite.rex.RexUtil#removeNullabilityCast()
The following examples show how to use
org.apache.calcite.rex.RexUtil#removeNullabilityCast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelOptUtil.java From calcite with Apache License 2.0 | 6 votes |
private static RexCall doCollapseExpandedIsNotDistinctFrom(final RexBuilder rexBuilder, final RexCall call, RexCall ifNull0Call, RexCall ifNull1Call, RexCall equalsCall) { final RexNode isNullInput0 = ifNull0Call.getOperands().get(0); final RexNode isNullInput1 = ifNull1Call.getOperands().get(0); final RexNode equalsInput0 = RexUtil .removeNullabilityCast(rexBuilder.getTypeFactory(), equalsCall.getOperands().get(0)); final RexNode equalsInput1 = RexUtil .removeNullabilityCast(rexBuilder.getTypeFactory(), equalsCall.getOperands().get(1)); if ((isNullInput0.equals(equalsInput0) && isNullInput1.equals(equalsInput1)) || (isNullInput1.equals(equalsInput0) && isNullInput0.equals(equalsInput1))) { return (RexCall) rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM, ImmutableList.of(isNullInput0, isNullInput1)); } return call; }
Example 2
Source File: FilterProjectTransposeRule.java From Bats with Apache License 2.0 | 5 votes |
/** * Simplifies the filter condition using a simplifier created by the * information in the current call. * * <p>This method is an attempt to replicate the simplification behavior of * {@link RelBuilder#filter(RexNode...)} which cannot be used in the case of * copying nodes. The main difference with the behavior of that method is that * it does not drop entirely the filter if the condition is always false. */ private RexNode simplifyFilterCondition(RexNode condition, RelOptRuleCall call) { final RexBuilder xBuilder = call.builder().getRexBuilder(); final RexExecutor executor = Util.first(call.getPlanner().getContext().unwrap(RexExecutor.class), Util.first(call.getPlanner().getExecutor(), RexUtil.EXECUTOR)); // unknownAsFalse => true since in the WHERE clause: // 1>null evaluates to unknown and WHERE unknown behaves exactly like WHERE false RexSimplify simplifier = new RexSimplify(xBuilder, RelOptPredicateList.EMPTY, executor); return RexUtil.removeNullabilityCast( xBuilder.getTypeFactory(), simplifier.simplifyUnknownAsFalse(condition)); }
Example 3
Source File: FilterProjectTransposeRule.java From calcite with Apache License 2.0 | 4 votes |
public void onMatch(RelOptRuleCall call) { final Filter filter = call.rel(0); final Project project = call.rel(1); if (RexOver.containsOver(project.getProjects(), null)) { // In general a filter cannot be pushed below a windowing calculation. // Applying the filter before the aggregation function changes // the results of the windowing invocation. // // When the filter is on the PARTITION BY expression of the OVER clause // it can be pushed down. For now we don't support this. return; } // convert the filter to one that references the child of the project RexNode newCondition = RelOptUtil.pushPastProject(filter.getCondition(), project); final RelBuilder relBuilder = call.builder(); RelNode newFilterRel; if (copyFilter) { final RelNode input = project.getInput(); final RelTraitSet traitSet = filter.getTraitSet() .replaceIfs(RelCollationTraitDef.INSTANCE, () -> Collections.singletonList( input.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE))) .replaceIfs(RelDistributionTraitDef.INSTANCE, () -> Collections.singletonList( input.getTraitSet().getTrait(RelDistributionTraitDef.INSTANCE))); newCondition = RexUtil.removeNullabilityCast(relBuilder.getTypeFactory(), newCondition); newFilterRel = filter.copy(traitSet, input, newCondition); } else { newFilterRel = relBuilder.push(project.getInput()).filter(newCondition).build(); } RelNode newProjRel = copyProject ? project.copy(project.getTraitSet(), newFilterRel, project.getProjects(), project.getRowType()) : relBuilder.push(newFilterRel) .project(project.getProjects(), project.getRowType().getFieldNames()) .build(); call.transformTo(newProjRel); }