kimberlite-query 0.4.2

SQL query layer for Kimberlite projections
Documentation

kmb-query: SQL query layer for Kimberlite projections

This crate provides a minimal SQL query engine for compliance lookups against the projection store.

SQL Subset

Supported SQL features:

  • SELECT with column list or *

  • FROM single table or JOIN (INNER, LEFT)

  • WHERE with comparison predicates (=, <, >, <=, >=, IN)

  • ORDER BY (ascending/descending)

  • LIMIT

  • GROUP BY with aggregates (COUNT, SUM, AVG, MIN, MAX)

  • HAVING with aggregate filtering

  • UNION / UNION ALL

  • DISTINCT

  • ALTER TABLE (ADD COLUMN, DROP COLUMN)

  • Parameterized queries ($1, $2, ...)

  • WITH (Common Table Expressions / CTEs)

  • Subqueries in FROM and JOIN (SELECT * FROM (SELECT ...) AS t)

Not yet supported:

  • WITH RECURSIVE
  • Window functions

Usage

use kimberlite_query::{QueryEngine, Schema, SchemaBuilder, ColumnDef, DataType, Value};
use kimberlite_store::{BTreeStore, TableId};

// Define schema
let schema = SchemaBuilder::new()
    .table(
        "users",
        TableId::new(1),
        vec![
            ColumnDef::new("id", DataType::BigInt).not_null(),
            ColumnDef::new("name", DataType::Text).not_null(),
        ],
        vec!["id".into()],
    )
    .build();

// Create engine
let engine = QueryEngine::new(schema);

// Execute query
let mut store = BTreeStore::open("data/projections")?;
let result = engine.query(&mut store, "SELECT * FROM users WHERE id = $1", &[Value::BigInt(42)])?;

Point-in-Time Queries

For compliance, you can query at a specific log position:

let result = engine.query_at(
    &mut store,
    "SELECT * FROM users WHERE id = 1",
    &[],
    Offset::new(1000),  // Query state as of log position 1000
)?;