use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project hive by apache.
the class HiveFilterProjectTSTransposeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final Project project = call.rel(1);
if (RexOver.containsOver(project.getProjects(), null)) {
// it can be pushed down. For now we don't support this.
return;
}
if (RexUtil.containsCorrelation(filter.getCondition())) {
// Correlate from being de-correlated.
return;
}
// convert the filter to one that references the child of the project
RexNode newCondition = RelOptUtil.pushPastProject(filter.getCondition(), project);
// Remove cast of BOOLEAN NOT NULL to BOOLEAN or vice versa. Filter accepts
// nullable and not-nullable conditions, but a CAST might get in the way of
// other rewrites.
final RelDataTypeFactory typeFactory = filter.getCluster().getTypeFactory();
if (RexUtil.isNullabilityCast(typeFactory, newCondition)) {
newCondition = ((RexCall) newCondition).getOperands().get(0);
}
RelNode newFilterRel = filterFactory == null ? filter.copy(filter.getTraitSet(), project.getInput(), newCondition) : filterFactory.createFilter(project.getInput(), newCondition);
RelNode newProjRel = projectFactory == null ? project.copy(project.getTraitSet(), newFilterRel, project.getProjects(), project.getRowType()) : projectFactory.createProject(newFilterRel, Collections.emptyList(), project.getProjects(), project.getRowType().getFieldNames());
call.transformTo(newProjRel);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project hive by apache.
the class HiveAntiSemiJoinRule method perform.
protected void perform(RelOptRuleCall call, Project project, Filter filter, Join join) {
LOG.debug("Start Matching HiveAntiJoinRule");
// https://issues.apache.org/jira/browse/HIVE-23991
if (join.getCondition().isAlwaysTrue()) {
return;
}
// We support conversion from left outer join only.
if (join.getJoinType() != JoinRelType.LEFT) {
return;
}
assert (filter != null);
List<RexNode> filterList = getResidualFilterNodes(filter, join);
if (filterList == null) {
return;
}
// If any projection is there from right side, then we can not convert to anti join.
boolean hasProjection = HiveCalciteUtil.hasAnyExpressionFromRightSide(join, project.getProjects());
if (hasProjection) {
return;
}
LOG.debug("Matched HiveAntiJoinRule");
// Build anti join with same left, right child and condition as original left outer join.
Join anti = HiveAntiJoin.getAntiJoin(join.getLeft().getCluster(), join.getLeft().getTraitSet(), join.getLeft(), join.getRight(), join.getCondition());
RelNode newProject;
if (filterList.isEmpty()) {
newProject = project.copy(project.getTraitSet(), anti, project.getProjects(), project.getRowType());
} else {
// Collate the filter condition using AND as the filter was decomposed based
// on AND condition (RelOptUtil.conjunctions).
RexNode condition = filterList.size() == 1 ? filterList.get(0) : join.getCluster().getRexBuilder().makeCall(SqlStdOperatorTable.AND, filterList);
Filter newFilter = filter.copy(filter.getTraitSet(), anti, condition);
newProject = project.copy(project.getTraitSet(), newFilter, project.getProjects(), project.getRowType());
}
call.transformTo(newProject);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project hive by apache.
the class CorrelateProjectExtractor method findCorrelationDependentCalls.
/**
* Traverses a plan and finds all simply correlated row expressions with the specified id.
*/
private static Set<RexNode> findCorrelationDependentCalls(CorrelationId corrId, RelNode plan) {
SimpleCorrelationCollector finder = new SimpleCorrelationCollector(corrId);
plan.accept(new RelHomogeneousShuttle() {
@Override
public RelNode visit(RelNode other) {
if (other instanceof Project || other instanceof Filter) {
other.accept(finder);
}
return super.visit(other);
}
});
return finder.correlations;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project beam by apache.
the class AbstractBeamCalcRel method estimateFilterSelectivity.
private static double estimateFilterSelectivity(RelNode child, RexProgram program, RelMetadataQuery mq) {
// Similar to calcite, if the calc node is representing filter operation we estimate the filter
// selectivity based on the number of equality conditions, number of inequality conditions, ....
RexLocalRef programCondition = program.getCondition();
RexNode condition;
if (programCondition == null) {
condition = null;
} else {
condition = program.expandLocalRef(programCondition);
}
// Currently this gets the selectivity based on Calcite's Selectivity Handler (RelMdSelectivity)
return mq.getSelectivity(child, condition);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project beam by apache.
the class BeamAggregateProjectMergeRule method getUnderlyingIO.
/**
* Following scenarios are possible:<br>
* 1) Aggregate <- Project <- IO.<br>
* 2) Aggregate <- Project <- Chain of Project/Filter <- IO.<br>
* 3) Aggregate <- Project <- Something else.<br>
* 4) Aggregate <- Project <- Chain of Project/Filter <- Something else.
*
* @param parent project that matched this rule.
* @return {@code BeamIOSourceRel} when it is present or null when some other {@code RelNode} is
* present.
*/
private BeamIOSourceRel getUnderlyingIO(Set<RelNode> visitedNodes, SingleRel parent) {
// No need to look at the same node more than once.
if (visitedNodes.contains(parent)) {
return null;
}
visitedNodes.add(parent);
List<RelNode> nodes = ((RelSubset) parent.getInput()).getRelList();
for (RelNode node : nodes) {
if (node instanceof Filter || node instanceof Project) {
// Search node inputs for an IO.
BeamIOSourceRel child = getUnderlyingIO(visitedNodes, (SingleRel) node);
if (child != null) {
return child;
}
} else if (node instanceof BeamIOSourceRel) {
return (BeamIOSourceRel) node;
}
}
return null;
}
Aggregations