use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator in project asterixdb by apache.
the class PushUnnestDownThroughProductRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.UNNEST) {
return false;
}
Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();
if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
return false;
}
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op2;
if (join.getCondition().getValue() != ConstantExpression.TRUE) {
return false;
}
List<LogicalVariable> used = new ArrayList<LogicalVariable>();
VariableUtilities.getUsedVariables(op1, used);
Mutable<ILogicalOperator> b0Ref = op2.getInputs().get(0);
ILogicalOperator b0 = b0Ref.getValue();
List<LogicalVariable> b0Scm = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(b0, b0Scm);
if (b0Scm.containsAll(used)) {
// push unnest on left branch
op2Ref.setValue(b0);
b0Ref.setValue(op1);
opRef.setValue(op2);
return true;
} else {
Mutable<ILogicalOperator> b1Ref = op2.getInputs().get(1);
ILogicalOperator b1 = b1Ref.getValue();
List<LogicalVariable> b1Scm = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(b1, b1Scm);
if (b1Scm.containsAll(used)) {
// push unnest on right branch
op2Ref.setValue(b1);
b1Ref.setValue(op1);
opRef.setValue(op2);
return true;
} else {
return false;
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator in project asterixdb by apache.
the class RemoveCartesianProductWithEmptyBranchRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator op = opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN && op.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
return false;
}
AbstractBinaryJoinOperator joinOperator = (AbstractBinaryJoinOperator) op;
ILogicalOperator left = joinOperator.getInputs().get(0).getValue();
ILogicalOperator right = joinOperator.getInputs().get(1).getValue();
if (!joinOperator.getCondition().getValue().equals(ConstantExpression.TRUE)) {
return false;
}
if (emptyBranch(left)) {
opRef.setValue(right);
return true;
}
if (emptyBranch(right)) {
opRef.setValue(left);
return true;
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator in project asterixdb by apache.
the class PushGroupByThroughProduct method push.
private void push(Mutable<ILogicalOperator> opRefGby, Mutable<ILogicalOperator> opRefJoin, int branch, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorToPush, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorNotToPush, IOptimizationContext context) throws AlgebricksException {
GroupByOperator gby = (GroupByOperator) opRefGby.getValue();
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) opRefJoin.getValue();
gby.getDecorList().clear();
gby.getDecorList().addAll(decorToPush);
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : decorNotToPush) {
LogicalVariable v1 = p.first;
if (v1 != null) {
VariableReferenceExpression varRef = (VariableReferenceExpression) p.second.getValue();
LogicalVariable v2 = varRef.getVariableReference();
OperatorManipulationUtil.substituteVarRec(join, v2, v1, true, context);
}
}
Mutable<ILogicalOperator> branchRef = join.getInputs().get(branch);
ILogicalOperator opBranch = branchRef.getValue();
opRefJoin.setValue(opBranch);
branchRef.setValue(gby);
opRefGby.setValue(join);
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator in project asterixdb by apache.
the class PushAggFuncIntoStandaloneAggregateRule method pushAggregateFunctionThroughJoin.
/**
* Does the actual push of aggregates for qualified joins.
*
* @param join
* @param assignOp
* that contains aggregate function calls.
* @param context
* @throws AlgebricksException
*/
private void pushAggregateFunctionThroughJoin(AbstractBinaryJoinOperator join, AssignOperator assignOp, IOptimizationContext context) throws AlgebricksException {
for (Mutable<ILogicalOperator> branchRef : join.getInputs()) {
AbstractLogicalOperator branch = (AbstractLogicalOperator) branchRef.getValue();
if (branch.getOperatorTag() == LogicalOperatorTag.AGGREGATE) {
AggregateOperator aggOp = (AggregateOperator) branch;
pushAggregateFunction(aggOp, assignOp, context);
} else if (branch.getOperatorTag() == LogicalOperatorTag.INNERJOIN || branch.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN) {
AbstractBinaryJoinOperator childJoin = (AbstractBinaryJoinOperator) branch;
pushAggregateFunctionThroughJoin(childJoin, assignOp, context);
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator in project asterixdb by apache.
the class PushProperJoinThroughProduct method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
LogicalOperatorTag tag1 = op.getOperatorTag();
if (tag1 != LogicalOperatorTag.INNERJOIN && tag1 != LogicalOperatorTag.LEFTOUTERJOIN) {
return false;
}
AbstractBinaryJoinOperator join1 = (AbstractBinaryJoinOperator) op;
ILogicalExpression cond1 = join1.getCondition().getValue();
// don't try to push a product down
if (OperatorPropertiesUtil.isAlwaysTrueCond(cond1)) {
return false;
}
Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
while (op2.isMap()) {
opRef2 = op2.getInputs().get(0);
op2 = (AbstractLogicalOperator) opRef2.getValue();
}
if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
return false;
}
InnerJoinOperator product = (InnerJoinOperator) op2;
if (!OperatorPropertiesUtil.isAlwaysTrueCond(product.getCondition().getValue())) {
return false;
}
usedInCond1AndMaps.clear();
cond1.getUsedVariables(usedInCond1AndMaps);
Mutable<ILogicalOperator> opIterRef = op.getInputs().get(0);
ILogicalOperator opIter = opIterRef.getValue();
do {
VariableUtilities.getUsedVariables(opIter, usedInCond1AndMaps);
opIterRef = opIter.getInputs().get(0);
opIter = opIterRef.getValue();
} while (opIter.isMap());
productLeftBranchVars.clear();
ILogicalOperator opLeft = op2.getInputs().get(0).getValue();
VariableUtilities.getLiveVariables(opLeft, productLeftBranchVars);
if (!OperatorPropertiesUtil.disjoint(usedInCond1AndMaps, productLeftBranchVars)) {
return false;
}
// now push the operators from in between joins, too
opIterRef = op.getInputs().get(0);
opIter = opIterRef.getValue();
Mutable<ILogicalOperator> op3Ref = product.getInputs().get(1);
ILogicalOperator op3 = op3Ref.getValue();
opRef2.setValue(op3);
op3Ref.setValue(join1);
opRef.setValue(product);
return true;
}
Aggregations