@Override public ILogicalOperator visitDistinctOperator(DistinctOperator op, Void arg) throws AlgebricksException { visitSingleInputOperator(op); List<LogicalVariable> distinctVarList = op.getDistinctByVarList(); for (LogicalVariable keyVar : correlatedKeyVars) { if (!distinctVarList.contains(keyVar)) { distinctVarList.add(keyVar); } } context.computeAndSetTypeEnvironmentForOperator(op); return op; }
private void typeGby(AbstractOperatorWithNestedPlans op, IOptimizationContext context) throws AlgebricksException { for (ILogicalPlan p : op.getNestedPlans()) { OperatorPropertiesUtil.typePlan(p, context); } context.computeAndSetTypeEnvironmentForOperator(op); }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { ILogicalOperator op = opRef.getValue(); if (context.getOutputTypeEnvironment(op) != null) { return false; } context.computeAndSetTypeEnvironmentForOperator(op); return true; }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { exprEqClassMap.clear(); substVisitor.setContext(context); boolean modified = removeCommonExpressions(opRef, context); if (modified) { context.computeAndSetTypeEnvironmentForOperator(opRef.getValue()); } return modified; }
private void propagateFilterInSecondaryUnnsetMap(UnnestMapOperator secondaryUnnest, IAType filterType, IOptimizationContext context) throws AlgebricksException { LogicalVariable minIndexFilterVar = context.newVar(); LogicalVariable maxIndexFilterVar = context.newVar(); secondaryUnnest.markPropagageIndexFilter(); secondaryUnnest.getVariables().add(minIndexFilterVar); secondaryUnnest.getVariableTypes().add(filterType); secondaryUnnest.getVariables().add(maxIndexFilterVar); secondaryUnnest.getVariableTypes().add(filterType); context.computeAndSetTypeEnvironmentForOperator(secondaryUnnest); }
private void inferTypes(ILogicalOperator op, IOptimizationContext context) throws AlgebricksException { for (Mutable<ILogicalOperator> childOpRef : op.getInputs()) { inferTypes(childOpRef.getValue(), context); } context.computeAndSetTypeEnvironmentForOperator(op); }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { boolean modified = false; List<Mutable<ILogicalExpression>> expressions = OperatorToolbox.getExpressions(opRef); for (Mutable<ILogicalExpression> expression : expressions) { if (processExpression(opRef, expression)) { modified = true; } } context.computeAndSetTypeEnvironmentForOperator(opRef.getValue()); return modified; }
private void insertProjectOperator(UnionAllOperator opUnion, int branch, ArrayList<LogicalVariable> usedVariables, IOptimizationContext context) throws AlgebricksException { ProjectOperator projectOp = new ProjectOperator(usedVariables); ILogicalOperator inputOp = opUnion.getInputs().get(branch).getValue(); projectOp.getInputs().add(new MutableObject<ILogicalOperator>(inputOp)); opUnion.getInputs().get(branch).setValue(projectOp); projectOp.setPhysicalOperator(new StreamProjectPOperator()); projectOp.setExecutionMode(inputOp.getExecutionMode()); context.computeAndSetTypeEnvironmentForOperator(projectOp); context.computeAndSetTypeEnvironmentForOperator(inputOp); }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (context.checkIfInDontApplySet(this, opRef.getValue())) { return false; } boolean modified = removeRedundantVariables(opRef, context); if (modified) { context.computeAndSetTypeEnvironmentForOperator(opRef.getValue()); } return modified; }
@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 { ILogicalOperator op = opRef.getValue(); if (op.acceptExpressionTransform(exprRef -> rewriteExpressionReference(op, exprRef, context))) { op.removeAnnotation(OperatorAnnotation.PUSHED_FIELD_ACCESS); context.computeAndSetTypeEnvironmentForOperator(op); return true; } return false; }
private static ExchangeOperator createOneToOneExchangeOp(MutableObject<ILogicalOperator> inputOperator, IOptimizationContext context) throws AlgebricksException { ExchangeOperator exchangeOperator = new ExchangeOperator(); exchangeOperator.setPhysicalOperator(new OneToOneExchangePOperator()); exchangeOperator.getInputs().add(inputOperator); exchangeOperator.setExecutionMode(AbstractLogicalOperator.ExecutionMode.PARTITIONED); exchangeOperator.recomputeSchema(); context.computeAndSetTypeEnvironmentForOperator(exchangeOperator); return exchangeOperator; }
private static ReplicateOperator createReplicateOperator(Mutable<ILogicalOperator> inputOperator, IOptimizationContext context, SourceLocation sourceLocation) throws AlgebricksException { ReplicateOperator replicateOperator = new ReplicateOperator(2); replicateOperator.setPhysicalOperator(new ReplicatePOperator()); replicateOperator.setSourceLocation(sourceLocation); replicateOperator.getInputs().add(inputOperator); OperatorManipulationUtil.setOperatorMode(replicateOperator); replicateOperator.recomputeSchema(); context.computeAndSetTypeEnvironmentForOperator(replicateOperator); return replicateOperator; }
private void setPrimaryFilterVar(UnnestMapOperator primaryOp, LogicalVariable minFilterVar, LogicalVariable maxFilterVar, IOptimizationContext context) throws AlgebricksException { primaryOp.setMinFilterVars(Collections.singletonList(minFilterVar)); primaryOp.setMaxFilterVars(Collections.singletonList(maxFilterVar)); VariableReferenceExpression minFilterVarRef = new VariableReferenceExpression(minFilterVar); minFilterVarRef.setSourceLocation(primaryOp.getSourceLocation()); VariableReferenceExpression maxFilterVarRef = new VariableReferenceExpression(maxFilterVar); maxFilterVarRef.setSourceLocation(primaryOp.getSourceLocation()); List<Mutable<ILogicalExpression>> indexFilterExpression = Arrays.asList(new MutableObject<>(minFilterVarRef), new MutableObject<>(maxFilterVarRef)); primaryOp.setAdditionalFilteringExpressions(indexFilterExpression); context.computeAndSetTypeEnvironmentForOperator(primaryOp); }
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); }
private void setNewOp(Mutable<ILogicalOperator> opRef, AbstractLogicalOperator newOp, IOptimizationContext context) throws AlgebricksException { ILogicalOperator oldOp = opRef.getValue(); opRef.setValue(newOp); newOp.getInputs().add(new MutableObject<>(oldOp)); newOp.recomputeSchema(); newOp.computeDeliveredPhysicalProperties(context); context.computeAndSetTypeEnvironmentForOperator(newOp); if (AlgebricksConfig.ALGEBRICKS_LOGGER.isTraceEnabled()) { AlgebricksConfig.ALGEBRICKS_LOGGER.trace(">>>> Structural properties for " + newOp.getPhysicalOperator() + ": " + newOp.getDeliveredPhysicalProperties() + "\n"); } PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(newOp, 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; }
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); }
public static void ntsToEts(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) { EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator(); context.computeAndSetTypeEnvironmentForOperator(ets); opRef.setValue(ets); } else { for (Mutable<ILogicalOperator> i : opRef.getValue().getInputs()) { ntsToEts(i, context); } } }
protected static LogicalVariable extractExprIntoAssignOpRef(ILogicalExpression gExpr, Mutable<ILogicalOperator> opRef2, IOptimizationContext context) throws AlgebricksException { LogicalVariable v = context.newVar(); AssignOperator a = new AssignOperator(v, new MutableObject<>(gExpr)); a.setSourceLocation(gExpr.getSourceLocation()); a.getInputs().add(new MutableObject<>(opRef2.getValue())); opRef2.setValue(a); if (gExpr.getExpressionTag() == LogicalExpressionTag.CONSTANT) { context.addNotToBeInlinedVar(v); } context.computeAndSetTypeEnvironmentForOperator(a); return v; }