Skip to content

trickle-labs/rs-polygraph

Repository files navigation

rs-polygraph

rs-polygraph is a high-performance Rust library that transpiles graph query languages to SPARQL. It transpiles openCypher and ISO GQL queries into SPARQL 1.1 (and SPARQL-star) algebra.

By providing a plug-and-play translation layer, rs-polygraph enables any SPARQL-compliant engine—such as Oxigraph, Apache Jena, or Ontotext GraphDB—to support modern property graph query standards without re-implementing their core execution logic.

Key Features

  • Multi-Language Support: Support for both the widely-used openCypher and the emerging ISO GQL standards.
  • Engine Agnostic: Emits standard SPARQL 1.1 Query Algebra using Spargebra.
  • RDF-star Ready: Supports high-efficiency edge property mapping via RDF-star/SPARQL-star, with fallback to standard reification for legacy engines.
  • Rust Native: Zero-cost abstractions and memory safety, perfect for embedding directly into database kernels.

Project Structure

The library is modularized to separate parsing from translation logic:

  • polygraph::parser: Leverages pest to generate a clean Abstract Syntax Tree (AST).
  • polygraph::translator: The core visitor-based logic that transforms Property Graph patterns into RDF triple patterns.
  • polygraph::lqa: Logical Query Algebra — a typed intermediate representation (Phase 3+) that factors openCypher semantics independently of SPARQL.
  • polygraph::target: Trait-based interface for easy integration with different SPARQL backends.

ISO GQL Support

GQL queries are handled via parse-time normalization to openCypher equivalents:

  • (n IS Label)(n:Label) (IS predicate)
  • (n IS Label1 & Label2)(n:Label1:Label2) (multi-label)
  • -[r IS KNOWS]->-[r:KNOWS]-> (IS edge type)
  • FILTER exprWHERE expr
  • NEXTWITH *

This design ensures GQL queries automatically benefit from the same semantic rules and correctness guarantees as openCypher without duplicating translation logic. At present, GQL support covers the ISO 39075 read-query subset that maps to openCypher semantics; advanced GQL constructs (quantified path patterns, full label expression trees) are future work.

Compliance

The project aims for full compliance with the openCypher TCK (Technology Compatibility Kit). We verify our transpilation by running TCK Gherkin scenarios against a reference SPARQL implementation to ensure semantic equivalence.

Usage

use polygraph::{Transpiler, TargetEngine};

let cypher = "MATCH (p:Person {name: 'Alice'})-[:KNOWS]->(friend) RETURN friend.name";

// Transpile to a SPARQL string or Algebra object
let sparql = Transpiler::to_sparql(cypher, TargetEngine::Oxigraph)?;

println!("Transpiled SPARQL:\n{}", sparql);

About

Transpile openCypher and ISO GQL queries to SPARQL 1.1 algebra for any RDF store.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors