Qwiratry — SQL-AST-Qwiratry-Mapping

SQL AST ↔ Qwiratry mapping

Extracted from SQL-AST-Comparison.md §3 (AST object comparison). Side-by-side mapping of SQL constructs to Red, SQL::Abstract, Qwiratry Query AST, RakuAST, and (where both SQL ASTs lack a node) SQL Mapping.

AST object comparison

For each SQL construct, the concrete AST type (or role) each library uses. — = no dedicated node; behaviour may still exist via driver defaults, projection tricks, model metadata, or runtime Raku code.

Qwiratry today is the Query AST (Qwiratry::Operator::* classes, all RakuAST::Node descendants). There is no separate SQL AST yet (planned in TOP plan §12.1). Filters and join conditions are Raku Blocks / callables, not structured expression nodes.

RakuAST column lists compiler AST equivalents only where a row’s SQL-ish construct maps to ordinary Raku expression or statement forms (typically predicates inside mold when blocks). Empty where there is no meaningful RakuAST counterpart at that abstraction level.

SQL Mapping is filled only for rows where both Red and SQL::Abstract have no AST node (—): how that item can still show up in actual SQL (keyword, encode-as-pattern, or “not SQL”).

Represented itemRedSQL::AbstractQwiratryRakuASTSQL Mapping
AST rootRed::AST (role)SQL::Abstract::Expression / SQL::Abstract::Query rolesRakuAST::Node (all Qwiratry::Operator::*::*Operator classes)RakuAST::Node—
Clause chain bagRed::AST::Chained (filter, order, group, limit, offset, table-list)fields on each query class (via SQL::Abstract::Query::Common)Qwiratry::Operator::Capability::ChainedOperator $.subject pipeline——
SELECTRed::AST::SelectSQL::Abstract::Selectcomposed operator pipeline (no Select root); read entry often Qwiratry::Operator::IO::SourceOperator (functionally ≈ SELECT)——
INSERTRed::AST::InsertSQL::Abstract::Insert::Values, SQL::Abstract::Insert::Select, SQL::Abstract::Insert::Defaultswrite sink Qwiratry::Operator::IO::OverwriteDestinationOperator / Destination family (among CREATE/INSERT/UPDATE/DELETE)——
UPDATERed::AST::UpdateSQL::Abstract::Updatewrite sink Qwiratry::Operator::IO::OverwriteDestinationOperator / Destination family (among CREATE/INSERT/UPDATE/DELETE)——
DELETERed::AST::DeleteSQL::Abstract::Deletewrite sink Qwiratry::Operator::IO::OverwriteDestinationOperator / Destination family (among CREATE/INSERT/UPDATE/DELETE)——
UPSERT / ON CONFLICT—SQL::Abstract::Conflicts, SQL::Abstract::Conflict::Update, SQL::Abstract::Conflict::Nothing, SQL::Abstract::Conflict::Target::* on SQL::Abstract::Insert———
UNION / INTERSECT / EXCEPTRed::AST::Union, Red::AST::Intersect, Red::AST::Minus (Red::AST::MultiSelect)SQL::Abstract::Compound on SQL::Abstract::SelectQwiratry::Operator::Set::UnionOperator, Qwiratry::Operator::Set::IntersectionOperator, Qwiratry::Operator::Set::SetDifferenceOperator——
VALUES (inline relation)—SQL::Abstract::Values———
CREATE TABLERed::AST::CreateTable—write sink Qwiratry::Operator::IO::OverwriteDestinationOperator / Destination family (among CREATE/INSERT/UPDATE/DELETE)——
CREATE VIEWRed::AST::CreateView—reusable named join ≈ Qwiratry::Operator::Set::NamedJoinOperator + Qwiratry::Query::NamedJoins (see Named join recall)——
ADD / CHANGE / DROP COLUMNRed::AST::CreateColumn, Red::AST::ChangeColumn, Red::AST::DropColumn—write sink Qwiratry::Operator::IO::OverwriteDestinationOperator / Destination family (schema change / DDL write)——
ADD FOREIGN KEYRed::AST::AddForeignKeyOnTable————
BEGIN / COMMIT / ROLLBACKRed::AST::BeginTransaction, Red::AST::CommitTransaction, Red::AST::RollbackTransaction————
Column referenceRed::Column (also does Red::AST)SQL::Abstract::IdentifierQwiratry::Operator::Navigation::AttributeOperator (⥷); column keys in selectorsRakuAST::Var::Lexical, RakuAST::Postcircumfix::*—
Table referenceRed::Model in Red::AST::Select.of / @.table-listSQL::Abstract::Table::Simple, SQL::Abstract::Table::RenamedQwiratry::Operator::IO::SourceOperator, Qwiratry::Operator::Navigation::ChildOperator on table——
Literal valueRed::AST::ValueSQL::Abstract::Literalvalues in predicate/join Blocks at runtimeRakuAST::IntLiteral, RakuAST::StrLiteral, RakuAST::NumLiteral, …—
Bind placeholderRed::AST::Value / unary·infix $.bindSQL::Abstract::Placeholder—RakuAST::Var::Lexical (in compiled blocks)—
Function callRed::AST::FunctionSQL::Abstract::Functioncalls inside predicate/join BlocksRakuAST::Call::Name, RakuAST::Call::Method, …—
Column alias (AS)projection via map / @.fieldsSQL::Abstract::Expression::RenamedQwiratry::Operator::Set::RenameOperator (ρ)——
* in projectionmodel column expansionSQL::Abstract::StarQwiratry::Operator::Set::ProjectionOperator with columns list = all column keys (expanded before execution); wildcard selectors often use * / WhateverRakuAST::Term::Whatever—
WHERERed::AST on Red::AST::Select/Red::AST::Chained $.filterSQL::Abstract::Conditions on SQL::Abstract::Select $.whereQwiratry::Operator::MapReduce::SelectionOperator (σ, &predicate)RakuAST::Block / expression subtree—
AND / ORRed::AST::AND, Red::AST::ORSQL::Abstract::Op::And, SQL::Abstract::Op::Or (in SQL::Abstract::Conditions)inside &predicate BlockRakuAST::ApplyInfix (&&/`, and/or`)—
NOTRed::AST::NotSQL::Abstract::Op::Notinside &predicate BlockRakuAST::ApplyPrefix (!, not)—
Comparisons (=, <, …)Red::AST::Eq, Red::AST::Lt, Red::AST::Gt, Red::AST::Le, Red::AST::Ge, Red::AST::NeSQL::Abstract::Op::Equals, SQL::Abstract::Op::LessThan, SQL::Abstract::Op::GreaterThan, …inside &predicate BlockRakuAST::ApplyInfix (==, <, >, …)—
LIKERed::AST::LikeSQL::Abstract::Op::Like, SQL::Abstract::Op::NotLikeinside &predicate BlockRakuAST::ApplyInfix (~~) + RakuAST::QuotedRegex, or RakuAST::Call::Method—
IN (value list)Red::AST::InSQL::Abstract::Op::In::ListQwiratry::Operator::Set::ElementOfOperator (∈); also in BlockRakuAST::ApplyInfix (∈, ~~) + list / junction—
IN / EXISTS (subquery)Red::AST::In + nested Red::AST::SelectSQL::Abstract::Op::In::Query, SQL::Abstract::Op::Existsnested operator trees——
BETWEENRed::AST::BetweenSQL::Abstract::Op::Between, SQL::Abstract::Op::NotBetweeninside &predicate BlockRakuAST::ApplyInfix (..) or chained comparisons—
IS NULL / definednessRed::AST::IsDefinedSQL::Abstract::Op::IsNullinside &predicate BlockRakuAST::ApplyPrefix + .defined, or RakuAST::Type::Definedness—
CASERed::AST::CaseSQL::Abstract::Op::Caseinside &predicate BlockRakuAST::Ternary, or RakuAST::Statement::If chain—
CASTRed::AST::CastSQL::Abstract::Op::Castinside &predicate BlockRakuAST::Type::Coercion, RakuAST::Call::Method (.Int, …)—
JSON path opsRed::AST::JsonItem, Red::AST::JsonRemoveItemSQL::Abstract::Op::JSON::GetElem, SQL::Abstract::Op::JSON::GetElemText, SQL::Abstract::Op::JSON::GetPath, SQL::Abstract::Op::JSON::GetPathTextinside &predicate Block; structured JSON via Qwiratry::Operator::IO::ParseOperator / RenderOperator (parse = treat as document; render = serialize back)RakuAST::Postcircumfix::LiteralHashIndex, RakuAST::Postcircumfix::HashIndex—
XML path ops——inside &predicate Block; structured XML via Qwiratry::Operator::IO::ParseOperator / RenderOperator (parse = treat as document; render = serialize back); tree navigation axes often apply—dialect XML/XPath (xpath, XMLEXTRACT, XMLQUERY, …) when the column is treated as a document, not opaque text
Arithmetic / concatRed::AST::Sum, Red::AST::Sub, Red::AST::Mul, Red::AST::Div, Red::AST::Concat, …SQL::Abstract::Op::Plus, SQL::Abstract::Op::Minus, SQL::Abstract::Op::Times, SQL::Abstract::Op::Concat, …inside &predicate BlockRakuAST::ApplyInfix, RakuAST::ApplyPrefix, RakuAST::ApplyPostfix—
Generic operatorRed::AST::Generic::Infix, Red::AST::Generic::Prefix, Red::AST::Generic::Postfixtyped SQL::Abstract::Op::* hierarchyinside &predicate BlockRakuAST::ApplyInfix, RakuAST::ApplyPrefix, RakuAST::ApplyPostfix, RakuAST::ApplyListInfix—
FROM / joined tables@.table-list + primary $.of (Red::Model)SQL::Abstract::Source (SQL::Abstract::Table, SQL::Abstract::Join, …)Qwiratry::Operator::IO::SourceOperator + join operator tree——
JOIN … ONjoin metadata on joined Red::Model entriesSQL::Abstract::Join::OnQwiratry::Operator::Set::InnerJoinOperator, … + Qwiratry::Operator::Set::JoinOperatorNode $.conditionRakuAST::Block (join condition)—
JOIN … USING—SQL::Abstract::Join::Using———
NATURAL / CROSS JOIN—SQL::Abstract::Join::Natural, SQL::Abstract::Join::CrossQwiratry::Operator::Set::NaturalJoinOperator, Qwiratry::Operator::Set::CrossJoinOperator——
Subquery in FROMRed::AST::Select (:sub-select)SQL::Abstract::Source::Querynested operator pipeline——
GROUP BY@.group on Red::AST::Select/Red::AST::ChainedSQL::Abstract::GroupBy— (Qwiratry::Operator::MapReduce::ReduceOperator approximates aggregation only)——
HAVING—SQL::Abstract::Conditions on SQL::Abstract::Select $.havingno dedicated node; same as Qwiratry::Operator::MapReduce::SelectionOperator (σ / grep) applied after grouping/aggregation (WHERE is σ before) — Qwiratry has no first-class GROUP BY, so HAVING is only a pipeline-position distinction——
DISTINCTRed::AST::Function (func<DISTINCT>) in projectionSQL::Abstract::Distinction, SQL::Abstract::Distinction::Columns on SQL::Abstract::Selectno UniqueOperator; not what ReduceOperator (⌿) does (fold → one accumulator). Approximable by reducing into a set, or by set-algebra pipelines, but not first-class DISTINCT——
ORDER BY@.order (Red::AST / Red::Column)SQL::Abstract::OrderBy, SQL::Abstract::Order::ModifierQwiratry::Operator::MapReduce::SortOperator (⇅)——
LIMIT / OFFSETInt on Red::AST::Select/Red::AST::ChainedSQL::Abstract::Limit, SQL::Abstract::Offset———
CTE (WITH)—SQL::Abstract::Common (+ SQL::Abstract::Query::Common $.common)———
Window definition / use—SQL::Abstract::Window::Clauses, SQL::Abstract::Window::Definition, SQL::Abstract::Window::Function———
Row locking (FOR UPDATE, …)Red::LockType on Red::AST::Select $.forSQL::Abstract::Locking, SQL::Abstract::Locking::Clause———
RETURNINGdriver emit context (e.g. "delete-returning")SQL::Abstract::Column::List on DML queries———
String functionsRed::AST::Substring, Red::AST::Index, Red::AST::Lowercase, Red::AST::UppercaseSQL::Abstract::Functioninside BlockRakuAST::Call::Method—
Date/time functionsRed::AST::DateTimePart, Red::AST::DateTimeCoerce, Red::AST::DateTimeNow, Red::AST::DateTimeTodaySQL::Abstract::Function, SQL::Abstract::Currentinside BlockRakuAST::Call::Name, RakuAST::Call::Method—
PK / table constraintsRed::AST::Pk, Red::AST::Constraint—Qwiratry::Table::Catalog, Qwiratry::Table::ForeignKey (metadata, not query nodes)——
SQL commentsRed::AST::Comment, Red::AST::TableComment————
Custom / escape SQL—SQL::Abstract::Expression::Custom———
Map / transform rowsvia map / Red::ResultSeq—Qwiratry::Operator::MapReduce::AggMapOperator (⇶)——
Aggregate / foldvia classify / aggregates—Qwiratry::Operator::MapReduce::ReduceOperator (⌿)——
Projection (column pick)@.fields / mapSQL::Abstract::Column::ListQwiratry::Operator::Set::ProjectionOperator (Π)——
Navigation axes (⪪ ⪫ ⪪⪪ …)——Qwiratry::Operator::Navigation::ChildOperator, Qwiratry::Operator::Navigation::ParentOperator, Qwiratry::Operator::Navigation::DescendantOperator, Qwiratry::Operator::Navigation::AncestorOperator, Qwiratry::Operator::Navigation::FollowingSiblingOperator, Qwiratry::Operator::Navigation::PrecedingSiblingOperator, Qwiratry::Operator::Navigation::FollowingOperator, Qwiratry::Operator::Navigation::PrecedingOperator, Qwiratry::Operator::Navigation::RootOperator (⇤)—FK follow ≈ joins; hierarchy ≈ recursive CTE / CONNECT BY; siblings/following ≈ LAG/LEAD or ordered self-joins (not XPath-style first-class axes)
Equijoin / outer / semijoin / antijoinvia model join metadataSQL::Abstract::Join::* variantsQwiratry::Operator::Set::EquijoinOperator, Qwiratry::Operator::Set::LeftOuterJoinOperator, Qwiratry::Operator::Set::RightOuterJoinOperator, Qwiratry::Operator::Set::FullOuterJoinOperator, Qwiratry::Operator::Set::LeftSemijoinOperator, Qwiratry::Operator::Set::RightSemijoinOperator, Qwiratry::Operator::Set::LeftAntijoinOperator, Qwiratry::Operator::Set::RightAntijoinOperator——
Named join recall (▵)——Qwiratry::Operator::Set::NamedJoinOperator + Qwiratry::Query::NamedJoins registry—reusable named join ≈ CREATE VIEW (or a named CTE) wrapping the join (see CREATE VIEW)
Symmetric difference (⊖)——Qwiratry::Operator::Set::SymmetricDifferenceOperator—(A EXCEPT B) UNION (B EXCEPT A) (or EXCEPT ALL variants)
Membership / subset / identity (excluding IN/ElementOf)——Qwiratry::Operator::Set::ContainsOperator, Qwiratry::Operator::Set::SubsetOperator, Qwiratry::Operator::Set::SubsetOrEqualOperator, Qwiratry::Operator::Set::IdentityOperatorRakuAST::ApplyInfix (∋, (<=), eqv, …)partial: set equality/containment via EXCEPT / INTERSECT / EXISTS / row comparisons (no first-class ⊆/≡)
Relational division (÷)——Qwiratry::Operator::Set::DivisionOperator—classic algebra; expressible with nested NOT EXISTS / grouping — no DIVIDE keyword
Power set (𝒫 / ℘)——Qwiratry::Operator::Set::PowerSetOperator—not SQL
Operator capability roles——Qwiratry::Operator::Capability::OperatorBase, Qwiratry::Operator::Capability::ChainedOperator, Qwiratry::Operator::Capability::LazyEvaluatedOperator, Qwiratry::Operator::Capability::EagerEvaluatedOperator, Qwiratry::Operator::Capability::MapReduceOperator, Qwiratry::Operator::Capability::SetOperator, Qwiratry::Operator::Capability::NavigationOperator, Qwiratry::Operator::Set::JoinOperatorNode, Qwiratry::Operator::Capability::IOOperator, Qwiratry::Operator::Capability::FormatOperator, Qwiratry::Operator::Capability::LocationOperator, …—not SQL (Walker/operator metadata)

