GQL vs SPARQL¶
Comparing the ISO standard GQL with W3C standard SPARQL.
Grafeo Query Language
Grafeo uses GQL as its query language. SPARQL is not supported. This guide is for users familiar with SPARQL/RDF who want to understand how GQL differs and how to accomplish similar tasks in Grafeo.
Overview¶
| Aspect | GQL | SPARQL |
|---|---|---|
| Standard | ISO/IEC 39075 | W3C Recommendation |
| Data Model | LPG | RDF |
| Pattern Style | ASCII art | Triple patterns |
| Verbosity | Concise | More verbose |
| Learning Curve | Lower | Higher |
Query Comparison¶
Basic Query¶
Relationship Query¶
Path Queries¶
Aggregation¶
Creating Data¶
Key Differences¶
1. Pattern Syntax¶
GQL uses ASCII-art patterns that visually represent the graph:
SPARQL uses triple patterns:
2. Properties on Relationships¶
GQL supports properties on relationships natively:
SPARQL requires reification:
3. Schema¶
- GQL: Schema-optional, validation at application level
- SPARQL: Uses RDFS/OWL ontologies for schema and reasoning
4. Identity¶
- GQL: Internal IDs, application-managed
- SPARQL: URIs enable global identity and linking
Migration Considerations¶
From SPARQL to GQL¶
- Map RDF types to LPG labels
- Map predicates to edge types or properties
- Handle reification explicitly
- Adapt property path syntax
From GQL to SPARQL¶
- Define URI scheme for nodes
- Create vocabulary for edge types
- Handle edge properties with reification
- Adapt pattern matching syntax
When to Use Each¶
| Use Case | Recommended |
|---|---|
| Application database | GQL |
| Knowledge graph | Either |
| Linked Data | SPARQL |
| Data integration | SPARQL |
| Performance-critical | GQL |
| Developer productivity | GQL |