feat: Unified Query AST + Multi-Language Execution Engine#9
Merged
Conversation
…ation Implements the core architecture from RFC issue #7: - Unified AST types (Query, SelectQuery, Expression, etc.) supporting SELECT, INSERT, UPDATE, DELETE, CTEs, window functions, subqueries, set operations, JSON access, and all standard SQL constructs - SQL parser (SQL → AST) powered by sqlparser crate with PostgreSQL dialect - SQL compiler (AST → SQL) for round-trip compilation back to PostgreSQL - Language adapter traits (QueryLanguageAdapter, DSLAdapter) for multi-language input support with built-in PostgreSQL adapter - Optimization pass infrastructure with composable transform pipeline and built-in redundant nesting removal pass - Query analysis engine for structural introspection (joins, CTEs, aggregations, window functions, subqueries, etc.) - Plugin architecture (QueryPlugin trait, PluginRegistry) for extensible adapters, optimizers, and DSL integrations - 65 unit tests covering parsing, compilation, round-trips, optimization, analysis, adapters, and plugin system Closes #7 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the foundational architecture from RFC #7 — the Unified Query AST and Multi-Language Execution Engine for pgrsql.
This PR introduces a complete
src/ast/module with the following layers:Core AST Types (
types.rs)Queryenum — top-level representation for SELECT, INSERT, UPDATE, DELETE, CTEs, and raw SQL passthroughSelectQuery— full SELECT support including DISTINCT, projections, FROM, JOINs, WHERE, GROUP BY, HAVING, WINDOW, ORDER BY, LIMIT/OFFSET, and set operations (UNION/INTERSECT/EXCEPT)Expressionenum — recursive expression tree supporting columns, literals, binary/unary ops, function calls, aggregates, window functions, CASE, subqueries, EXISTS, IN, BETWEEN, IS NULL, CAST, arrays, JSON access, type casts, and parametersJoin,TableRef,WindowSpec,CTE— complete relational algebra primitivesSQL Parser (
parser.rs)sqlparsercrate with PostgreSQL dialectSQL Compiler (
compiler.rs)SQL → AST → SQL(verified by tests)Language Adapter Layer (
adapter.rs)QueryLanguageAdaptertrait — for parsing raw query languages (SQL dialects)DSLAdaptertrait — for Domain-Specific Languages that compile to our ASTAdapterRegistry— manages multiple adapters with auto-detectionPostgresAdapterregistered by defaultOptimization Infrastructure (
optimizer.rs)OptimizationPasstrait — pure transformation passes over the ASTOptimizer— composable pipeline of ordered passesanalyze_query()— structural introspection returningQueryAnalysis(detects joins, CTEs, aggregation, window functions, subqueries, set operations, JSON ops)RemoveRedundantNestingpassPlugin Architecture (
plugin.rs)QueryPlugintrait — register capabilities at startupPluginRegistry— central registry for adapters, DSLs, and optimization passesArchitecture
Test plan
cargo fmtapplied🤖 Generated with Claude Code