Expand description
§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:
-
SELECTwith column list or* -
FROMsingle table orJOIN(INNER, LEFT) -
WHEREwith comparison predicates (=,<,>,<=,>=,IN) -
ORDER BY(ascending/descending) -
LIMIT -
GROUP BYwith aggregates (COUNT,SUM,AVG,MIN,MAX) -
HAVINGwith 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
)?;Modules§
- dml_
planner - AUDIT-2026-04 S3.1 — translate parsed DML AST into the wire-event
payloads that
kimberlite-kernel’sCommand::Insert/Command::Update/Command::Deletecarry asrow_data. - explain
- EXPLAIN renderer for query plans.
- information_
schema information_schemavirtual tables.- key_
encoder - Lexicographic key encoding for B+tree lookups.
- rbac_
filter - RBAC query filtering and rewriting.
- window
- AUDIT-2026-04 S3.2 — SQL window functions.
Structs§
- Column
Def - Definition of a table column.
- Column
Name - SQL column name.
- Index
Def - Definition of a secondary index on a table.
- Parsed
Alter Table - Parsed ALTER TABLE statement.
- Parsed
Column - Parsed column definition.
- Parsed
Create Index - Parsed CREATE INDEX statement.
- Parsed
Create Mask - Parsed
CREATE MASK <name> ON <table>.<column> USING <strategy>statement. - Parsed
Create Table - Parsed CREATE TABLE statement.
- Parsed
Create User - Parsed CREATE USER statement.
- Parsed
Cte - A Common Table Expression (CTE) parsed from a WITH clause.
- Parsed
Delete - Parsed DELETE statement.
- Parsed
Grant - Parsed GRANT statement.
- Parsed
Insert - Parsed INSERT statement.
- Parsed
Select - Parsed SELECT statement.
- Parsed
SetClassification - Parsed
ALTER TABLE <t> MODIFY COLUMN <c> SET CLASSIFICATION '<class>'. - Parsed
Union - Parsed UNION / UNION ALL statement.
- Parsed
Update - Parsed UPDATE statement.
- Prepared
Query - A prepared (planned) query ready for execution.
- Query
Engine - Query engine for executing SQL against a projection store.
- Query
Result - Result of executing a query.
- Schema
- Schema registry mapping SQL names to store types.
- Schema
Builder - Builder for constructing schemas fluently.
- Table
Def - Definition of a table in the schema.
- Table
Name - SQL table name.
Enums§
- Data
Type - SQL data types supported by the query engine.
- Having
Condition - A condition in the HAVING clause.
- Having
Op - Comparison operators for HAVING conditions.
- Parsed
Statement - Top-level parsed SQL statement.
- Predicate
- A comparison predicate from the WHERE clause.
- Predicate
Value - A value in a predicate (literal or parameter reference).
- Query
Error - Errors that can occur during query parsing and execution.
- Time
Travel - Time-travel coordinate extracted from a SQL string.
- Value
- A typed SQL value.
Functions§
- execute
- Executes a query plan against the current store state.
- extract_
at_ offset - Extracts
AT OFFSET <n>from a SQL string. - extract_
time_ travel - Extracts a
TimeTravelcoordinate from a SQL string, covering bothAT OFFSET <n>and the SQL:2011 temporal formsFOR SYSTEM_TIME AS OF '<iso8601>'andAS OF '<iso8601>'. - parse_
statement - Parses a SQL statement string into a
ParsedStatement. - plan_
query - Plans a parsed SELECT statement.
- try_
parse_ custom_ statement - Attempts to parse custom SQL extensions that
sqlparserdoes not support.