private void setAsFinal(ILogicalOperator access, IOptimizationContext context, String finalAnnot) { access.getAnnotations().put(finalAnnot, true); context.addToDontApplySet(this, access); }
/** * Check the correctness of the parameters of the ftcontains(). Also rearrange options as arguments. * The expected form of ftcontains() is ftcontains(expression1, expression2, parameters as a record). */ private boolean checkParameter(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); boolean modified = op.acceptExpressionTransform(ftcontainsExprVisitor); if (modified) { context.addToDontApplySet(this, op); } return modified; }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (context.checkIfInDontApplySet(this, op)) { return false; } computeDefaultPhysicalOp(op, true, context); context.addToDontApplySet(this, op); return true; }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (context.checkIfInDontApplySet(this, opRef.getValue())) { return false; } VXQueryOptimizationContext vxqueryContext = (VXQueryOptimizationContext) context; vxqueryContext.incrementTotalDataSources(); context.addToDontApplySet(this, opRef.getValue()); return false; } }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { ILogicalOperator op = opRef.getValue(); if (context.checkIfInDontApplySet(this, op)) { return false; } op.accept(visitor, null); context.computeAndSetTypeEnvironmentForOperator(op); context.addToDontApplySet(this, op); return false; }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (op1.getOperatorTag() != LogicalOperatorTag.ORDER) { return false; } if (context.checkIfInDontApplySet(this, op1)) { return false; } context.addToDontApplySet(this, op1); OrderOperator oo = (OrderOperator) op1; return extractComplexExpressions(oo, oo.getOrderExpressions(), context); }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext ctx) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (ctx.checkIfInDontApplySet(this, op)) { return false; } ctx.addToDontApplySet(this, op); this.recordVisitor.setOptimizationContext(ctx, op.computeInputTypeEnvironment(ctx)); boolean res = op.acceptExpressionTransform(recordVisitor); if (res) { ctx.computeAndSetTypeEnvironmentForOperator(op); } return res; }
@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.UNNEST) { context.addToDontApplySet(this, op); return false; } UnnestOperator unnest = (UnnestOperator) op; ILogicalExpression unnestExpr = unnest.getExpressionRef().getValue(); if (needsScanCollection(unnestExpr, op)) { UnnestingFunctionCallExpression newExpr = new UnnestingFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), new MutableObject<ILogicalExpression>(unnestExpr)); newExpr.setSourceLocation(unnestExpr.getSourceLocation()); unnest.getExpressionRef().setValue(newExpr); context.addToDontApplySet(this, op); return true; } context.addToDontApplySet(this, op); return false; }
private void typeOpRec(Mutable<ILogicalOperator> r, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) r.getValue(); for (Mutable<ILogicalOperator> i : op.getInputs()) { typeOpRec(i, context); } if (op.hasNestedPlans()) { for (ILogicalPlan p : ((AbstractOperatorWithNestedPlans) op).getNestedPlans()) { typePlan(p, context); } } context.computeAndSetTypeEnvironmentForOperator(op); context.addToDontApplySet(this, op); }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.WINDOW) { return false; } if (context.checkIfInDontApplySet(this, op)) { return false; } context.addToDontApplySet(this, op); WindowOperator winOp = (WindowOperator) op; boolean rewritten = ExtractGbyExpressionsRule.extractComplexExpressions(winOp, winOp.getPartitionExpressions(), Function.identity(), context); rewritten |= ExtractOrderExpressionsRule.extractComplexExpressions(winOp, winOp.getOrderExpressions(), context); if (rewritten) { context.computeAndSetTypeEnvironmentForOperator(op); } return rewritten; } }
private boolean applyRuleDown(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> varSet, IOptimizationContext context) throws AlgebricksException { boolean changed = applies(opRef, varSet, context); AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); VariableUtilities.getUsedVariables(op, varSet); if (op.hasNestedPlans()) { AbstractOperatorWithNestedPlans aonp = (AbstractOperatorWithNestedPlans) op; for (ILogicalPlan p : aonp.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { if (applyRuleDown(r, varSet, context)) { changed = true; } context.addToDontApplySet(this, r.getValue()); } } } for (Mutable<ILogicalOperator> i : op.getInputs()) { if (applyRuleDown(i, varSet, context)) { changed = true; } context.addToDontApplySet(this, i.getValue()); } return changed; }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (context.checkIfInDontApplySet(this, op)) { return false; } context.addToDontApplySet(this, op); if (op.getOperatorTag() != LogicalOperatorTag.AGGREGATE) { return false; } AggregateOperator aggOp = (AggregateOperator) op; if (!aggOp.isGlobal() || aggOp.getExecutionMode() == ExecutionMode.LOCAL) { return false; } Set<SimilarAggregatesInfo> toReplaceSet = new HashSet<SimilarAggregatesInfo>(); Pair<Boolean, Mutable<ILogicalOperator>> result = tryToPushAgg(aggOp, null, toReplaceSet, context); if (!result.first || result.second == null) { return false; } replaceOriginalAggFuncs(toReplaceSet); context.computeAndSetTypeEnvironmentForOperator(aggOp); return true; } }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (op1.getOperatorTag() == LogicalOperatorTag.GROUP) { GroupByOperator groupBy = (GroupByOperator) op1; for (ILogicalPlan p : groupBy.getNestedPlans()) { for (Mutable<ILogicalOperator> aggRef : p.getRoots()) { // make sure we do not trigger this rule for aggregate operators with group by if (aggRef.getValue().getOperatorTag() == LogicalOperatorTag.AGGREGATE) { context.addToDontApplySet(this, aggRef.getValue()); } } } } return false; }
private boolean applyRuleDown(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> varSet, IOptimizationContext context) throws AlgebricksException { boolean changed = applies(opRef, varSet, context); changed |= appliesForReverseCase(opRef, varSet, context); AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); VariableUtilities.getUsedVariables(op, varSet); if (op.hasNestedPlans()) { // Variables used by the parent operators should be live at op. Set<LogicalVariable> localLiveVars = new ListSet<LogicalVariable>(); VariableUtilities.getLiveVariables(op, localLiveVars); varSet.retainAll(localLiveVars); AbstractOperatorWithNestedPlans aonp = (AbstractOperatorWithNestedPlans) op; for (ILogicalPlan p : aonp.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { if (applyRuleDown(r, varSet, context)) { changed = true; } context.addToDontApplySet(this, r.getValue()); } } } for (Mutable<ILogicalOperator> i : op.getInputs()) { if (applyRuleDown(i, varSet, context)) { changed = true; } context.addToDontApplySet(this, i.getValue()); } return changed; }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (context.checkIfInDontApplySet(this, opRef.getValue())) return false; AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); context.addToDontApplySet(this, opRef.getValue()); /** * rewrite list constructor types for list constructor functions */ List<Mutable<ILogicalExpression>> expressions; switch (op.getOperatorTag()) { case ASSIGN: AbstractAssignOperator assignOp = (AbstractAssignOperator) op; expressions = assignOp.getExpressions(); break; case UNNEST: AbstractUnnestOperator unnestOp = (AbstractUnnestOperator) op; expressions = Collections.singletonList(unnestOp.getExpressionRef()); break; default: return false; } IVariableTypeEnvironment env = op.computeOutputTypeEnvironment(context); return rewriteExpressions(expressions, env); }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) { return false; } if (context.checkIfInDontApplySet(this, op1)) { return false; } context.addToDontApplySet(this, op1); GroupByOperator g = (GroupByOperator) op1; boolean r1 = extractComplexExpressions(g, g.getGroupByList(), context); boolean r2 = extractComplexExpressions(g, g.getDecorList(), context); boolean fired = r1 || r2; if (fired) { context.computeAndSetTypeEnvironmentForOperator(g); } return fired; }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (context.checkIfInDontApplySet(this, op)) { return false; } // Disable aggregate combiners for nested plans inside window operators if (op.getOperatorTag() == LogicalOperatorTag.WINDOW) { WindowOperator winOp = (WindowOperator) op; if (winOp.hasNestedPlans()) { for (ILogicalPlan plan : winOp.getNestedPlans()) { for (Mutable<ILogicalOperator> root : plan.getRoots()) { ILogicalOperator rootOp = root.getValue(); if (rootOp.getOperatorTag() == LogicalOperatorTag.AGGREGATE) { context.addToDontApplySet(this, rootOp); } } } } } return false; }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (context.checkIfInDontApplySet(this, opRef.getValue())) { return false; } int variableId = 0; // TODO Move the setVarCounter to the compiler after the translator has run. AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); switch (op.getOperatorTag()) { case ASSIGN: case AGGREGATE: AbstractAssignOperator assign = (AbstractAssignOperator) op; variableId = assign.getVariables().get(0).getId(); break; case UNNEST: UnnestOperator unnest = (UnnestOperator) op; variableId = unnest.getVariable().getId(); break; default: return false; } if (context.getVarCounter() <= variableId) { context.setVarCounter(variableId + 1); } context.addToDontApplySet(this, opRef.getValue()); return false; }
return false; context.addToDontApplySet(this, op);
/** * Generate new ORDER operator that uses TopKSort module and replaces the old ORDER operator. */ private boolean pushLimitIntoOrder(Mutable<ILogicalOperator> opRef, Mutable<ILogicalOperator> opRef2, IOptimizationContext context) throws AlgebricksException { PhysicalOptimizationConfig physicalOptimizationConfig = context.getPhysicalOptimizationConfig(); LimitOperator limitOp = (LimitOperator) opRef.getValue(); OrderOperator orderOp = (OrderOperator) opRef2.getValue(); // We don't push-down LIMIT into in-memory sort. if (orderOp.getPhysicalOperator().getOperatorTag() != PhysicalOperatorTag.STABLE_SORT) { return false; } Integer topK = getOutputLimit(limitOp); if (topK == null) { return false; } // Create the new ORDER operator, set the topK value, and replace the current one. OrderOperator newOrderOp = new OrderOperator(orderOp.getOrderExpressions(), topK); newOrderOp.setSourceLocation(orderOp.getSourceLocation()); newOrderOp.setPhysicalOperator( new StableSortPOperator(physicalOptimizationConfig.getMaxFramesExternalSort(), newOrderOp.getTopK())); newOrderOp.getInputs().addAll(orderOp.getInputs()); newOrderOp.setExecutionMode(orderOp.getExecutionMode()); newOrderOp.recomputeSchema(); newOrderOp.computeDeliveredPhysicalProperties(context); opRef2.setValue(newOrderOp); context.computeAndSetTypeEnvironmentForOperator(newOrderOp); context.addToDontApplySet(this, limitOp); return true; }