Skip to main content

SchemaRegistry

Struct SchemaRegistry 

Source
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

Source

pub fn new() -> Self

Source

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!
    ])),
);
Source

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",
    &[],
);
Source

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"],
);
Source

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"),
);
Source

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).

Source

pub fn keys(&self) -> Vec<String>

List all registered query keys.

Source

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).

Source

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.

Source

pub fn tables(&self) -> Vec<(String, SchemaRef)>

Every registered query as (table_name, schema), for the Flight SQL GetTables surface. Named queries report their alias; queries registered without a name report the Cypher string as the table name.

Trait Implementations§

Source§

impl Clone for SchemaRegistry

Source§

fn clone(&self) -> SchemaRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SchemaRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SchemaRegistry

Source§

fn default() -> SchemaRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more