use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class IntroduceTransactionCommitByAssignOpRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.SELECT) {
return false;
}
SelectOperator selectOperator = (SelectOperator) op;
Mutable<ILogicalOperator> childOfSelect = selectOperator.getInputs().get(0);
//[Direction] SelectOp(cond1)<--ChildOps... ==> SelectOp(booleanValue of cond1)<--NewAssignOp(cond1)<--ChildOps...
//#. Create an assign-operator with a new local variable and the condition of the select-operator.
//#. Set the input(child operator) of the new assign-operator to input(child operator) of the select-operator.
// (Later, the newly created assign-operator will apply the condition on behalf of the select-operator,
// and set the variable of the assign-operator to a boolean value according to the condition evaluation.)
//#. Give the select-operator the result boolean value created by the newly created child assign-operator.
//create an assignOp with a variable and the condition of the select-operator.
LogicalVariable v = context.newVar();
AssignOperator assignOperator = new AssignOperator(v, new MutableObject<ILogicalExpression>(selectOperator.getCondition().getValue()));
//set the input of the new assign-operator to the input of the select-operator.
assignOperator.getInputs().add(childOfSelect);
//set the result value of the assign-operator to the condition of the select-operator
//scalarFunctionCallExpression);
selectOperator.getCondition().setValue(new VariableReferenceExpression(v));
selectOperator.getInputs().set(0, new MutableObject<ILogicalOperator>(assignOperator));
context.computeAndSetTypeEnvironmentForOperator(assignOperator);
//Once this rule is fired, don't apply again.
context.addToDontApplySet(this, selectOperator);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class PushFieldAccessRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (context.checkIfInDontApplySet(this, op)) {
return false;
}
if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
return false;
}
AssignOperator access = (AssignOperator) op;
ILogicalExpression expr = getFirstExpr(access);
String finalAnnot;
if (AnalysisUtil.isAccessToFieldRecord(expr)) {
finalAnnot = OperatorAnnotation.PUSHED_FIELD_ACCESS;
} else if (AnalysisUtil.isRunnableAccessToFieldRecord(expr)) {
finalAnnot = OperatorAnnotation.PUSHED_RUNNABLE_FIELD_ACCESS;
} else {
return false;
}
return propagateFieldAccessRec(opRef, context, finalAnnot);
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class PushAggFuncIntoStandaloneAggregateRule method pushAggregateFunction.
private boolean pushAggregateFunction(AggregateOperator aggOp, AssignOperator assignOp, IOptimizationContext context) throws AlgebricksException {
Mutable<ILogicalOperator> opRef3 = aggOp.getInputs().get(0);
AbstractLogicalOperator op3 = (AbstractLogicalOperator) opRef3.getValue();
// If there's a group by below the agg, then we want to have the agg pushed into the group by.
if (op3.getOperatorTag() == LogicalOperatorTag.GROUP) {
return false;
}
if (aggOp.getVariables().size() != 1) {
return false;
}
ILogicalExpression aggExpr = aggOp.getExpressions().get(0).getValue();
if (aggExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression origAggFuncExpr = (AbstractFunctionCallExpression) aggExpr;
if (origAggFuncExpr.getFunctionIdentifier() != BuiltinFunctions.LISTIFY) {
return false;
}
LogicalVariable aggVar = aggOp.getVariables().get(0);
List<LogicalVariable> used = new LinkedList<LogicalVariable>();
VariableUtilities.getUsedVariables(assignOp, used);
if (!used.contains(aggVar)) {
return false;
}
List<Mutable<ILogicalExpression>> srcAssignExprRefs = new LinkedList<Mutable<ILogicalExpression>>();
if (fingAggFuncExprRef(assignOp.getExpressions(), aggVar, srcAssignExprRefs) == false) {
return false;
}
if (srcAssignExprRefs.isEmpty()) {
return false;
}
AbstractFunctionCallExpression aggOpExpr = (AbstractFunctionCallExpression) aggOp.getExpressions().get(0).getValue();
aggOp.getExpressions().clear();
aggOp.getVariables().clear();
for (Mutable<ILogicalExpression> srcAssignExprRef : srcAssignExprRefs) {
AbstractFunctionCallExpression assignFuncExpr = (AbstractFunctionCallExpression) srcAssignExprRef.getValue();
FunctionIdentifier aggFuncIdent = BuiltinFunctions.getAggregateFunction(assignFuncExpr.getFunctionIdentifier());
// Push the agg func into the agg op.
List<Mutable<ILogicalExpression>> aggArgs = new ArrayList<Mutable<ILogicalExpression>>();
aggArgs.add(aggOpExpr.getArguments().get(0));
AggregateFunctionCallExpression aggFuncExpr = BuiltinFunctions.makeAggregateFunctionExpression(aggFuncIdent, aggArgs);
LogicalVariable newVar = context.newVar();
aggOp.getVariables().add(newVar);
aggOp.getExpressions().add(new MutableObject<ILogicalExpression>(aggFuncExpr));
// The assign now just "renames" the variable to make sure the upstream plan still works.
srcAssignExprRef.setValue(new VariableReferenceExpression(newVar));
}
context.computeAndSetTypeEnvironmentForOperator(aggOp);
context.computeAndSetTypeEnvironmentForOperator(assignOp);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class PushAggFuncIntoStandaloneAggregateRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
// Pattern to match: assign <-- aggregate <-- !(group-by)
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
return false;
}
AssignOperator assignOp = (AssignOperator) op;
Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
if (op2.getOperatorTag() == LogicalOperatorTag.AGGREGATE) {
AggregateOperator aggOp = (AggregateOperator) op2;
// Make sure the agg expr is a listify.
return pushAggregateFunction(aggOp, assignOp, context);
} else if (op2.getOperatorTag() == LogicalOperatorTag.INNERJOIN || op2.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN) {
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op2;
// Tries to push aggregates through the join.
if (containsAggregate(assignOp.getExpressions()) && pushableThroughJoin(join)) {
pushAggregateFunctionThroughJoin(join, assignOp, context);
return true;
}
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator in project asterixdb by apache.
the class PushAggregateIntoNestedSubplanRule method collectOneVarPerAggFromOpWithNestedPlans.
private List<LogicalVariable> collectOneVarPerAggFromOpWithNestedPlans(AbstractOperatorWithNestedPlans op) {
List<ILogicalPlan> nPlans = op.getNestedPlans();
if (nPlans == null || nPlans.isEmpty()) {
return Collections.emptyList();
}
List<LogicalVariable> aggVars = new ArrayList<>();
// test that the operator computes a "listify" aggregate
for (int i = 0; i < nPlans.size(); i++) {
AbstractLogicalOperator topOp = (AbstractLogicalOperator) nPlans.get(i).getRoots().get(0).getValue();
if (topOp.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
continue;
}
AggregateOperator agg = (AggregateOperator) topOp;
if (agg.getVariables().size() != 1) {
continue;
}
ILogicalExpression expr = agg.getExpressions().get(0).getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
continue;
}
AbstractFunctionCallExpression fceAgg = (AbstractFunctionCallExpression) expr;
if (fceAgg.getFunctionIdentifier() != BuiltinFunctions.LISTIFY) {
continue;
}
aggVars.add(agg.getVariables().get(0));
}
return aggVars;
}
Aggregations