@Override public Boolean visitOrderOperator(OrderOperator op, ILogicalOperator arg) throws AlgebricksException { AbstractLogicalOperator aop = (AbstractLogicalOperator) arg; if (aop.getOperatorTag() != LogicalOperatorTag.ORDER) { return Boolean.FALSE; } OrderOperator orderOpArg = (OrderOperator) copyAndSubstituteVar(op, arg); boolean isomorphic = compareIOrderAndExpressions(op.getOrderExpressions(), orderOpArg.getOrderExpressions()); return isomorphic; }
@Override public Void visitOrderOperator(OrderOperator op, Void arg) { for (Pair<IOrder, Mutable<ILogicalExpression>> oe : op.getOrderExpressions()) { oe.second.getValue().getUsedVariables(usedVariables); } return null; }
@Override public ILogicalOperator visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException { return new OrderOperator(this.deepCopyOrderAndExpression(op.getOrderExpressions())); }
@Override public Void visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException { for (Pair<IOrder, Mutable<ILogicalExpression>> p : op.getOrderExpressions()) { sweepExpression(p.second.getValue()); } return null; }
@Override public String visitOrderOperator(OrderOperator op, Boolean showDetails) throws AlgebricksException { stringBuilder.setLength(0); stringBuilder.append("order "); int topK = op.getTopK(); if (topK != -1) { stringBuilder.append("(topK: ").append(topK).append(") "); } printOrderExprList(op.getOrderExpressions()); appendSchema(op, showDetails); appendAnnotations(op, showDetails); appendPhysicalOperatorInfo(op, showDetails); return stringBuilder.toString(); }
@Override public ILogicalOperator visitOrderOperator(OrderOperator op, ILogicalOperator arg) throws AlgebricksException { OrderOperator opCopy = new OrderOperator(deepCopyOrderExpressionReferencePairList(op.getOrderExpressions())); deepCopyInputsAnnotationsAndExecutionMode(op, arg, opCopy); return opCopy; }
@Override public Void visitOrderOperator(OrderOperator op, Pair<LogicalVariable, LogicalVariable> pair) throws AlgebricksException { for (Pair<IOrder, Mutable<ILogicalExpression>> oe : op.getOrderExpressions()) { oe.second.getValue().substituteVar(pair.first, pair.second); } substVarTypes(op, pair); return null; }
public void computeLocalProperties(ILogicalOperator op) { OrderOperator ord = (OrderOperator) op; List<OrderColumn> orderColumns = new ArrayList<OrderColumn>(); for (Pair<IOrder, Mutable<ILogicalExpression>> p : ord.getOrderExpressions()) { ILogicalExpression expr = p.second.getValue(); if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) { VariableReferenceExpression varRef = (VariableReferenceExpression) expr; LogicalVariable var = varRef.getVariableReference(); orderColumns.add(new OrderColumn(var, p.first.getKind())); } else { throw new IllegalStateException(); } } sortColumns = orderColumns.toArray(new OrderColumn[orderColumns.size()]); orderProp = new LocalOrderProperty(orderColumns); }
@Override public Void visitOrderOperator(OrderOperator op, Integer indent) throws AlgebricksException { addIndent(indent).append("order "); if (op.getTopK() != -1) { buffer.append("(topK: " + op.getTopK() + ") "); } pprintOrderList(op.getOrderExpressions(), indent); return null; }
@Override public Void visitOrderOperator(OrderOperator op, Integer indent) throws AlgebricksException { addIndent(indent).append("\"operator\": \"order\""); int topK = op.getTopK(); List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> orderExpressions = op.getOrderExpressions(); pprintOrderExprList(orderExpressions, topK, indent); return null; }
@Override public ILogicalOperator visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException { visitSingleInputOperator(op); if (correlatedKeyVars.isEmpty()) { return op; } orderingExprs.clear(); orderingExprs.addAll(OperatorManipulationUtil.cloneOrderExpressions(op.getOrderExpressions())); List<Pair<IOrder, Mutable<ILogicalExpression>>> orderExprList = new ArrayList<>(); // Adds keyVars to the prefix of sorting columns. for (LogicalVariable keyVar : correlatedKeyVars) { VariableReferenceExpression keyVarRef = new VariableReferenceExpression(keyVar); keyVarRef.setSourceLocation(op.getSourceLocation()); orderExprList.add(new Pair<>(OrderOperator.ASC_ORDER, new MutableObject<>(keyVarRef))); } orderExprList.addAll(op.getOrderExpressions()); // Creates an order operator with the new expression list. OrderOperator orderOp = new OrderOperator(orderExprList); orderOp.setSourceLocation(op.getSourceLocation()); orderOp.getInputs().addAll(op.getInputs()); context.computeAndSetTypeEnvironmentForOperator(orderOp); return orderOp; }
@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); }
List<LogicalVariable> orderedColumn = new ArrayList<>(order.getOrderExpressions().size()); for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> orderExpression : order .getOrderExpressions()) { if (orderExpression.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) { throw new CompilationException(ErrorCode.COMPILATION_ERROR,
@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) { VariableReferenceExpression liveVarRef = new VariableReferenceExpression(liveVar); liveVarRef.setSourceLocation(op.getSourceLocation()); orderExprList.add(new Pair<IOrder, Mutable<ILogicalExpression>>(OrderOperator.ASC_ORDER, new MutableObject<ILogicalExpression>(liveVarRef))); } orderExprList.addAll(op.getOrderExpressions()); // Creates an order operator with the new expression list. OrderOperator orderOp = new OrderOperator(orderExprList); orderOp.setSourceLocation(op.getSourceLocation()); orderOp.getInputs().addAll(op.getInputs()); context.computeAndSetTypeEnvironmentForOperator(orderOp); return orderOp; }
List<Pair<IOrder, Mutable<ILogicalExpression>>> orderKeys = orderOperator.getOrderExpressions(); Set<LogicalVariable> orderUsedVars = new HashSet<LogicalVariable>(); for (Pair<IOrder, Mutable<ILogicalExpression>> orderKey : orderKeys) {
@Override public Pair<ILogicalOperator, LogicalVariable> visit(OrderbyClause oc, Mutable<ILogicalOperator> tupSource) throws CompilationException { SourceLocation sourceLoc = oc.getSourceLocation(); OrderOperator ord = new OrderOperator(); ord.setSourceLocation(sourceLoc); Iterator<OrderModifier> modifIter = oc.getModifierList().iterator(); Mutable<ILogicalOperator> topOp = tupSource; for (Expression e : oc.getOrderbyList()) { Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(e, topOp); OrderModifier m = modifIter.next(); OrderOperator.IOrder comp = translateOrderModifier(m); ord.getOrderExpressions().add(new Pair<>(comp, new MutableObject<>(p.first))); topOp = p.second; } ord.getInputs().add(topOp); if (oc.getNumTuples() > 0) { ord.getAnnotations().put(OperatorAnnotations.CARDINALITY, oc.getNumTuples()); } if (oc.getNumFrames() > 0) { ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames()); } if (oc.getRangeMap() != null) { Iterator<OrderModifier> orderModifIter = oc.getModifierList().iterator(); boolean ascending = orderModifIter.next() == OrderModifier.ASC; RangeMapBuilder.verifyRangeOrder(oc.getRangeMap(), ascending); ord.getAnnotations().put(OperatorAnnotations.USE_STATIC_RANGE, oc.getRangeMap()); } return new Pair<>(ord, null); }
for (Pair<IOrder, Mutable<ILogicalExpression>> oe : order1.getOrderExpressions()) { order2.getOrderExpressions().add(oe);
pkVarRef.setSourceLocation(sourceLoc); Mutable<ILogicalExpression> vRef = new MutableObject<>(pkVarRef); order.getOrderExpressions().add(new Pair<>(OrderOperator.ASC_ORDER, vRef));
pkVarRef.setSourceLocation(sourceLoc); Mutable<ILogicalExpression> vRef = new MutableObject<>(pkVarRef); order.getOrderExpressions().add(new Pair<>(OrderOperator.ASC_ORDER, vRef));
/** * 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; }