public static List<SortCondition> transform(NodeTransform nodeTransform, List<SortCondition> conditions) { List<SortCondition> conditions2 = new ArrayList<SortCondition>() ; boolean same = true ; for ( SortCondition sc : conditions ) { Expr expr = sc.getExpression() ; Expr expr2 = transform(nodeTransform, expr) ; if ( expr != expr2 ) same = false ; SortCondition sc2 = new SortCondition(expr2, sc.getDirection()) ; conditions2.add(sc2) ; } if ( same ) return conditions ; return conditions2 ; } }
public void output(IndentedWriter out, SerializationContext sCxt) { FmtExpr fmt = new FmtExpr(out, sCxt) ; format(fmt, out) ; } }
@Override public int hashCode() { int x = this.getDirection() ; if ( getExpression() != null ) x ^= getExpression().hashCode() ; return x ; }
public void addOrderBy(Expr expr, int direction) { SortCondition sc = new SortCondition(expr, direction) ; addOrderBy(sc) ; }
@Override public void visit(OpOrder opOrder) { for ( Iterator<SortCondition> iter = opOrder.getConditions().iterator() ; iter.hasNext(); ) { SortCondition sc = iter.next(); Set<Var> x = sc.getExpression().getVarsMentioned() ; acc.addAll(x) ; } }
@Override public int hashCode() { int x = this.getDirection() ; if ( getExpression() != null ) x ^= getExpression().hashCode() ; return x ; }
public void addOrderBy(Expr expr, int direction) { SortCondition sc = new SortCondition(expr, direction) ; addOrderBy(sc) ; }
@Override public void visit(OpOrder opOrder) { for (Iterator<SortCondition> iter = opOrder.getConditions().iterator(); iter.hasNext();) { SortCondition sc = iter.next() ; Set<Var> x = sc.getExpression().getVarsMentioned() ; acc.addAll(x) ; } } }
@Override public void visit(OpOrder opOrder) { List<SortCondition> conditions = opOrder.getConditions() ; List<SortCondition> conditions2 = new ArrayList<SortCondition>() ; boolean changed = false ; for ( SortCondition sc : conditions ) { Expr e = sc.getExpression() ; Expr e2 = ExprTransformer.transform(exprTransform, e) ; conditions2.add(new SortCondition(e2, sc.getDirection())) ; if ( e != e2 ) changed = true ; } OpOrder x = opOrder ; if ( changed ) x = new OpOrder(opOrder.getSubOp(), conditions2) ; visit1(x) ; }
@Override public boolean equals(Object other) { if ( this == other ) return true ; if ( ! ( other instanceof SortCondition ) ) return false ; SortCondition sc = (SortCondition)other ; if ( sc.getDirection() != this.getDirection() ) return false ; if ( ! Lib.equal(this.getExpression(), sc.getExpression()) ) return false ; // if ( ! Utils.eq(this.getVariable(), sc.getVariable()) ) // return false ; return true ; }
@Override public List<SortCondition> getOrderBy() { List<SortCondition> conditions = new ArrayList<SortCondition>(); List<OrderCondition> orderConditions = selectQuery .getSolutionModifier().getOrderClause(); for (OrderCondition condition : orderConditions) { Var expr = null; int dir = ORDER_UNKNOW; if (condition.getType() == OrderCondition.EOrderType.ASC) { dir = ORDER_ASCENDING; } else if (condition.getType() == OrderCondition.EOrderType.DESC) { dir = ORDER_DESCENDING; } SortCondition sortCondition = new SortCondition(expr, dir); conditions.add(sortCondition); } return conditions.size() > 0 ? conditions : null; }
/** * Determines whether a sort condition is valid in terms of this optimizer * * @param cond * Sort Condition * @param projectVars * Project Variables * @return True if valid, false otherwise */ private boolean isValidSortCondition(SortCondition cond, List<Var> projectVars) { if (cond.getExpression().isVariable()) { return projectVars.contains(cond.getExpression().asVar()); } else { for (Var v : cond.getExpression().getVarsMentioned()) { if (!projectVars.contains(v)) return false; } return true; } } }
@Override public void output(IndentedWriter out, SerializationContext sCxt) { if ( sCxt == null ) sCxt = new SerializationContext() ; FmtExprSPARQL fmt = new FmtExprSPARQL(out, sCxt) ; format(fmt, out) ; } }
@Override public void visit(OpOrder opOrder) { List<SortCondition> conditions = opOrder.getConditions() ; List<SortCondition> conditions2 = new ArrayList<SortCondition>() ; boolean changed = false ; for ( SortCondition sc : conditions ) { Expr e = sc.getExpression() ; Expr e2 = transform(e, exprTransform) ; conditions2.add(new SortCondition(e2, sc.getDirection())) ; if ( e != e2 ) changed = true ; } OpOrder x = opOrder ; if ( changed ) x = new OpOrder(opOrder.getSubOp(), conditions2) ; visit1(x) ; }
@Override public boolean equals(Object other) { if ( this == other ) return true ; if ( ! ( other instanceof SortCondition ) ) return false ; SortCondition sc = (SortCondition)other ; if ( sc.getDirection() != this.getDirection() ) return false ; if ( ! Lib.equal(this.getExpression(), sc.getExpression()) ) return false ; // if ( ! Utils.eq(this.getVariable(), sc.getVariable()) ) // return false ; return true ; }
public void addOrderBy(Node var, int direction) { if ( ! var.isVariable() ) throw new QueryException("Not a variable: "+var) ; SortCondition sc = new SortCondition(var, direction) ; addOrderBy(sc) ; }
/** * Determines whether a sort condition is valid in terms of this optimizer * * @param cond * Sort Condition * @param projectVars * Project Variables * @return True if valid, false otherwise */ private boolean isValidSortCondition(SortCondition cond, Collection<Var> projectVars, Set<Var> seenVars) { if (cond.getExpression().isVariable()) { if (projectVars.contains(cond.getExpression().asVar())) { seenVars.add(cond.getExpression().asVar()); return true; } return false; } else { for (Var v : cond.getExpression().getVarsMentioned()) { if (!projectVars.contains(v)) return false; seenVars.add(v); } return true; } } }
@Override public void output(IndentedWriter out) { out.print(Plan.startMarker) ; out.print("SortCondition ") ; FmtExprSPARQL fmt = new FmtExprSPARQL(out, null) ; format(fmt, out) ; out.print(Plan.finishMarker) ; }
Expr e = sc.getExpression() ; e = ExprLib.replaceAggregateByVariable(e) ; scList.add(new SortCondition(e, sc.getDirection())) ;
private void formatSortCondition(SortCondition sc) { boolean close = true ; String tag = null ; if ( sc.getDirection() != Query.ORDER_DEFAULT ) { if ( sc.getDirection() == Query.ORDER_ASCENDING ) { tag = Tags.tagAsc ; WriterLib.start(out, tag, NoNL) ; } if ( sc.getDirection() == Query.ORDER_DESCENDING ) { tag = Tags.tagDesc ; WriterLib.start(out, tag, NoNL) ; } } WriterExpr.output(out, sc.getExpression(), sContext) ; if ( tag != null ) WriterLib.finish(out, tag) ; }