/*** * @param context * the optimization context * @param subplanInputOperator * the input operator to the target SubplanOperator * @param nts * the NestedTupleSourceOperator to be replaced by <code>subplanInputOperator</code> * @throws AlgebricksException */ public InlineLeftNtsInSubplanJoinFlatteningVisitor(IOptimizationContext context, ILogicalOperator subplanInputOperator, ILogicalOperator nts) throws AlgebricksException { this.context = context; this.subplanInputOperator = subplanInputOperator; this.targetNts = nts; VariableUtilities.getSubplanLocalLiveVariables(subplanInputOperator, liveVarsFromSubplanInput); }
@Override public Void visitGroupByOperator(GroupByOperator op, IOptimizationContext ctx) throws AlgebricksException { List<LogicalVariable> header = new ArrayList<>(); for (Pair<LogicalVariable, Mutable<ILogicalExpression>> gbyTerm : op.getGroupByList()) { header.add(gbyTerm.first); } List<LogicalVariable> liveVars = new ArrayList<>(); VariableUtilities.getSubplanLocalLiveVariables(op, liveVars); ctx.addPrimaryKey(new FunctionalDependency(header, liveVars)); return null; }
@Override public Void visitSubplanOperator(SubplanOperator op, Void arg) throws AlgebricksException { Set<LogicalVariable> producedVars = new HashSet<>(); Set<LogicalVariable> liveVars = new HashSet<>(); for (ILogicalPlan p : op.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { VariableUtilities.getProducedVariablesInDescendantsAndSelf(r.getValue(), producedVars); VariableUtilities.getSubplanLocalLiveVariables(r.getValue(), liveVars); } } producedVars.retainAll(liveVars); producedVariables.addAll(producedVars); return null; }
private static boolean pushNeededProjections(Set<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef, IOptimizationContext context, ILogicalOperator initialOp) throws AlgebricksException { Set<LogicalVariable> allP = new LinkedHashSet<LogicalVariable>(); AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); VariableUtilities.getSubplanLocalLiveVariables(op, allP); Set<LogicalVariable> toProject = new LinkedHashSet<LogicalVariable>(); for (LogicalVariable v : toPush) { if (allP.contains(v)) { toProject.add(v); } } if (toProject.equals(allP)) { // projection would be redundant, since we would project everything // but we can try with the children boolean push = false; if (pushThroughOp(toProject, opRef, initialOp, context).first) { push = true; } return push; } else { return pushAllProjectionsOnTopOf(toProject, opRef, context, initialOp); } }
VariableUtilities.getSubplanLocalLiveVariables(operator, liveVars);
private static ScalarFunctionCallExpression getNestedIsMissingCall(AbstractFunctionCallExpression call, OptimizableOperatorSubTree rightSubTree) throws AlgebricksException { ScalarFunctionCallExpression isMissingFuncExpr; if (call.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.NOT)) { if (call.getArguments().get(0).getValue().getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { if (((AbstractFunctionCallExpression) call.getArguments().get(0).getValue()).getFunctionIdentifier() .equals(AlgebricksBuiltinFunctions.IS_MISSING)) { isMissingFuncExpr = (ScalarFunctionCallExpression) call.getArguments().get(0).getValue(); if (isMissingFuncExpr.getArguments().get(0).getValue() .getExpressionTag() == LogicalExpressionTag.VARIABLE) { LogicalVariable var = ((VariableReferenceExpression) isMissingFuncExpr.getArguments().get(0).getValue()) .getVariableReference(); List<LogicalVariable> liveSubplanVars = new ArrayList<>(); VariableUtilities.getSubplanLocalLiveVariables(rightSubTree.getRoot(), liveSubplanVars); if (liveSubplanVars.contains(var)) { return isMissingFuncExpr; } } } } } return null; }
VariableUtilities.getSubplanLocalLiveVariables(op.getInputs().get(0).getValue(), inputLiveVars);