mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-06-22 13:18:06 +02:00
SPARQL query service (#754)
SPARQL 1.1 query service wrapping pub/sub triples interface Add a backend-agnostic SPARQL query service that parses SPARQL queries using rdflib, decomposes them into triple pattern lookups via the existing TriplesClient pub/sub interface, and performs in-memory joins, filters, and projections. Includes: - SPARQL parser, algebra evaluator, expression evaluator, solution sequence operations (BGP, JOIN, OPTIONAL, UNION, FILTER, BIND, VALUES, GROUP BY, ORDER BY, LIMIT/OFFSET, DISTINCT, aggregates) - FlowProcessor service with TriplesClientSpec - Gateway dispatcher, request/response translators, API spec - Python SDK method (FlowInstance.sparql_query) - CLI command (tg-invoke-sparql-query) - Tech spec (docs/tech-specs/sparql-query.md) New unit tests for SPARQL query
This commit is contained in:
parent
62c30a3a50
commit
d9dc4cbab5
23 changed files with 3498 additions and 3 deletions
|
|
@ -13,4 +13,5 @@ from .rows_query import *
|
|||
from .diagnosis import *
|
||||
from .collection import *
|
||||
from .storage import *
|
||||
from .tool_service import *
|
||||
from .tool_service import *
|
||||
from .sparql_query import *
|
||||
40
trustgraph-base/trustgraph/schema/services/sparql_query.py
Normal file
40
trustgraph-base/trustgraph/schema/services/sparql_query.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from dataclasses import dataclass, field
|
||||
|
||||
from ..core.primitives import Error, Term, Triple
|
||||
from ..core.topic import queue
|
||||
|
||||
############################################################################
|
||||
|
||||
# SPARQL query
|
||||
|
||||
@dataclass
|
||||
class SparqlBinding:
|
||||
"""A single row of SPARQL SELECT results.
|
||||
Values are ordered to match the variables list in SparqlQueryResponse.
|
||||
"""
|
||||
values: list[Term | None] = field(default_factory=list)
|
||||
|
||||
@dataclass
|
||||
class SparqlQueryRequest:
|
||||
user: str = ""
|
||||
collection: str = ""
|
||||
query: str = "" # SPARQL query string
|
||||
limit: int = 10000 # Safety limit on results
|
||||
|
||||
@dataclass
|
||||
class SparqlQueryResponse:
|
||||
error: Error | None = None
|
||||
query_type: str = "" # "select", "ask", "construct", "describe"
|
||||
|
||||
# For SELECT queries
|
||||
variables: list[str] = field(default_factory=list)
|
||||
bindings: list[SparqlBinding] = field(default_factory=list)
|
||||
|
||||
# For ASK queries
|
||||
ask_result: bool = False
|
||||
|
||||
# For CONSTRUCT/DESCRIBE queries
|
||||
triples: list[Triple] = field(default_factory=list)
|
||||
|
||||
sparql_query_request_queue = queue('sparql-query', cls='request')
|
||||
sparql_query_response_queue = queue('sparql-query', cls='response')
|
||||
Loading…
Add table
Add a link
Reference in a new issue