use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class SPARQLParserTest method testParsedTupleQueryRootNode.
@Test
public void testParsedTupleQueryRootNode() throws Exception {
StringBuilder qb = new StringBuilder();
qb.append("SELECT * {?a <foo:bar> \"test\"}");
ParsedTupleQuery q = (ParsedTupleQuery) parser.parseQuery(qb.toString(), null);
TupleExpr te = q.getTupleExpr();
assertNotNull(te);
assertTrue(te instanceof Projection);
assertNull(te.getParentNode());
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class TupleExprBuilderTest method testAskQuerySolutionModifiers.
@Test
public void testAskQuerySolutionModifiers() {
String query = "ASK WHERE { ?foo ?bar ?baz . } ORDER BY ?foo LIMIT 1";
try {
TupleExprBuilder builder = new TupleExprBuilder(ValueFactoryImpl.getInstance());
ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(query);
TupleExpr result = builder.visit(qc, null);
assertTrue(result instanceof Order);
} catch (Exception e) {
e.printStackTrace();
fail("should parse ask query with solution modifiers");
}
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class BasicGroup method filteredTuple.
private TupleExpr filteredTuple(TupleExpr theExpr) {
TupleExpr aExpr = theExpr;
for (ValueExpr aValEx : mFilters) {
Filter aFilter = new Filter();
aFilter.setCondition(aValEx);
aFilter.setArg(aExpr);
aExpr = aFilter;
}
return aExpr;
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class GraphPattern method buildTupleExpr.
/**
* Builds a combined tuple expression from the tuple expressions and constraints in this graph pattern.
*
* @return A tuple expression for this graph pattern.
*/
public TupleExpr buildTupleExpr() {
TupleExpr result;
if (requiredTEs.isEmpty()) {
result = new SingletonSet();
} else {
result = requiredTEs.get(0);
for (int i = 1; i < requiredTEs.size(); i++) {
TupleExpr te = requiredTEs.get(i);
// if (containsProjection(te) || containsProjection(result))
// {
// result = new BottomUpJoin(result, te);
// }
// else {
result = new Join(result, te);
// }
}
}
for (Map.Entry<TupleExpr, List<ValueExpr>> entry : optionalTEs) {
List<ValueExpr> constraints = entry.getValue();
if (constraints != null && !constraints.isEmpty()) {
ValueExpr condition = constraints.get(0);
for (int i = 1; i < constraints.size(); i++) {
condition = new And(condition, constraints.get(i));
}
result = new LeftJoin(result, entry.getKey(), condition);
} else {
result = new LeftJoin(result, entry.getKey());
}
}
for (ValueExpr constraint : constraints) {
result = new Filter(result, constraint);
}
return result;
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class SPARQLParser method parseQuery.
@Override
public ParsedQuery parseQuery(String queryStr, String baseURI) throws MalformedQueryException {
try {
ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(queryStr);
StringEscapesProcessor.process(qc);
BaseDeclProcessor.process(qc, baseURI);
Map<String, String> prefixes = PrefixDeclProcessor.process(qc);
WildcardProjectionProcessor.process(qc);
BlankNodeVarProcessor.process(qc);
if (qc.containsQuery()) {
// handle query operation
TupleExpr tupleExpr = buildQueryModel(qc);
ParsedQuery query;
ASTQuery queryNode = qc.getQuery();
if (queryNode instanceof ASTSelectQuery) {
query = new ParsedTupleQuery(queryStr, tupleExpr);
} else if (queryNode instanceof ASTConstructQuery) {
query = new ParsedGraphQuery(queryStr, tupleExpr, prefixes);
} else if (queryNode instanceof ASTAskQuery) {
query = new ParsedBooleanQuery(queryStr, tupleExpr);
} else if (queryNode instanceof ASTDescribeQuery) {
query = new ParsedDescribeQuery(queryStr, tupleExpr, prefixes);
} else {
throw new RuntimeException("Unexpected query type: " + queryNode.getClass());
}
// Handle dataset declaration
Dataset dataset = DatasetDeclProcessor.process(qc);
if (dataset != null) {
query.setDataset(dataset);
}
return query;
} else {
throw new IncompatibleOperationException("supplied string is not a query operation");
}
} catch (ParseException e) {
throw new MalformedQueryException(e.getMessage(), e);
} catch (TokenMgrError e) {
throw new MalformedQueryException(e.getMessage(), e);
}
}
Aggregations