Red spreads SELECT clauses across Red::AST::Select and a linked Red::AST::Chained bag on Red::ResultSeq; Abstract keeps them as typed fields on SQL::Abstract::Select (and siblings). Red joins are not separate AST nodes — joined tables appear as Red::Model-shaped entries in @.table-list with join type/on supplied via model metaclass. Abstract models joins explicitly as SQL::Abstract::Join::* implementing SQL::Abstract::Source.

Qwiratry expresses queries as a tree of operator nodes chained by Qwiratry::Operator::Capability::ChainedOperator.subject, with σ/Π/ρ and join operators covering much of relational algebra plus navigation and I/O layers. Expression-level SQL (comparisons, CASE, CAST, …) lives in compiled Raku blocks today rather than in the Query AST itself; the RakuAST column shows what those blocks lower to when extracted from mold source.

Type-name prefixes in the table: Red::*, SQL::Abstract::* (nested in the SQL::Abstract unit class), Qwiratry::Operator::* / Qwiratry::Table::* / Qwiratry::Query::*, and RakuAST::*.

Qwiratry v0.11.0

Declarative query and data-walking architecture for Raku, with transformers, molds, walkers, I/O pipelines, and aggregate functions.

Authors

  • Tim Nelson

License

Dependencies

SlangifyImplementation::Loader:ver<0.0.9+>Glob::Grammar

