use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class InlineAllNtsInSubplanVisitor method visitGroupByOperator.
@Override
public ILogicalOperator visitGroupByOperator(GroupByOperator op, Void arg) throws AlgebricksException {
visitSingleInputOperator(op);
Set<LogicalVariable> groupKeyVars = new HashSet<>();
// VariableReferenceExpressions.
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> keyVarExprRef : op.getGroupByList()) {
ILogicalExpression expr = keyVarExprRef.second.getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
VariableReferenceExpression varExpr = (VariableReferenceExpression) expr;
LogicalVariable sourceVar = varExpr.getVariableReference();
updateInputToOutputVarMapping(sourceVar, keyVarExprRef.first, false);
groupKeyVars.add(keyVarExprRef.first);
}
}
// Add correlated key variables into group-by keys.
Map<LogicalVariable, LogicalVariable> addedGroupKeyMapping = new HashMap<>();
for (LogicalVariable keyVar : correlatedKeyVars) {
if (!groupKeyVars.contains(keyVar)) {
LogicalVariable newVar = context.newVar();
op.getGroupByList().add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(newVar, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(keyVar))));
addedGroupKeyMapping.put(keyVar, newVar);
}
}
// Updates decor list.
Iterator<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorExprIter = op.getDecorList().iterator();
while (decorExprIter.hasNext()) {
ILogicalExpression expr = decorExprIter.next().second.getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
VariableReferenceExpression varExpr = (VariableReferenceExpression) expr;
if (correlatedKeyVars.contains(varExpr.getVariableReference())) {
decorExprIter.remove();
}
}
}
// Updates the var mapping for added group-by keys.
for (Map.Entry<LogicalVariable, LogicalVariable> entry : addedGroupKeyMapping.entrySet()) {
updateInputToOutputVarMapping(entry.getKey(), entry.getValue(), false);
}
return op;
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class InlineAllNtsInSubplanVisitor method visitAggregateOperator.
/**
* Wraps an AggregateOperator or RunningAggregateOperator with a group-by
* operator where the group-by keys are variables in keyVarsToEnforce. Note
* that the function here prevents this visitor being used to rewrite
* arbitrary query plans. Instead, it could only be used for rewriting a
* nested plan within a subplan operator.
*
* @param op
* the logical operator for aggregate or running aggregate.
* @return the wrapped group-by operator if {@code keyVarsToEnforce} is not
* empty, and {@code op} otherwise.
* @throws AlgebricksException
*/
private ILogicalOperator visitAggregateOperator(ILogicalOperator op) throws AlgebricksException {
visitSingleInputOperator(op);
if (correlatedKeyVars.isEmpty()) {
return op;
}
GroupByOperator gbyOp = new GroupByOperator();
// Creates a copy of correlatedKeyVars, to fix the ConcurrentModificationExcetpion in ASTERIXDB-1581.
List<LogicalVariable> copyOfCorrelatedKeyVars = new ArrayList<>(correlatedKeyVars);
for (LogicalVariable keyVar : copyOfCorrelatedKeyVars) {
// This limits the visitor can only be applied to a nested logical
// plan inside a Subplan operator,
// where the keyVarsToEnforce forms a candidate key which can
// uniquely identify a tuple out of the nested-tuple-source.
LogicalVariable newVar = context.newVar();
gbyOp.getGroupByList().add(new Pair<>(newVar, new MutableObject<>(new VariableReferenceExpression(keyVar))));
updateInputToOutputVarMapping(keyVar, newVar, false);
}
ILogicalOperator inputOp = op.getInputs().get(0).getValue();
gbyOp.getInputs().add(new MutableObject<>(inputOp));
NestedTupleSourceOperator nts = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(gbyOp));
op.getInputs().clear();
op.getInputs().add(new MutableObject<>(nts));
ILogicalPlan nestedPlan = new ALogicalPlanImpl();
nestedPlan.getRoots().add(new MutableObject<>(op));
gbyOp.getNestedPlans().add(nestedPlan);
OperatorManipulationUtil.computeTypeEnvironmentBottomUp(gbyOp, context);
return op;
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class InlineAllNtsInSubplanVisitor method createUnnestForAggregatedList.
private Pair<ILogicalOperator, LogicalVariable> createUnnestForAggregatedList(LogicalVariable aggVar) {
LogicalVariable unnestVar = context.newVar();
// Creates an unnest function expression.
Mutable<ILogicalExpression> unnestArg = new MutableObject<ILogicalExpression>(new VariableReferenceExpression(aggVar));
List<Mutable<ILogicalExpression>> unnestArgList = new ArrayList<Mutable<ILogicalExpression>>();
unnestArgList.add(unnestArg);
Mutable<ILogicalExpression> unnestExpr = new MutableObject<ILogicalExpression>(new UnnestingFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), unnestArgList));
ILogicalOperator unnestOp = new UnnestOperator(unnestVar, unnestExpr);
return new Pair<ILogicalOperator, LogicalVariable>(unnestOp, unnestVar);
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class InlineAllNtsInSubplanVisitor method createRecordConstructorAssignOp.
private Pair<ILogicalOperator, LogicalVariable> createRecordConstructorAssignOp(Set<LogicalVariable> inputLiveVars) {
// Creates a nested record.
List<Mutable<ILogicalExpression>> recordConstructorArgs = new ArrayList<>();
for (LogicalVariable inputLiveVar : inputLiveVars) {
if (!correlatedKeyVars.contains(inputLiveVar)) {
recordConstructorArgs.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(new AString(Integer.toString(inputLiveVar.getId()))))));
recordConstructorArgs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(inputLiveVar)));
}
}
LogicalVariable recordVar = context.newVar();
Mutable<ILogicalExpression> recordExprRef = new MutableObject<ILogicalExpression>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR), recordConstructorArgs));
AssignOperator assignOp = new AssignOperator(recordVar, recordExprRef);
return new Pair<ILogicalOperator, LogicalVariable>(assignOp, recordVar);
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.
the class InlineLeftNtsInSubplanJoinFlatteningVisitor method visitOrderOperator.
@Override
public ILogicalOperator visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException {
boolean underJoin = hasJoinAncestor;
visitSingleInputOperator(op);
if (!rewritten || !underJoin) {
return op;
}
// Adjust the ordering if its input operator pipeline has been rewritten.
List<Pair<IOrder, Mutable<ILogicalExpression>>> orderExprList = new ArrayList<>();
// Adds keyVars to the prefix of sorting columns.
for (LogicalVariable liveVar : liveVarsFromSubplanInput) {
orderExprList.add(new Pair<IOrder, Mutable<ILogicalExpression>>(OrderOperator.ASC_ORDER, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(liveVar))));
}
orderExprList.addAll(op.getOrderExpressions());
// Creates an order operator with the new expression list.
OrderOperator orderOp = new OrderOperator(orderExprList);
orderOp.getInputs().addAll(op.getInputs());
context.computeAndSetTypeEnvironmentForOperator(orderOp);
return orderOp;
}
Aggregations