Search in sources :

Example 1 with TupleExpr

use of org.openrdf.query.algebra.TupleExpr in project backstage by zepheira.

the class TupleQueryBuilder method joinTupleExpressions.

public TupleExpr joinTupleExpressions() {
    Iterator<TupleExpr> i = _tupleExprs.iterator();
    TupleExpr result = i.hasNext() ? i.next() : null;
    while (i.hasNext()) {
        result = new Join(result, i.next());
    }
    return result;
}
Also used : Join(org.openrdf.query.algebra.Join) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Example 2 with TupleExpr

use of org.openrdf.query.algebra.TupleExpr in project backstage by zepheira.

the class TupleQueryBuilder method makeFilterTupleExpr.

public TupleExpr makeFilterTupleExpr() {
    TupleExpr tupleExprs = joinTupleExpressions();
    ValueExpr conditions = joinConditions();
    return (conditions == null) ? tupleExprs : new Filter(tupleExprs, conditions);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Filter(org.openrdf.query.algebra.Filter) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Example 3 with TupleExpr

use of org.openrdf.query.algebra.TupleExpr in project gocd by gocd.

the class SesameGraph method contextualize.

private void contextualize(Query query) throws Exception {
    if (contextVar == null) {
        return;
    }
    TupleExpr tupleExpr = ((SailQuery) query).getParsedQuery().getTupleExpr();
    tupleExpr.visit(new QueryModelVisitorBase() {

        public void meet(StatementPattern node) throws Exception {
            if (node.getContextVar() != null) {
                throw new UnsupportedSPARQLStatementException("Attempted to execute a SPARQL statement with a GRAPH clause against a context aware graph.");
            }
            node.setContextVar(contextVar);
        }
    });
}
Also used : QueryModelVisitorBase(org.openrdf.query.algebra.helpers.QueryModelVisitorBase) StatementPattern(org.openrdf.query.algebra.StatementPattern) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException) TupleExpr(org.openrdf.query.algebra.TupleExpr) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) OpenRDFException(org.openrdf.OpenRDFException) NoSuchElementException(java.util.NoSuchElementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)

Example 4 with TupleExpr

use of org.openrdf.query.algebra.TupleExpr in project backstage by zepheira.

the class Expression method computeOutputOnValue.

public ExpressionQueryResult computeOutputOnValue(Value value, Database database, SailRepositoryConnection connection) throws ExpressionException {
    TupleQueryBuilder builder = new TupleQueryBuilder();
    Var valueVar = builder.makeVar("value", value);
    ExpressionResult expressionResult = computeOutputOnItem(database, builder, valueVar);
    if (expressionResult.valueExpr instanceof Var) {
        Var resultVar = (Var) expressionResult.valueExpr;
        ProjectionElemList projectionElements = new ProjectionElemList();
        projectionElements.addElement(new ProjectionElem(resultVar.getName()));
        TupleExpr t = builder.makeFilterTupleExpr();
        if (t == null) {
            // TODO[dfhuynh]: This happens if the expression is just "value". I'm not sure what to do here.
            return null;
        }
        Projection projection = new Projection(t, projectionElements);
        TupleQuery query = new MyTupleQuery(new ParsedTupleQuery(projection), connection);
        return new ExpressionQueryResult(query, expressionResult.valueType, resultVar);
    }
    return null;
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) Var(org.openrdf.query.algebra.Var) Projection(org.openrdf.query.algebra.Projection) TupleQueryBuilder(edu.mit.simile.backstage.model.TupleQueryBuilder) ParsedTupleQuery(org.openrdf.query.parser.ParsedTupleQuery) MyTupleQuery(edu.mit.simile.backstage.util.MyTupleQuery) TupleQuery(org.openrdf.query.TupleQuery) MyTupleQuery(edu.mit.simile.backstage.util.MyTupleQuery) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) TupleExpr(org.openrdf.query.algebra.TupleExpr) ParsedTupleQuery(org.openrdf.query.parser.ParsedTupleQuery)

Example 5 with TupleExpr

use of org.openrdf.query.algebra.TupleExpr in project backstage by zepheira.

the class TupleQueryBuilder method getStringSerialization.

public String getStringSerialization() {
    StringBuffer sb = new StringBuffer();
    boolean first = true;
    for (TupleExpr tupleExpr : _tupleExprs) {
        if (first) {
            first = false;
        } else {
            sb.append(';');
        }
        sb.append(QueryModelTreePrinter.printTree(tupleExpr));
    }
    for (ValueExpr valueExpr : _conditions) {
        if (first) {
            first = false;
            sb.append('|');
        } else {
            sb.append(';');
        }
        sb.append(QueryModelTreePrinter.printTree(valueExpr));
    }
    return sb.toString();
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Aggregations

TupleExpr (org.openrdf.query.algebra.TupleExpr)5 ValueExpr (org.openrdf.query.algebra.ValueExpr)2 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)1 MalformedSPARQLException (com.thoughtworks.studios.shine.semweb.MalformedSPARQLException)1 MoreThanOneResultFoundException (com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException)1 UnsupportedSPARQLStatementException (com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)1 TupleQueryBuilder (edu.mit.simile.backstage.model.TupleQueryBuilder)1 MyTupleQuery (edu.mit.simile.backstage.util.MyTupleQuery)1 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 OpenRDFException (org.openrdf.OpenRDFException)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 TupleQuery (org.openrdf.query.TupleQuery)1 TupleQueryResultHandlerException (org.openrdf.query.TupleQueryResultHandlerException)1 Filter (org.openrdf.query.algebra.Filter)1 Join (org.openrdf.query.algebra.Join)1 Projection (org.openrdf.query.algebra.Projection)1 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)1 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)1