use of org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class PushSelectIntoJoinRule method copySelectToBranch.
private static void copySelectToBranch(SelectOperator select, Mutable<ILogicalOperator> branch, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator newSelect = new SelectOperator(select.getCondition(), select.getRetainMissing(), select.getMissingPlaceholderVariable());
Mutable<ILogicalOperator> newRef = new MutableObject<ILogicalOperator>(branch.getValue());
newSelect.getInputs().add(newRef);
branch.setValue(newSelect);
context.computeAndSetTypeEnvironmentForOperator(newSelect);
}
use of org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class PushSelectIntoJoinRule method pushOps.
private void pushOps(List<ILogicalOperator> opList, Mutable<ILogicalOperator> joinBranch, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator topOp = joinBranch.getValue();
ListIterator<ILogicalOperator> iter = opList.listIterator(opList.size());
while (iter.hasPrevious()) {
ILogicalOperator op = iter.previous();
List<Mutable<ILogicalOperator>> opInpList = op.getInputs();
opInpList.clear();
opInpList.add(new MutableObject<ILogicalOperator>(topOp));
topOp = op;
context.computeAndSetTypeEnvironmentForOperator(op);
}
joinBranch.setValue(topOp);
}
use of org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class PushGroupByIntoSortRule method generateMergeAggregationExpressions.
private boolean generateMergeAggregationExpressions(GroupByOperator gby, IOptimizationContext context) throws AlgebricksException {
if (gby.getNestedPlans().size() != 1) {
throw new AlgebricksException("External/sort group-by currently works only for one nested plan with one root containing" + "an aggregate and a nested-tuple-source.");
}
ILogicalPlan p0 = gby.getNestedPlans().get(0);
if (p0.getRoots().size() != 1) {
throw new AlgebricksException("External/sort group-by currently works only for one nested plan with one root containing" + "an aggregate and a nested-tuple-source.");
}
IMergeAggregationExpressionFactory mergeAggregationExpressionFactory = context.getMergeAggregationExpressionFactory();
Mutable<ILogicalOperator> r0 = p0.getRoots().get(0);
AggregateOperator aggOp = (AggregateOperator) r0.getValue();
List<Mutable<ILogicalExpression>> aggFuncRefs = aggOp.getExpressions();
List<LogicalVariable> originalAggVars = aggOp.getVariables();
int n = aggOp.getExpressions().size();
List<Mutable<ILogicalExpression>> mergeExpressionRefs = new ArrayList<Mutable<ILogicalExpression>>();
for (int i = 0; i < n; i++) {
ILogicalExpression mergeExpr = mergeAggregationExpressionFactory.createMergeAggregation(originalAggVars.get(i), aggFuncRefs.get(i).getValue(), context);
if (mergeExpr == null) {
return false;
}
mergeExpressionRefs.add(new MutableObject<ILogicalExpression>(mergeExpr));
}
aggOp.setMergeExpressions(mergeExpressionRefs);
return true;
}
use of org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class EliminateSubplanRule method elimSubplanOverEts.
private void elimSubplanOverEts(Mutable<ILogicalOperator> opRef, IOptimizationContext ctx) throws AlgebricksException {
SubplanOperator subplan = (SubplanOperator) opRef.getValue();
for (ILogicalPlan p : subplan.getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
OperatorManipulationUtil.ntsToEts(r, ctx);
}
}
LinkedList<Mutable<ILogicalOperator>> allRoots = subplan.allRootsInReverseOrder();
if (allRoots.size() == 1) {
opRef.setValue(allRoots.get(0).getValue());
} else {
ILogicalOperator topOp = null;
for (Mutable<ILogicalOperator> r : allRoots) {
if (topOp == null) {
topOp = r.getValue();
} else {
InnerJoinOperator j = new InnerJoinOperator(new MutableObject<ILogicalExpression>(ConstantExpression.TRUE));
j.getInputs().add(new MutableObject<ILogicalOperator>(topOp));
j.getInputs().add(r);
ctx.setOutputTypeEnvironment(j, j.computeOutputTypeEnvironment(ctx));
topOp = j;
}
}
opRef.setValue(topOp);
}
}
use of org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class ListifyUnnestingFunctionRule method listifyUnnestingFunction.
// Performs the actual logical transformation.
private boolean listifyUnnestingFunction(ILogicalOperator op, Mutable<ILogicalExpression> exprRef, AbstractFunctionCallExpression func, IOptimizationContext context) throws AlgebricksException {
IFunctionInfo functionInfo = func.getFunctionInfo();
// Checks if the function is an unnesting function.
if (!BuiltinFunctions.isBuiltinUnnestingFunction(functionInfo.getFunctionIdentifier())) {
return false;
}
// Generates the listified collection in a subplan.
SubplanOperator subplanOperator = new SubplanOperator();
// Creates a nested tuple source operator.
NestedTupleSourceOperator ntsOperator = new NestedTupleSourceOperator(new MutableObject<>(subplanOperator));
// Unnests the dataset.
LogicalVariable unnestVar = context.newVar();
ILogicalExpression unnestExpr = new UnnestingFunctionCallExpression(functionInfo, func.getArguments());
UnnestOperator unnestOperator = new UnnestOperator(unnestVar, new MutableObject<>(unnestExpr));
unnestOperator.getInputs().add(new MutableObject<>(ntsOperator));
// Listify the dataset into one collection.
LogicalVariable aggVar = context.newVar();
Mutable<ILogicalExpression> aggArgExprRef = new MutableObject<>(new VariableReferenceExpression(unnestVar));
ILogicalExpression aggExpr = new AggregateFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.LISTIFY), false, new ArrayList<>(Collections.singletonList(aggArgExprRef)));
AggregateOperator aggregateOperator = new AggregateOperator(new ArrayList<>(Collections.singletonList(aggVar)), new ArrayList<>(Collections.singletonList(new MutableObject<>(aggExpr))));
aggregateOperator.getInputs().add(new MutableObject<>(unnestOperator));
// Adds the aggregate operator as the root of the subplan.
subplanOperator.setRootOp(new MutableObject<>(aggregateOperator));
// Sticks a subplan operator into the query plan.
// Note: given the way we compile JOINs, the unnesting function expression cannot appear in
// any binary operators.
// Example test queries:
// asterixdb/asterix-app/src/test/resources/runtimets/results/list/query-ASTERIXDB-159-2
// asterixdb/asterix-app/src/test/resources/runtimets/results/list/query-ASTERIXDB-159-3
subplanOperator.getInputs().add(op.getInputs().get(0));
op.getInputs().set(0, new MutableObject<>(subplanOperator));
exprRef.setValue(new VariableReferenceExpression(aggVar));
// Computes type environments for new operators.
context.computeAndSetTypeEnvironmentForOperator(ntsOperator);
context.computeAndSetTypeEnvironmentForOperator(unnestOperator);
context.computeAndSetTypeEnvironmentForOperator(aggregateOperator);
context.computeAndSetTypeEnvironmentForOperator(subplanOperator);
return true;
}
Aggregations