Skip to main content

Module ast

Module ast 

Source
Expand description

rudb’s abstract syntax tree.

The parse tree the matcher produces is DuckDB’s grammar, faithfully. That is the point of it and it is also why nothing downstream should read it: a bump of the vendored grammar is allowed to rename BetweenInLikeExpression, and if the binder is matching on that name then the bump is a rewrite. This module is the boundary. It is ours, it changes when we decide it changes, and transform is the one place that knows both shapes.

Everything is an arena with u32 indices, per spec/04-architecture.md section 4.5. There is no Box and no Vec inside a node. A list of children is a Slice into a side vector, which means a node is a fixed size, the whole tree is a handful of allocations, and walking it is a sequential read rather than a pointer chase per node. It also means an Ast is Clone and Send without any thought, and that a subtree can be addressed by a u32 in a plan or an error without borrowing anything.

The one cost is that you cannot hold a reference to a node and index the arena at the same time, so the code reads a node out by value first. Nodes are small and Copy, so that is a register move.

Structs§

Alter
ALTER TABLE name action or ALTER VIEW name RENAME TO other.
Ast
A parsed statement or script, with every arena it points into.
Attach
ATTACH [OR REPLACE] [IF NOT EXISTS] [DATABASE] path [AS alias] [(options)].
CaseArm
One WHEN a THEN b.
ColumnDef
One column of a CREATE TABLE.
Conflict
ON CONFLICT, INSERT OR REPLACE or INSERT OR IGNORE.
CopyTo
COPY ... TO, which writes what a query answers to a file.
CreateTable
CREATE TABLE name (columns) or CREATE TABLE name AS query.
CreateView
CREATE VIEW name (columns) AS query.
Cte
A WITH name AS MATERIALIZED (query), which is run once and read wherever it is named.
DropTable
DROP TABLE a, b or DROP VIEW a, b.
Index
CREATE [UNIQUE] INDEX name ON table (elements) or DROP INDEX name.
Insert
INSERT INTO name (columns) query.
OrderItem
One entry of an order by list.
Query
A query: a body, plus the modifiers that apply to whatever the body produced.
Schema
CREATE SCHEMA name or DROP SCHEMA name.
Select
One select block.
Sequence
CREATE SEQUENCE name options or DROP SEQUENCE name.
Setting
SET name = value and RESET name.
Slice
A run of items in one of the side vectors.
Target
One entry of a target list.
TypeDef
CREATE TYPE name AS type or DROP TYPE name.
WindowSpec
Everything inside the parentheses of an OVER.

Enums§

AlterAction
What one ALTER TABLE does. A column is named as written.
BinaryOp
An infix operator.
ConflictAction
What happens to a row whose key is already held.
Constraint
One constraint of a CREATE TABLE, by its place in the list of its kind.
Distinct
What the DISTINCT clause of a select said.
Expr
One expression.
JoinKind
Which join.
LiteralKind
Which literal.
Nulls
Null placement in a sort.
Order
Sort direction, with the unwritten case kept apart from the default it resolves to.
Quantifier
Whether a set operator or an aggregate keeps duplicates.
QueryBody
What produces the rows of a query.
Scope
Which copy of a setting a statement means.
SetOp
Which set operator.
Source
One entry in a FROM clause, which is a tree because joins nest.
Statement
One statement.
Transaction
What a transaction statement asks for.
UnaryOp
A prefix or postfix operator.
WindowBound
One end of a window frame.
WindowExclude
Which peers of the current row the frame drops once its bounds have been applied.
WindowUnit
How a window frame measures the distance to its bounds.

Type Aliases§

AlterRef
Index into Ast::alters.
AttachRef
An index into Ast::attaches.
CopyToRef
An index into Ast::copies.
CreateTableRef
An index into Ast::create_tables.
CreateViewRef
An index into Ast::create_views.
DropTableRef
An index into Ast::drop_tables.
ExprRef
An index into Ast::exprs.
IndexRef
Index into Ast::indexes.
InsertRef
An index into Ast::inserts.
QueryRef
An index into Ast::queries.
SchemaRef
Index into Ast::schemas.
SelectRef
An index into Ast::selects.
SequenceRef
Index into Ast::sequences.
SettingRef
An index into Ast::settings.
SourceRef
An index into Ast::sources.
StrRef
An index into Ast::strings.
TypeRef
Index into Ast::types.
WindowRef
An index into Ast::windows.