Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust Crate Structure

SQE is organized as a Cargo workspace with 11 crates. Each crate has a focused responsibility.

Dependency Graph

graph TB
    SERVER["sqe-server binary<br/>(in sqe-coordinator)"]
    CLI["sqe-cli"]

    SERVER --> COORD["sqe-coordinator"]
    SERVER --> WORKER["sqe-worker"]

    COORD --> AUTH["sqe-auth"]
    COORD --> CAT["sqe-catalog"]
    COORD --> SQL["sqe-sql"]
    COORD --> POLICY["sqe-policy"]
    COORD --> PLANNER["sqe-planner"]
    COORD --> METRICS["sqe-metrics"]
    COORD --> TRINO["sqe-trino-compat"]
    COORD --> CORE["sqe-core"]

    WORKER --> PLANNER
    WORKER --> METRICS
    WORKER --> CORE

    AUTH --> CORE
    CAT --> CORE
    SQL --> CORE
    POLICY --> CORE
    PLANNER --> CORE
    METRICS --> CORE
    TRINO --> CORE

    CLI --> CORE

    style SERVER fill:#6f9,stroke:#333
    style CLI fill:#6f9,stroke:#333

Crate Reference

sqe-core

Shared types used across all crates.

ModuleContents
config.rsSqeConfig and all sub-configs, TOML loading, env var overrides
error.rsSqeError enum (Auth, Catalog, Execution, Config, NotImplemented, Internal)
session.rsSession struct (id, user, tokens, expiry), SessionUser (username, roles)
lib.rsVERSION constant

sqe-auth

Keycloak OIDC authentication.

ModuleContents
authenticator.rsAuthenticator — ROPC grant, token refresh, background refresh task
keycloak.rsKeycloakClient — HTTP calls to Keycloak token endpoint, role extraction
token_cache.rsTokenCache — DashMap of session → cached tokens, expiry tracking

sqe-catalog

Iceberg REST catalog client (wraps iceberg-rust).

ModuleContents
rest_catalog.rsSessionCatalog — per-user catalog with bearer token, namespace/table ops
catalog_provider.rsSqeCatalogProvider — DataFusion CatalogProvider bridge
schema_provider.rsSqeSchemaProvider — DataFusion SchemaProvider for Iceberg namespaces
table_provider.rsIceberg → DataFusion TableProvider
credential_vending.rsExtract S3 credentials from Polaris table load response
iceberg_scan.rsIceberg scan configuration
info_schema.rsVirtual information_schema (tables, schemata, columns)

sqe-sql

SQL parsing and statement classification.

ModuleContents
classifier.rsparse_and_classify(sql)StatementKind, routes all SQL statement types

sqe-policy

Policy enforcement framework (pluggable backend).

ModuleContents
lib.rsPolicyEnforcer trait, PassthroughEnforcer (default no-op)

sqe-planner

Distributed query planning.

ModuleContents
scan_task.rsScanTask — serializable message from coordinator to worker
splitter.rssplit_files() — divide data files across workers

sqe-coordinator

The coordinator: SQL routing, session management, write handling.

ModuleContents
flight_sql.rsSqeFlightSqlService — Arrow Flight SQL server (735 lines)
query_handler.rsQueryHandler — central query routing and execution (596 lines)
session_manager.rsSessionManager — session lifecycle, token refresh integration
worker_registry.rsWorkerRegistry — worker discovery, health checking
catalog_ops.rsDDL operations (DROP TABLE, CREATE/DROP SCHEMA)
write_handler.rsCTAS and INSERT INTO handling
writer.rsParquet file writing to S3
distributed_scan.rsDistributed scan coordination
mode.rsMode enum, resolve_mode() for sqe-server
bin/sqe_server.rsUnified server binary entry point

sqe-worker

Stateless scan executor.

ModuleContents
executor.rsexecute_scan(ScanTask) — read Parquet from S3, return Arrow batches
flight_service.rsWorkerFlightService — Flight server for receiving scan tasks

sqe-cli

Interactive SQL client.

ModuleContents
main.rsCLI argument parsing (clap), REPL loop, auth flow
client.rsSqlClient trait, QueryResult type
flight.rsFlightClient — Flight SQL client with handshake and token auth
http.rsHttpClient — Trino HTTP protocol client
display.rsOutput formatting: ASCII table, CSV, JSON

sqe-metrics

Observability stack.

ModuleContents
lib.rsMetricsRegistry — Prometheus counters, histograms, gauges
server.rsPrometheus HTTP /metrics endpoint (axum)
audit.rsAuditLogger — JSONL audit log writer
otel.rsOpenTelemetry init (traces, metrics, logs via OTLP/gRPC)

sqe-trino-compat

Trino wire protocol compatibility layer.

ModuleContents
server.rsTrino HTTP server (/v1/statement endpoint)
protocol.rsRecordBatch → Trino JSON response serialization
types.rsArrow → Trino type mapping

Key External Dependencies

CrateVersionPurpose
datafusion51Query engine (SQL planning, optimization, execution)
arrow / arrow-flight57Columnar data format and Flight SQL protocol
iceberg / iceberg-catalog-rest0.8Iceberg table format and REST catalog
tonic0.14gRPC framework (Flight SQL server + client)
axum0.8HTTP framework (health, metrics, Trino compat)
tokio1Async runtime
sqlparser0.59SQL parsing
moka0.12Async TTL cache (metadata caching)
clap4CLI argument parsing
tracing0.1Structured logging
opentelemetry0.31Distributed tracing and metrics