Java Code Examples for org.apache.jena.query.Query#hasOrderBy()

The following examples show how to use org.apache.jena.query.Query#hasOrderBy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SparqlToGremlinCompiler.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * 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.desc : Order.asc);
        }
    }

    return orderingIndex;
}
 
Example 2
Source File: QueryStatistics.java    From IGUANA with GNU Affero General Public License v3.0 6 votes vote down vote up
public void getStatistics(Query q) {
	if(q.isSelectType()) {
		
		size++;
		offset+=q.hasOffset()?1:0;
		aggr+=q.hasAggregators()?1:0;
		groupBy+=q.hasGroupBy()?1:0;
		having+=q.hasHaving()?1:0;
		orderBy+=q.hasOrderBy()?1:0;

		StatisticsVisitor visitor = new StatisticsVisitor();
		visitor.setElementWhere(q.getQueryPattern());
		ElementWalker.walk(q.getQueryPattern(), visitor);
		
		union+=visitor.union?1:0;
		optional+=visitor.optional?1:0;
		filter+=visitor.filter?1:0;
		triples += visitor.bgps;
		
	}
}
 
Example 3
Source File: QueryXExprNormalizer.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visitOrderBy(Query query) {
    if (query.hasOrderBy()) {
        query.getOrderBy().replaceAll((sc) -> {
            final Expr expr = enzer.normalize(sc.getExpression());
            return new SortCondition(expr, sc.getDirection());
        });
    }
}
 
Example 4
Source File: SelectQueryPartialCopyVisitor.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visitOrderBy(final Query query) {
    if (query.hasOrderBy()) {
        for (SortCondition sc : query.getOrderBy()) {
            output.addOrderBy(sc);
        }
    }
}
 
Example 5
Source File: SelectExtractionVisitor.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visitOrderBy(final Query query) {
    if (query.hasOrderBy()) {
    	isDummyQuery = false;
        for (SortCondition sc : query.getOrderBy()) {
            output.addOrderBy(sc);
        }
    }
}
 
Example 6
Source File: SPARQLExtQuerySerializer.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visitOrderBy(Query query) {
    if (query.hasOrderBy()) {
        out.print("ORDER BY ");
        boolean first = true;
        for (SortCondition sc : query.getOrderBy()) {
            if (!first) {
                out.print(" ");
            }
            sc.format(fmtExpr, out);
            first = false;
        }
        out.println();
    }
}