protected List<List<AlgebricksPipeline>> compileSubplansImpl(IOperatorSchema outerPlanSchema, AbstractOperatorWithNestedPlans npOp, IOperatorSchema opSchema, JobGenContext context) throws AlgebricksException { List<List<AlgebricksPipeline>> subplans = new ArrayList<>(npOp.getNestedPlans().size()); PlanCompiler pc = new PlanCompiler(context); for (ILogicalPlan p : npOp.getNestedPlans()) { subplans.add(buildPipelineWithProjection(p, outerPlanSchema, npOp, opSchema, pc)); } return subplans; }
private void mapVariablesInNestedPlans(AbstractOperatorWithNestedPlans op, ILogicalOperator arg) throws AlgebricksException { if (op.getOperatorTag() != arg.getOperatorTag()) { return; } AbstractOperatorWithNestedPlans argOp = (AbstractOperatorWithNestedPlans) arg; List<ILogicalPlan> plans = op.getNestedPlans(); List<ILogicalPlan> plansArg = argOp.getNestedPlans(); if (plans.size() != plansArg.size()) { return; } for (int i = 0; i < plans.size(); i++) { List<Mutable<ILogicalOperator>> roots = plans.get(i).getRoots(); List<Mutable<ILogicalOperator>> rootsArg = plansArg.get(i).getRoots(); if (roots.size() != rootsArg.size()) { return; } for (int j = 0; j < roots.size(); j++) { ILogicalOperator topOp1 = roots.get(j).getValue(); ILogicalOperator topOp2 = rootsArg.get(j).getValue(); topOp1.accept(this, topOp2); } } }
private boolean inlineOuterInputAssignIntoAgg(AggregateOperator aggOp, AbstractOperatorWithNestedPlans opWithNestedPlans) throws AlgebricksException { AbstractLogicalOperator op2 = (AbstractLogicalOperator) opWithNestedPlans.getInputs().get(0).getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; } AssignOperator assignOp = (AssignOperator) op2; VarExprSubstitution ves = new VarExprSubstitution(assignOp.getVariables(), assignOp.getExpressions()); return inlineVariables(aggOp, ves); }
ILogicalOperator subplanInput = subplan.getInputs().get(0).getValue(); AbstractLogicalOperator subplanInputOp = (AbstractLogicalOperator) subplanInput; List<ILogicalPlan> nestedPlans = subplan.getNestedPlans(); List<Mutable<ILogicalOperator>> nestedRoots = new ArrayList<Mutable<ILogicalOperator>>(); for (ILogicalPlan nestedPlan : nestedPlans) { SourceLocation sourceLoc = subplan.getSourceLocation();
private boolean inlined(ILogicalOperator planRootOp, AbstractOperatorWithNestedPlans opWithNestedPlan) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) planRootOp; if (op1.getOperatorTag() != LogicalOperatorTag.AGGREGATE) { return false; } AggregateOperator aggOp = (AggregateOperator) op1; boolean inlined = inlineInputAssignIntoAgg(aggOp); if (opWithNestedPlan.getOperatorTag() == LogicalOperatorTag.WINDOW) { inlined |= inlineOuterInputAssignIntoAgg(aggOp, opWithNestedPlan); } return inlined; }
@Override public void recomputeSchema() { super.recomputeSchema(); schema.addAll(variables); }
opWithNestedPlans.getUsedVariablesExceptNestedPlans(targetUsedVars); } else { VariableUtilities.getUsedVariables(op, targetUsedVars);
@Override public void recomputeSchema() { super.recomputeSchema(); for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gByList) { schema.add(p.first); } for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : decorList) { schema.add(getDecorVariable(p)); } }
private void typeGby(AbstractOperatorWithNestedPlans op, IOptimizationContext context) throws AlgebricksException { for (ILogicalPlan p : op.getNestedPlans()) { OperatorPropertiesUtil.typePlan(p, context); } context.computeAndSetTypeEnvironmentForOperator(op); }
if (occurs == 0) { AbstractOperatorWithNestedPlans nspOp = nspWithAgg.get(aggVar); AggregateOperator aggOp = (AggregateOperator) nspOp.getNestedPlans() .get(nspAggVarToPlanIndex.get(aggVar)).getRoots().get(0).getValue(); int pos = aggOp.getVariables().indexOf(aggVar); for (Pair<AbstractOperatorWithNestedPlans, Integer> remove : removeList) { AbstractOperatorWithNestedPlans groupByOperator = remove.first; ILogicalPlan subplan = remove.first.getNestedPlans().get(remove.second); if (nspToSubplanListMap.containsKey(groupByOperator)) { List<ILogicalPlan> subplans = nspToSubplanListMap.get(groupByOperator); nspToSubplanListMap.forEach((key, value) -> key.getNestedPlans().removeAll(value));
private void visitNestedPlans(AbstractOperatorWithNestedPlans op) throws AlgebricksException { for (ILogicalPlan p : op.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { VariableUtilities.getUsedVariablesInDescendantsAndSelf(r.getValue(), usedVariables); } } } }
private void substInNestedPlans(LogicalVariable v1, LogicalVariable v2, AbstractOperatorWithNestedPlans op) throws AlgebricksException { for (ILogicalPlan p : op.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { VariableUtilities.substituteVariablesInDescendantsAndSelf(r.getValue(), v1, v2, ctx); } } }
public static void getFreeVariablesInSubplans(AbstractOperatorWithNestedPlans op, Set<LogicalVariable> freeVars) throws AlgebricksException { for (ILogicalPlan p : op.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) r.getValue(), freeVars); } } }
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; }
protected void printNestedPlans(AbstractOperatorWithNestedPlans op, Integer indent) throws AlgebricksException { boolean first = true; if (op.getNestedPlans().isEmpty()) { buffer.append("}"); } else { for (ILogicalPlan p : op.getNestedPlans()) { // PrettyPrintUtil.indent(buffer, level + 10).append("var " + // p.first + ":\n"); buffer.append("\n"); if (first) { first = false; } else { addIndent(indent).append(" {\n"); } printPlan(p, indent + 10); addIndent(indent).append(" }"); } } }
Iterator<ILogicalPlan> planIter = opWithNest.getNestedPlans().iterator(); while (planIter.hasNext()) { ILogicalPlan p = planIter.next(); for (int i = opWithNest.getNestedPlans().size() - 1; i >= 0; i--) { ILogicalPlan nestedPlan = opWithNest.getNestedPlans().get(i); List<Mutable<ILogicalOperator>> rootsToBeRemoved = new ArrayList<Mutable<ILogicalOperator>>(); for (Mutable<ILogicalOperator> r : nestedPlan.getRoots()) { if (nestedPlan.getRoots().size() == rootsToBeRemoved.size() && opWithNest.getNestedPlans().size() > 1) { nestedPlan.getRoots().removeAll(rootsToBeRemoved); opWithNest.getNestedPlans().remove(nestedPlan);
AbstractLogicalOperator lastOperator = (AbstractLogicalOperator) operatorWithNestedPlan.getNestedPlans() .get(0).getRoots().get(0).getValue(); cardinalityVariable = vxqueryContext.getCardinalityOperatorMap(lastOperator);
private void rewriteAggregateInNestedSubplan(LogicalVariable oldAggVar, AbstractOperatorWithNestedPlans nspOp, AggregateFunctionCallExpression aggFun, LogicalVariable newAggVar, IOptimizationContext context) throws AlgebricksException { for (int j = 0; j < nspOp.getNestedPlans().size(); j++) { AggregateOperator aggOp = (AggregateOperator) nspOp.getNestedPlans().get(j).getRoots().get(0).getValue(); int n = aggOp.getVariables().size(); for (int i = 0; i < n; i++) { LogicalVariable v = aggOp.getVariables().get(i); if (v.equals(oldAggVar)) { AbstractFunctionCallExpression oldAggExpr = (AbstractFunctionCallExpression) aggOp.getExpressions().get(i).getValue(); AggregateFunctionCallExpression newAggFun = BuiltinFunctions .makeAggregateFunctionExpression(aggFun.getFunctionIdentifier(), new ArrayList<>()); newAggFun.setSourceLocation(oldAggExpr.getSourceLocation()); for (Mutable<ILogicalExpression> arg : oldAggExpr.getArguments()) { ILogicalExpression cloned = arg.getValue().cloneExpression(); newAggFun.getArguments().add(new MutableObject<>(cloned)); } aggOp.getVariables().add(newAggVar); aggOp.getExpressions().add(new MutableObject<>(newAggFun)); context.computeAndSetTypeEnvironmentForOperator(aggOp); break; } } } }
for (ILogicalPlan plan : opWithNested.getNestedPlans()) { for (Mutable<ILogicalOperator> r : plan.getRoots()) { collectUnusedAssignedVars(r, new HashSet<LogicalVariable>(accumulatedUsedVarFromRootSet), false,
private static void computeSchemaBottomUpForOp(AbstractLogicalOperator op) throws AlgebricksException { for (Mutable<ILogicalOperator> i : op.getInputs()) { computeSchemaBottomUpForOp((AbstractLogicalOperator) i.getValue()); } if (op.hasNestedPlans()) { AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op; for (ILogicalPlan p : a.getNestedPlans()) { computeSchemaBottomUpForPlan(p); } } op.recomputeSchema(); }