comparison gql sparql SPARQL vs GQL This guide compares SPARQL (W3C standard for RDF) with GQL (ISO standard for property graphs). Both are powerful graph query languages, but they're designed for different data models.
Data Model Differences Aspect SPARQL (RDF) GQL (Property Graph) Basic Unit Triple (subject-predicate-object) Nodes and edges with properties Schema Schema-less, uses ontologies Labels and property types Identity IRIs (URIs) Internal IDs Properties Reified as triples First-class attributes Multi-values Multiple triples Arrays/lists
Query Syntax Comparison Finding Entities Finding Relationships Filtering Optional Matches Aggregations Path Traversal Union Queries Feature Comparison Feature SPARQL GQL Pattern Matching Triple patterns Node/edge patterns Path Expressions Property paths (+, *, ?) Variable-length patterns (*1..5) Negation MINUS, NOT EXISTS NOT, WHERE NOT Subqueries Full support Full support Aggregation GROUP BY, HAVING WITH, HAVING Updates SPARQL Update (INSERT/DELETE) INSERT, SET, DELETE Federated Queries SERVICE keyword Not standard Named Graphs GRAPH keyword Limited support
When to Use Each Use SPARQL When: Working with RDF/Linked Data Need semantic reasoning (RDFS/OWL inference) Querying knowledge graphs with ontologies Federated queries across multiple endpoints Data follows W3C standards (Dublin Core, FOAF, Schema.org) Use GQL When: Working with property graph data Need intuitive pattern matching syntax Building application databases Relationships have properties (weights, timestamps) Prefer ASCII-art style query patterns Grafeo Support Grafeo supports both query languages:
// Enable both features
[ dependencies ]
grafeo - engine = { version = "0.1" , features = [ "gql" , "sparql" ] }
Aspect SPARQL GQL Index Usage SPO, POS, OSP indexes Node/edge/property indexes Join Strategy Hash/merge joins on variables Pattern-based joins Path Queries Optimized for transitive closure Optimized for bounded paths Cardinality Triple-based estimation Node/edge-based estimation
Migration Tips SPARQL to GQL Replace triple patterns with node/edge patterns Convert FILTER to WHERE clauses Replace property paths with variable-length patterns Map IRIs to node labels and properties GQL to SPARQL Define appropriate prefixes for your domain Model node properties as separate triples Convert edge patterns to predicate URIs Use OPTIONAL for optional relationships Further Reading