pub struct SchemaRegistry { /* private fields */ }Expand description
Maps Cypher query strings to their expected Arrow return schemas.
§Two modes
Auto-string (default) — leave the registry empty or only register the
queries you care about. Unregistered queries fall back to an all-Utf8
schema inferred from FalkorDB’s response header at query time.
Registered (typed) — pre-declare the schema so columns like _gar_id,
src, and dst come back as Int64 instead of strings. Use the
convenience helpers register_vertex_query and register_edge_query
for the common cases, or register for full control.
§Example — minimal setup (auto-string only)
use std::sync::Arc;
use graphar_flight::SchemaRegistry;
// An empty registry is valid; all queries use auto-string mode.
let registry = Arc::new(SchemaRegistry::new());§Example — typed vertex + edge schemas
use std::sync::Arc;
use graphar_flight::SchemaRegistry;
let registry = Arc::new(SchemaRegistry::new());
// _gar_id → Int64, extra columns → Utf8.
registry.register_vertex_query(
"MATCH (n:Person) RETURN n._gar_id AS _gar_id, n.name, n.age",
&["name", "age"],
);
// src + dst → Int64, extra columns → Utf8.
registry.register_edge_query(
"MATCH (a:Person)-[r:KNOWS]->(b:Person) \
RETURN a._gar_id AS src, b._gar_id AS dst, r.since",
&["since"],
);Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
pub fn new() -> Self
Sourcepub fn register(&self, key: impl Into<String>, schema: SchemaRef) -> &Self
pub fn register(&self, key: impl Into<String>, schema: SchemaRef) -> &Self
Register an arbitrary schema under key. Overwrites any existing entry.
Use this when you need full control over column types. For the common
vertex / edge patterns prefer register_vertex_query and
register_edge_query.
use std::sync::Arc;
use graphar_flight::SchemaRegistry;
use arrow_schema::{DataType, Field, Schema};
let registry = SchemaRegistry::new();
registry.register(
"MATCH (n:Person) RETURN n._gar_id AS _gar_id, n.name, n.age",
Arc::new(Schema::new(vec![
Field::new("_gar_id", DataType::Int64, false),
Field::new("name", DataType::Utf8, true),
Field::new("age", DataType::Int64, true), // typed!
])),
);Sourcepub fn register_vertex_query(&self, query: &str, extra_cols: &[&str]) -> &Self
pub fn register_vertex_query(&self, query: &str, extra_cols: &[&str]) -> &Self
Register a vertex query schema.
Adds _gar_id: Int64 (non-nullable) as the first column, then appends
each name in extra_cols as a nullable Utf8 column.
The query string must exactly match what the Flight SQL client sends.
By convention, the RETURN clause should alias the internal ID as
_gar_id and list the extra columns in the same order as extra_cols.
§Example
use std::sync::Arc;
use graphar_flight::SchemaRegistry;
let registry = SchemaRegistry::new();
// Person vertices — id as Int64, everything else as Utf8.
registry.register_vertex_query(
"MATCH (n:Person) RETURN n._gar_id AS _gar_id, n.name, n.city",
&["name", "city"],
);
// No extra properties — only _gar_id.
registry.register_vertex_query(
"MATCH (n:Company) RETURN n._gar_id AS _gar_id",
&[],
);Sourcepub fn register_edge_query(&self, query: &str, extra_cols: &[&str]) -> &Self
pub fn register_edge_query(&self, query: &str, extra_cols: &[&str]) -> &Self
Register an edge query schema.
Adds src: Int64 and dst: Int64 (both non-nullable) as the first two
columns, then appends each name in extra_cols as a nullable Utf8 column.
The RETURN clause should alias the source _gar_id as src and the
destination _gar_id as dst, matching GraphAr’s internal IDs.
§Example
use std::sync::Arc;
use graphar_flight::SchemaRegistry;
let registry = SchemaRegistry::new();
// Edges with no properties — just src + dst.
registry.register_edge_query(
"MATCH (a:Person)-[:FOLLOWS]->(b:Person) \
RETURN a._gar_id AS src, b._gar_id AS dst",
&[],
);
// Edges with a string property.
registry.register_edge_query(
"MATCH (a:Person)-[r:KNOWS]->(b:Person) \
RETURN a._gar_id AS src, b._gar_id AS dst, r.since",
&["since"],
);
// Multiple edge properties.
registry.register_edge_query(
"MATCH (a:Person)-[r:RATED]->(b:Movie) \
RETURN a._gar_id AS src, b._gar_id AS dst, r.score, r.review",
&["score", "review"],
);Sourcepub fn register_named(
&self,
name: impl Into<String>,
query: impl Into<String>,
schema: SchemaRef,
) -> &Self
pub fn register_named( &self, name: impl Into<String>, query: impl Into<String>, schema: SchemaRef, ) -> &Self
Register a query under a friendly table name.
The schema is stored under query (so direct execution of the Cypher
still works) and name becomes an alias the Flight SQL metadata
surface advertises in GetTables. A generic ADBC/ODBC client can then
SELECT * FROM <name> and the server rewrites it to query.
use graphar_flight::SchemaRegistry;
use std::sync::Arc;
use arrow_schema::{DataType, Field, Schema};
let registry = SchemaRegistry::new();
registry.register_named(
"people",
"MATCH (n:Person) RETURN n._gar_id AS _gar_id, n.name",
Arc::new(Schema::new(vec![
Field::new("_gar_id", DataType::Int64, false),
Field::new("name", DataType::Utf8, true),
])),
);
assert_eq!(
registry.resolve_table("people").as_deref(),
Some("MATCH (n:Person) RETURN n._gar_id AS _gar_id, n.name"),
);Sourcepub fn get(&self, key: &str) -> Option<SchemaRef>
pub fn get(&self, key: &str) -> Option<SchemaRef>
Look up a schema by exact key. Returns None for unregistered queries
(the server then falls back to auto-string mode).
Sourcepub fn name_of(&self, query: &str) -> Option<String>
pub fn name_of(&self, query: &str) -> Option<String>
The friendly table name a Cypher query was registered under, if any.
The inverse of resolve_table: used by per-query authorization so a
policy can name a query by its short table name. Returns None for a
query registered without a name (the caller then keys on the Cypher).
Sourcepub fn resolve_table(&self, ident: &str) -> Option<String>
pub fn resolve_table(&self, ident: &str) -> Option<String>
Resolve a GetTables-style identifier (a friendly name or the Cypher
key itself) to the Cypher query to execute. Returns None when neither
a name alias nor a registered query matches.
Trait Implementations§
Source§impl Clone for SchemaRegistry
impl Clone for SchemaRegistry
Source§fn clone(&self) -> SchemaRegistry
fn clone(&self) -> SchemaRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SchemaRegistry
impl Debug for SchemaRegistry
Source§impl Default for SchemaRegistry
impl Default for SchemaRegistry
Source§fn default() -> SchemaRegistry
fn default() -> SchemaRegistry
Auto Trait Implementations§
impl Freeze for SchemaRegistry
impl RefUnwindSafe for SchemaRegistry
impl Send for SchemaRegistry
impl Sync for SchemaRegistry
impl Unpin for SchemaRegistry
impl UnsafeUnpin for SchemaRegistry
impl UnwindSafe for SchemaRegistry
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request