/** * Extracts any {@code SortCondition} instances from the SPARQL query and holds them in an index of their keys * where the value is that keys sorting direction. */ private static Map<String, Order> createOrderIndexFromQuery(final Query query) { final Map<String, Order> orderingIndex = new HashMap<>(); if (query.hasOrderBy()) { final List<SortCondition> sortingConditions = query.getOrderBy(); for (SortCondition sortCondition : sortingConditions) { final Expr expr = sortCondition.getExpression(); // by default, the sort will be ascending. getDirection() returns -2 if the DESC/ASC isn't // supplied - weird orderingIndex.put(expr.getVarName(), sortCondition.getDirection() == -1 ? Order.decr : Order.incr); } } return orderingIndex; }
@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 ( ! Objects.equals(this.getExpression(), sc.getExpression()) ) return false ; // if ( ! Utils.eq(this.getVariable(), sc.getVariable()) ) // return false ; return true ; }
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) ; }
protected List<SortCondition> transform(List<SortCondition> conditions) { List<SortCondition> conditions2 = new ArrayList<>() ; boolean changed = false ; for ( SortCondition sc : conditions ) { Expr e = sc.getExpression() ; Expr e2 = transform(e) ; conditions2.add(new SortCondition(e2, sc.getDirection())) ; if ( e != e2 ) changed = true ; } if ( changed ) return conditions2 ; else return conditions ; }
public static List<SortCondition> transform(NodeTransform nodeTransform, List<SortCondition> conditions) { List<SortCondition> conditions2 = new ArrayList<>() ; boolean same = true ; for ( SortCondition sc : conditions ) { Expr expr = sc.getExpression() ; Expr expr2 = NodeTransformLib.transform(nodeTransform, expr) ; if ( expr != expr2 ) same = false ; SortCondition sc2 = new SortCondition(expr2, sc.getDirection()) ; conditions2.add(sc2) ; } if ( same ) return conditions ; return conditions2 ; }
@Override public int hashCode() { int x = this.getDirection() ; if ( getExpression() != null ) x ^= getExpression().hashCode() ; return x ; }
private List<SortCondition> processConditions(List<SortCondition> baseConditions, List<SortCondition> processedConditions, Var var) { List<SortCondition> inputConditions = processedConditions != null ? processedConditions : baseConditions; List<SortCondition> outputConditions = new ArrayList<>(); for (SortCondition cond : inputConditions) { Expr e = cond.getExpression(); e = ExprTransformer.transform(new ExprTransformSubstitute(var, getAssignExpr(var)), e); outputConditions.add(new SortCondition(e, cond.getDirection())); } return outputConditions; }
public final SortCondition rewrite(SortCondition sortCondition) { sortCondition.getExpression().visit(this); return new SortCondition(pop(), sortCondition.getDirection()); }
public final SortCondition rewrite(SortCondition sortCondition) { sortCondition.getExpression().visit(this); return new SortCondition(pop(), sortCondition.getDirection()); }
@Override public void visit(OpOrder opOrder) { List<SortCondition> conditions = opOrder.getConditions() ; List<SortCondition> conditions2 = new ArrayList<>() ; boolean changed = false ; for ( SortCondition sc : conditions ) { Expr e = sc.getExpression() ; Expr e2 = transform(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) ; }
query.addOrderBy(sc) ; else query.addOrderBy(new SortCondition(expr, sc.getDirection())) ; }) ;
SqlSortCondition sqlCond = new SqlSortCondition(sqlExpr, sc.getDirection());
scList.add(new SortCondition(e, sc.getDirection())) ;