SPARQL
src/query/sparql/ contains a SPARQL 1.1 parser, an RDF data model with N-Triples and Turtle readers and writers, an in-memory executor, a planner to LogicalPlan, and result formatters. None of it is reachable from a running server.
Not wired: no listener or HTTP route accepts SPARQL. QueryEngine::parse_query refuses QueryLanguage::SPARQL with "SPARQL queries not supported in QueryEngine; use QueryCompiler", and QueryCompiler, which holds a SparqlAnalyzer, is not constructed outside src/query/mod.rs (source: src/query/engine.rs, QueryEngine::parse_query; src/query/mod.rs, QueryCompiler). The only callers are the module's own unit tests.
The module comment lists "Full SPARQL 1.1 query parsing" and "Integration with SynergyDB's unified query engine"; the sections below describe what the code does (source: src/query/sparql/mod.rs, module comment).
Two execution paths
(source: src/query/sparql/mod.rs, SparqlEngine::execute, SparqlEngine::to_logical_plan, SparqlAnalyzer::parse; src/query/sparql/parser.rs, parse_sparql; src/query/sparql/executor.rs, SparqlExecutor; src/query/sparql/planner.rs, SparqlPlanner::plan)
-
Executor.
SparqlEngine::execute(query, dataset)evaluates against aDatasetthe caller builds in memory, for example fromparse_turtleorparse_ntriples(source:src/query/sparql/mod.rs,SparqlEngine;src/query/sparql/rdf.rs,parse_turtle,parse_ntriples). -
Planner.
SparqlPlannermaps triple patterns to scans of a table namedrdf_triples(source:src/query/sparql/planner.rs,SparqlPlanner::new). No code creates anrdf_triplestable.
Parsed syntax
| Element | Covered by the AST |
|---|---|
| Query forms |
SELECT, CONSTRUCT, DESCRIBE, ASK
|
| Graph patterns | basic graph patterns, groups, OPTIONAL, UNION, GRAPH, FILTER, MINUS, BIND, SERVICE, sub-SELECT, VALUES
|
| Property paths | IRI, inverse ^, sequence /, alternative \|, *, +, ?, negated set !(...)
|
| Aggregates |
COUNT, SUM, MIN, MAX, AVG, GROUP_CONCAT, SAMPLE
|
| Built-ins |
STR, LANG, LANGMATCHES, DATATYPE, BOUND, IRI/URI, BNODE, RAND, ABS, CEIL, FLOOR, ROUND, CONCAT, SUBSTR, STRLEN, REPLACE, UCASE, LCASE, ENCODE_FOR_URI, CONTAINS, STRSTARTS, STRENDS, STRBEFORE, STRAFTER, YEAR, MONTH, DAY, HOURS, MINUTES, SECONDS, TIMEZONE, TZ, NOW, UUID, STRUUID, MD5, SHA1, SHA256, SHA384, SHA512, COALESCE, IF, STRLANG, STRDT, sameTerm, isIRI/isURI, isBlank, isLiteral, isNumeric, REGEX
|
(source: src/query/sparql/ast.rs, QueryForm, GroupGraphPattern, PropertyPath, AggregateFunction, BuiltInCall)
SPARQL Update (INSERT DATA, DELETE DATA, LOAD and the rest) is not parsed (source: src/query/sparql/parser.rs).
Executor behaviour
The executor evaluates patterns as follows (source: src/query/sparql/executor.rs, evaluate_pattern, match_triple, get_active_graph):
| Pattern | What the code does |
|---|---|
| Basic graph pattern | Matches triples and joins bindings |
| Group | Joins the solutions of each member |
OPTIONAL |
Returns the inner solutions, which the enclosing group then joins; Solutions::left_join exists but is not called, so non-matching rows are dropped instead of kept |
UNION |
Union of both sides |
FILTER |
Returns a unit solution; the filter expression is not applied to the group's solutions |
BIND |
Returns one empty binding; the variable is not bound |
MINUS |
Returns the inner solutions, which the group joins rather than subtracts |
GRAPH <g> |
Evaluates against the default graph; the graph name is ignored |
FROM, FROM NAMED
|
Ignored; the default graph is used |
VALUES |
Produces the listed bindings |
SERVICE |
Error "SERVICE federated queries not implemented" |
Sub-SELECT
|
Error "Subqueries not fully implemented" |
| Property path in a triple pattern | No match |
HAVING is applied with evaluate_filter; that is the only call site of the filter evaluator in query execution (source: src/query/sparql/executor.rs, evaluate_filter). DESCRIBE returns every triple whose subject or object is a described resource (source: src/query/sparql/executor.rs, execute).
Result formats: JSON, XML, CSV and TSV for SELECT and ASK; graph results from CONSTRUCT and DESCRIBE are refused by the XML, CSV and TSV formatters (source: src/query/sparql/mod.rs, format_json, format_xml, format_csv, format_tsv).
Planner behaviour
SparqlPlanner handles basic graph patterns, groups with filters, OPTIONAL, UNION, FILTER, BIND, MINUS, GRAPH and VALUES. It refuses SERVICE ("SERVICE not supported"), property paths ("Property paths in query planning") and property paths in CONSTRUCT templates (source: src/query/sparql/planner.rs, plan_pattern, plan_bgp, plan_inline_data). Not verified: no test executes a planner output on QueryEngine.
Tests
-
src/query/sparql/parser.rs(11):test_parse_simple_select,test_parse_select_with_variables,test_parse_with_prefix,test_parse_filter,test_parse_optional,test_parse_order_by_limit_offset,test_parse_group_by,test_parse_ask,test_parse_construct,test_parse_describe,test_parse_union. -
src/query/sparql/mod.rs(10), includingtest_engine_execute_select,test_engine_execute_ask,test_engine_execute_constructand the formatter tests. -
src/query/sparql/executor.rs(8): bindings, joins, triple matching, expression evaluation andCOUNT,SUM,AVGaggregates. -
src/query/sparql/rdf.rs(7),src/query/sparql/planner.rs(3),src/query/sparql/ast.rs(3).
No test runs a query with FILTER, OPTIONAL or MINUS through the executor and checks the rows, which is why the gaps above are not caught (source: src/query/sparql/executor.rs, mod.rs, tests modules).