Test Dependencies

Provides

  • Qwiratry
  • Qwiratry::Aggregate::AggSub
  • Qwiratry::Aggregate::AggSub::Compiler
  • Qwiratry::Aggregate::Avg
  • Qwiratry::Aggregate::BodyRewrite
  • Qwiratry::Aggregate::Count
  • Qwiratry::Aggregate::DenseRank
  • Qwiratry::Aggregate::Driver
  • Qwiratry::Aggregate::Rank
  • Qwiratry::Aggregate::Sum
  • Qwiratry::AggregateFunction
  • Qwiratry::Context
  • Qwiratry::DatabaseStorage
  • Qwiratry::DatabaseStorage::CSVdemo
  • Qwiratry::DatabaseStorage::Location
  • Qwiratry::DatabaseStorage::Location::Tree
  • Qwiratry::DatabaseStorage::Memory
  • Qwiratry::FieldMode
  • Qwiratry::Format
  • Qwiratry::Format::Base
  • Qwiratry::Format::CSVdemo
  • Qwiratry::Format::HalfHuman
  • Qwiratry::Format::JSONdemo
  • Qwiratry::Format::NDJSONdemo
  • Qwiratry::Format::Textish::RenderWalkable
  • Qwiratry::Implementation::Loader
  • Qwiratry::Location
  • Qwiratry::Location::Base
  • Qwiratry::Location::File
  • Qwiratry::Mold
  • Qwiratry::Mold::Compiler
  • Qwiratry::Mold::Registry
  • Qwiratry::Mold::Slang
  • Qwiratry::MovingFrameAggregateFunction
  • Qwiratry::Operator::Capability
  • Qwiratry::Operator::IO
  • Qwiratry::Operator::MapReduce
  • Qwiratry::Operator::Navigation
  • Qwiratry::Operator::Set
  • Qwiratry::Query::Evaluator::Eager
  • Qwiratry::Query::Evaluator::Filter
  • Qwiratry::Query::Evaluator::Join
  • Qwiratry::Query::Evaluator::Lazy
  • Qwiratry::Query::Evaluator::MapReduce
  • Qwiratry::Query::Evaluator::Navigation
  • Qwiratry::Query::Evaluator::Relational
  • Qwiratry::Query::Evaluator::Row
  • Qwiratry::Query::Evaluator::Set
  • Qwiratry::Query::Evaluator::Union
  • Qwiratry::Query::Extract
  • Qwiratry::Query::NamedJoins
  • Qwiratry::Query::RelationCommon
  • Qwiratry::Query::Runtime
  • Qwiratry::Query::Selector
  • Qwiratry::Query::Slang
  • Qwiratry::Query::Slang::Ops
  • Qwiratry::Query::Slang::Topic
  • Qwiratry::Query::Specificity
  • Qwiratry::Query::Topic
  • Qwiratry::QueryCursor
  • Qwiratry::QueryIterator
  • Qwiratry::QueryMatch
  • Qwiratry::Setup
  • Qwiratry::Singleton
  • Qwiratry::Strategy
  • Qwiratry::Strategy::ControlSignal
  • Qwiratry::Strategy::FinishResult
  • Qwiratry::Strategy::RewriteSpec
  • Qwiratry::Strategy::Traversal
  • Qwiratry::Suggest
  • Qwiratry::TaOP
  • Qwiratry::Table
  • Qwiratry::Table::Schema
  • Qwiratry::Transformer
  • Qwiratry::Transformer::Copy
  • Qwiratry::Transformer::TreeRewrite
  • Qwiratry::Tree::Navigator
  • Qwiratry::Tree::Navigator::Base
  • Qwiratry::Tree::Navigator::Filesystem
  • Qwiratry::Tree::Navigator::Match
  • Qwiratry::Tree::Navigator::RakuAST
  • Qwiratry::Tree::Replace
  • Qwiratry::Walker
  • Qwiratry::Walker::Capabilities
  • Qwiratry::Walker::Factory
  • Qwiratry::Walker::Implementation::Table
  • Qwiratry::Walker::Implementation::Tree
  • Qwiratry::Walker::Implementation::TreeWithPath
  • Qwiratry::Walker::Master
  • Qwiratry::Walker::Providing
  • TypedIterator
  • WalkCursor
  • X::Qwiratry

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.