use of org.apache.calcite.rex.RexNode in project hive by apache.
the class FilterSelectivityEstimator method computeDisjunctionSelectivity.
/**
* Disjunction Selectivity -> (1 D(1-m1/n)(1-m2/n)) where n is the total
* number of tuples from child and m1 and m2 is the expected number of tuples
* from each part of the disjunction predicate.
* <p>
* Note we compute m1. m2.. by applying selectivity of the disjunctive element
* on the cardinality from child.
*
* @param call
* @return
*/
private Double computeDisjunctionSelectivity(RexCall call) {
Double tmpCardinality;
Double tmpSelectivity;
double selectivity = 1;
for (RexNode dje : call.getOperands()) {
tmpSelectivity = dje.accept(this);
if (tmpSelectivity == null) {
tmpSelectivity = 0.99;
}
tmpCardinality = childCardinality * tmpSelectivity;
if (tmpCardinality > 1 && tmpCardinality < childCardinality) {
tmpSelectivity = (1 - tmpCardinality / childCardinality);
} else {
tmpSelectivity = 1.0;
}
selectivity *= tmpSelectivity;
}
if (selectivity < 0.0)
selectivity = 0.0;
return (1 - selectivity);
}
use of org.apache.calcite.rex.RexNode in project hive by apache.
the class HiveFilterAggregateTransposeRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
final Filter filterRel = call.rel(0);
RexNode condition = filterRel.getCondition();
if (!HiveCalciteUtil.isDeterministic(condition)) {
return false;
}
return super.matches(call);
}
use of org.apache.calcite.rex.RexNode in project hive by apache.
the class HiveFilterJoinRule method validateJoinFilters.
/*
* Any predicates pushed down to joinFilters that aren't equality conditions:
* put them back as aboveFilters because Hive doesn't support not equi join
* conditions.
*/
@Override
protected void validateJoinFilters(List<RexNode> aboveFilters, List<RexNode> joinFilters, Join join, JoinRelType joinType) {
if (joinType.equals(JoinRelType.INNER)) {
ListIterator<RexNode> filterIter = joinFilters.listIterator();
while (filterIter.hasNext()) {
RexNode exp = filterIter.next();
if (exp instanceof RexCall) {
RexCall c = (RexCall) exp;
boolean validHiveJoinFilter = false;
if ((c.getOperator().getKind() == SqlKind.EQUALS)) {
validHiveJoinFilter = true;
for (RexNode rn : c.getOperands()) {
// (r1.x +r2.x)=(r1.y+r2.y) on join condition.
if (filterRefersToBothSidesOfJoin(rn, join)) {
validHiveJoinFilter = false;
break;
}
}
} else if ((c.getOperator().getKind() == SqlKind.LESS_THAN) || (c.getOperator().getKind() == SqlKind.GREATER_THAN) || (c.getOperator().getKind() == SqlKind.LESS_THAN_OR_EQUAL) || (c.getOperator().getKind() == SqlKind.GREATER_THAN_OR_EQUAL)) {
validHiveJoinFilter = true;
// r2.x) on join condition.
if (filterRefersToBothSidesOfJoin(c, join)) {
validHiveJoinFilter = false;
}
}
if (validHiveJoinFilter)
continue;
}
aboveFilters.add(exp);
filterIter.remove();
}
}
}
use of org.apache.calcite.rex.RexNode in project hive by apache.
the class HiveFilterProjectTransposeRule method onMatch.
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final Project origproject = call.rel(1);
RexNode filterCondToPushBelowProj = filter.getCondition();
RexNode unPushedFilCondAboveProj = null;
if (RexUtil.containsCorrelation(filterCondToPushBelowProj)) {
// Correlate from being de-correlated.
return;
}
if (RexOver.containsOver(origproject.getProjects(), null)) {
RexNode origFilterCond = filterCondToPushBelowProj;
filterCondToPushBelowProj = null;
if (pushThroughWindowing) {
Set<Integer> commonPartitionKeys = getCommonPartitionCols(origproject.getProjects());
List<RexNode> newPartKeyFilConds = new ArrayList<RexNode>();
List<RexNode> unpushedFilConds = new ArrayList<RexNode>();
// from t1 where value < 10)t1)t2
if (!commonPartitionKeys.isEmpty()) {
for (RexNode ce : RelOptUtil.conjunctions(origFilterCond)) {
RexNode newCondition = RelOptUtil.pushPastProject(ce, origproject);
if (HiveCalciteUtil.isDeterministicFuncWithSingleInputRef(newCondition, commonPartitionKeys)) {
newPartKeyFilConds.add(newCondition);
} else {
unpushedFilConds.add(ce);
}
}
if (!newPartKeyFilConds.isEmpty()) {
filterCondToPushBelowProj = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), newPartKeyFilConds, true);
}
if (!unpushedFilConds.isEmpty()) {
unPushedFilCondAboveProj = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), unpushedFilConds, true);
}
}
}
}
if (filterCondToPushBelowProj != null) {
RelNode newProjRel = getNewProject(filterCondToPushBelowProj, unPushedFilCondAboveProj, origproject, filter.getCluster().getTypeFactory(), call.builder());
call.transformTo(newProjRel);
}
}
use of org.apache.calcite.rex.RexNode in project hive by apache.
the class HiveFilterProjectTransposeRule method getNewProject.
private static RelNode getNewProject(RexNode filterCondToPushBelowProj, RexNode unPushedFilCondAboveProj, Project oldProj, RelDataTypeFactory typeFactory, RelBuilder relBuilder) {
// convert the filter to one that references the child of the project
RexNode newPushedCondition = RelOptUtil.pushPastProject(filterCondToPushBelowProj, oldProj);
// other rewrites.
if (RexUtil.isNullabilityCast(typeFactory, newPushedCondition)) {
newPushedCondition = ((RexCall) newPushedCondition).getOperands().get(0);
}
RelNode newPushedFilterRel = relBuilder.push(oldProj.getInput()).filter(newPushedCondition).build();
RelNode newProjRel = relBuilder.push(newPushedFilterRel).project(oldProj.getProjects(), oldProj.getRowType().getFieldNames()).build();
if (unPushedFilCondAboveProj != null) {
// other rewrites.
if (RexUtil.isNullabilityCast(typeFactory, newPushedCondition)) {
unPushedFilCondAboveProj = ((RexCall) unPushedFilCondAboveProj).getOperands().get(0);
}
newProjRel = relBuilder.push(newProjRel).filter(unPushedFilCondAboveProj).build();
}
return newProjRel;
}
Aggregations