Lance Graph Query Engine
A graph query engine for Lance datasets with Cypher syntax support. This crate enables querying Lance's columnar datasets using familiar graph query patterns, interpreting tabular data as property graphs.
Features
- Cypher query parsing and AST construction
- Graph configuration for mapping Lance tables to nodes and relationships
- Semantic validation with typed
GraphErrordiagnostics - Pluggable execution strategies (DataFusion planner by default, simple executor, Lance Native placeholder)
- Async query execution that returns Arrow
RecordBatchresults - JSON-serializable parameter binding for reusable query templates
- Logical plan debugging via
CypherQuery::explain
Quick Start
use HashMap;
use Arc;
use ;
use ;
use ;
let config = builder
.with_node_label
.with_relationship
.build?;
let schema = new;
let batch = try_new?;
let mut tables = new;
tables.insert;
let query = new?
.with_config
.with_parameter;
let runtime = new?;
// Use default DataFusion-based execution
let result = runtime.block_on?;
// Opt in to the simple executor if you only need projection/filter support.
let simple = runtime.block_on?;
The query expects a HashMap<String, RecordBatch> keyed by the labels and relationship types referenced in the Cypher text. Each record batch should expose the columns configured through GraphConfig (ID fields, property fields, etc.). Relationship mappings also expect a batch keyed by the relationship type (for example KNOWS) that contains the configured source/target ID columns and any optional property columns.
Configuring Graph Mappings
Graph mappings are declared with GraphConfig::builder():
use ;
let config = builder
.with_node_label
.with_relationship
.build?;
For finer control, build NodeMapping and RelationshipMapping instances explicitly:
let person = new
.with_properties
.with_filter;
let knows = new
.with_properties;
let config = builder
.with_node_mapping
.with_relationship_mapping
.build?;
Executing Cypher Queries
CypherQuery::newparses Cypher text into the internal AST.with_configattaches the graph configuration used for validation and execution.with_parameter/with_parametersbind JSON-serializable values that can be referenced as$paramin the Cypher text.executeis asynchronous and returns an ArrowRecordBatch. PassNonefor the default DataFusion planner orSome(ExecutionStrategy::Simple)for the single-table executor.ExecutionStrategy::LanceNativeis reserved for future native execution support and currently errors.explainis asynchronous and returns a formatted string containing the graph logical plan alongside the DataFusion logical and physical plans.
Queries with a single MATCH clause containing a path pattern are planned as joins using the provided mappings. Other queries can opt into the single-table projection/filter pipeline via ExecutionStrategy::Simple when DataFusion's planner is unnecessary.
A builder (CypherQueryBuilder) is also available for constructing queries programmatically without parsing text.
Supported Cypher Surface
- Node patterns
(:Label)with optional variables. - Relationship patterns with fixed direction and type, including multi-hop paths.
- Property comparisons against literal values with
AND/OR/NOT/EXISTS. - RETURN lists of property accesses, optional
DISTINCT,ORDER BY,SKIP(offset), andLIMIT. - Positional and named parameters (e.g.
$min_age).
Basic aggregations like COUNT are supported. Optional matches and subqueries are parsed but not executed yet.
Crate Layout
ast– Cypher AST definitions.parser– Nom-based Cypher parser.semantic– Lightweight semantic checks on the AST.logical_plan– Builders for graph logical plans.datafusion_planner– DataFusion-based execution planning.simple_executor– Simple single-table executor.config– Graph configuration types and builders.query– High levelCypherQueryAPI and runtime.error–GraphErrorand result helpers.source_catalog– Helpers for looking up table metadata.
Error Handling
Most APIs return Result<T, GraphError>. Errors include parsing failures, missing mappings, and execution issues surfaced from DataFusion.
Testing
Benchmarks
See the repository root README.md for benchmark setup, run commands, and report locations.
Python Bindings
See the Python package docs for setup and development:
- Python package README:
python/README.md - Runnable examples (from repo root):
examples/README.md
License
Apache-2.0. See the top-level LICENSE file for details.