Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/kleene

crates/kleene-gql/README.md

kleene-gql

GQL (ISO/IEC 39075) read queries on kleene: MATCH node and edge patterns with labels, WHERE comparisons joined by AND, RETURN [DISTINCT] ... [LIMIT n], and quantified edges (-[:CALLS]->*, ->+, {m,n}; the Cypher form -[:CALLS*]-> too). A Catalog names the relation behind each node label, edge label and property; the query lowers onto kleene-plan, where a quantified edge runs as a graph walk (BFS or closure), never as recursive joins.

Part of kleene.

use kleene_gql::{Catalog, query};
use kleene_plan::{Engine, Facts, Source};
use kleene_sparse::{CpuBackend, CpuDevice};

let one = |xs: &[u64]| Source::Facts(Facts::from_rows(1, xs.iter().map(|&x| [x])).unwrap());
let two = |xs: &[(u64, u64)]| {
    Source::Facts(Facts::from_rows(2, xs.iter().map(|&(a, b)| [a, b])).unwrap())
};
let mut c = Catalog::new();
c.label("Func", one(&[0, 1, 2, 3]))
    .edge("CALLS", two(&[(0, 1), (1, 2), (3, 0)]));

// Threads: the rules' joins and the graph kernels run on the device's own workers
// (`CpuDevice::default()` takes every core), not on tokio. Only table reads through
// DataFusion run on the runtime you bring: give it more than one thread.
let engine = Engine::<CpuBackend>::new(CpuDevice::default());
let text = "MATCH (a)-[:CALLS]->+(b) WHERE a = 1 RETURN DISTINCT b";
let rt = tokio::runtime::Builder::new_multi_thread().build()?;
let t = rt.block_on(query(&engine, &c, text))?;
assert_eq!(t.columns, ["b"]);
assert_eq!(t.rows, [[2]]);
# Ok::<(), Box<dyn std::error::Error>>(())

Licence

MIT or Apache-2.0, at your option.