use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class PushAssignDownThroughProductRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
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 assign 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 assign 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.AbstractLogicalOperator in project asterixdb by apache.
the class PushFunctionsBelowJoin method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
return false;
}
AssignOperator assignOp = (AssignOperator) op;
// Find a join operator below this assign.
Mutable<ILogicalOperator> joinOpRef = findJoinOp(assignOp.getInputs().get(0));
if (joinOpRef == null) {
return false;
}
AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) joinOpRef.getValue();
// Check if the assign uses a function that we wish to push below the join if possible.
funcExprs.clear();
gatherFunctionCalls(assignOp, funcExprs);
if (funcExprs.isEmpty()) {
return false;
}
// Try to push the functions down the input branches of the join.
boolean modified = false;
if (pushDownFunctions(joinOp, 0, funcExprs, context)) {
modified = true;
}
if (pushDownFunctions(joinOp, 1, funcExprs, context)) {
modified = true;
}
if (modified) {
context.computeAndSetTypeEnvironmentForOperator(joinOp);
}
return modified;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class IsolateHyracksOperatorsRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
IPhysicalOperator pt = op.getPhysicalOperator();
if (pt == null || op.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
return false;
}
if (!pt.isMicroOperator()) {
return testIfExchangeBelow(opRef, context);
} else {
return testIfExchangeAbove(opRef, context);
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class IsolateHyracksOperatorsRule method disableJobGenRec.
private void disableJobGenRec(ILogicalOperator operator) {
AbstractLogicalOperator op = (AbstractLogicalOperator) operator;
op.disableJobGen();
for (Mutable<ILogicalOperator> i : op.getInputs()) {
disableJobGenRec(i.getValue());
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class PullSelectOutOfEqJoin method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
return false;
}
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op;
ILogicalExpression expr = join.getCondition().getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) expr;
FunctionIdentifier fi = fexp.getFunctionIdentifier();
if (!fi.equals(AlgebricksBuiltinFunctions.AND)) {
return false;
}
List<Mutable<ILogicalExpression>> eqVarVarComps = new ArrayList<Mutable<ILogicalExpression>>();
List<Mutable<ILogicalExpression>> otherPredicates = new ArrayList<Mutable<ILogicalExpression>>();
for (Mutable<ILogicalExpression> arg : fexp.getArguments()) {
if (isEqVarVar(arg.getValue())) {
eqVarVarComps.add(arg);
} else {
otherPredicates.add(arg);
}
}
if (eqVarVarComps.isEmpty() || otherPredicates.isEmpty()) {
return false;
}
// pull up
ILogicalExpression pulledCond = makeCondition(otherPredicates, context);
SelectOperator select = new SelectOperator(new MutableObject<ILogicalExpression>(pulledCond), false, null);
ILogicalExpression newJoinCond = makeCondition(eqVarVarComps, context);
join.getCondition().setValue(newJoinCond);
select.getInputs().add(new MutableObject<ILogicalOperator>(join));
opRef.setValue(select);
context.computeAndSetTypeEnvironmentForOperator(select);
return true;
}
Aggregations