pub struct Ast {Show 35 fields
pub statements: Vec<Statement>,
pub queries: Vec<Query>,
pub query_spans: Vec<Span>,
pub selects: Vec<Select>,
pub exprs: Vec<Expr>,
pub expr_spans: Vec<Span>,
pub sources: Vec<Source>,
pub strings: Vec<String>,
pub parts: Vec<StrRef>,
pub expr_lists: Vec<ExprRef>,
pub source_lists: Vec<SourceRef>,
pub targets: Vec<Target>,
pub order_items: Vec<OrderItem>,
pub case_arms: Vec<CaseArm>,
pub create_tables: Vec<CreateTable>,
pub constraints: Vec<Constraint>,
pub create_views: Vec<CreateView>,
pub drop_tables: Vec<DropTable>,
pub schemas: Vec<Schema>,
pub sequences: Vec<Sequence>,
pub types: Vec<TypeDef>,
pub alters: Vec<Alter>,
pub indexes: Vec<Index>,
pub inserts: Vec<Insert>,
pub settings: Vec<Setting>,
pub attaches: Vec<Attach>,
pub column_defs: Vec<ColumnDef>,
pub name_lists: Vec<Slice>,
pub rows: Vec<Slice>,
pub windows: Vec<WindowSpec>,
pub ctes: Vec<Cte>,
pub cte_lists: Vec<u32>,
pub named_args: Vec<(ExprRef, Slice)>,
pub array_lists: Vec<ExprRef>,
pub aggregate_orders: Vec<(ExprRef, Slice)>,
}Expand description
A parsed statement or script, with every arena it points into.
Cheap to clone, cheap to send, and self contained: no index in here refers to anything outside
it, and nothing in here borrows the query text. The text is copied into strings on the way in,
which costs one allocation per distinct identifier and buys an Ast that outlives the string it
came from.
Fields§
§statements: Vec<Statement>The statements in the script, in order.
queries: Vec<Query>The query arena.
query_spans: Vec<Span>Source ranges parallel to queries.
selects: Vec<Select>The select arena.
exprs: Vec<Expr>The expression arena.
expr_spans: Vec<Span>Source ranges parallel to exprs.
sources: Vec<Source>The from-item arena.
strings: Vec<String>Interned text. Identifiers keep the case they were written in, because DuckDB does not fold it at any point, including for quoted identifiers.
parts: Vec<StrRef>Backing store for every Slice of names.
expr_lists: Vec<ExprRef>Backing store for every Slice of expressions.
source_lists: Vec<SourceRef>Backing store for every Slice of from items.
targets: Vec<Target>Backing store for every Slice of target list entries.
order_items: Vec<OrderItem>Backing store for every Slice of order by entries.
case_arms: Vec<CaseArm>Backing store for every Slice of case arms.
create_tables: Vec<CreateTable>The CREATE TABLE arena.
constraints: Vec<Constraint>Backing store for every Slice of constraints.
create_views: Vec<CreateView>The CREATE VIEW arena.
drop_tables: Vec<DropTable>The DROP TABLE arena.
schemas: Vec<Schema>The CREATE SCHEMA and DROP SCHEMA arena.
sequences: Vec<Sequence>The CREATE SEQUENCE and DROP SEQUENCE arena.
types: Vec<TypeDef>The CREATE TYPE and DROP TYPE arena.
alters: Vec<Alter>The ALTER TABLE and ALTER VIEW arena.
indexes: Vec<Index>The CREATE INDEX and DROP INDEX arena.
inserts: Vec<Insert>The INSERT arena.
settings: Vec<Setting>The SET and RESET arena.
attaches: Vec<Attach>The ATTACH arena.
column_defs: Vec<ColumnDef>Backing store for every Slice of column definitions.
name_lists: Vec<Slice>Backing store for every Slice of names, which is a name list rather than a name.
rows: Vec<Slice>Backing store for the rows of a VALUES, each of which is a run of expressions.
windows: Vec<WindowSpec>The window arena, holding what was inside the parentheses of every OVER.
ctes: Vec<Cte>The materialised WITH arena.
cte_lists: Vec<u32>Backing store for every Slice of materialised WITH indexes.
named_args: Vec<(ExprRef, Slice)>The named arguments of the calls that take any, each call with a run of targets whose alias
is the name. Only unnest takes them so far, and a side table keeps every other call as it
was rather than carrying an empty list on each.
array_lists: Vec<ExprRef>The lists written ARRAY[...] rather than [...]. They are the same list, and only the
name of a column holding one tells them apart.
aggregate_orders: Vec<(ExprRef, Slice)>The ORDER BY written inside an aggregate call, list(x ORDER BY y), as a run of
OrderItem beside the call it belongs to. Kept to one side for the reason the named
arguments are: few calls have one and every call would carry the field.
Implementations§
Source§impl Ast
impl Ast
Sourcepub fn query_span(&self, query: QueryRef) -> Span
pub fn query_span(&self, query: QueryRef) -> Span
The source range of a query.
Sourcepub fn string(&self, index: StrRef) -> &str
pub fn string(&self, index: StrRef) -> &str
The text behind a StrRef, or the empty string for NONE.
Sourcepub fn parameters(&self) -> Vec<&str>
pub fn parameters(&self) -> Vec<&str>
Every parameter identifier the statement uses, once each, in the order they were written.
The arena is built as the walk goes, so its order is the written order, and a parameter used twice is one identifier here because it is one value to provide.
Sourcepub fn name(&self, slice: Slice) -> impl Iterator<Item = &str>
pub fn name(&self, slice: Slice) -> impl Iterator<Item = &str>
The parts of a name, outermost first.
Sourcepub fn name_text(&self, slice: Slice) -> String
pub fn name_text(&self, slice: Slice) -> String
A name written back out with dots between the parts, for error messages and tests.
Sourcepub fn window(&self, index: WindowRef) -> WindowSpec
pub fn window(&self, index: WindowRef) -> WindowSpec
One window.
Sourcepub fn cte_list(&self, slice: Slice) -> &[u32]
pub fn cte_list(&self, slice: Slice) -> &[u32]
The materialised WITH definitions a query introduces, outermost first.
Sourcepub fn source_list(&self, slice: Slice) -> &[SourceRef] ⓘ
pub fn source_list(&self, slice: Slice) -> &[SourceRef] ⓘ
The from items of a list.
Sourcepub fn target_list(&self, slice: Slice) -> &[Target]
pub fn target_list(&self, slice: Slice) -> &[Target]
The entries of a target list.
Sourcepub fn named_args(&self, call: ExprRef) -> &[Target]
pub fn named_args(&self, call: ExprRef) -> &[Target]
The named arguments of a call, in the order they were written, each as a target whose alias is the name. Empty for a call that has none.
Sourcepub fn aggregate_order(&self, call: ExprRef) -> &[OrderItem]
pub fn aggregate_order(&self, call: ExprRef) -> &[OrderItem]
The ORDER BY written inside a call, empty when it has none.
Sourcepub fn written_as_array(&self, list: ExprRef) -> bool
pub fn written_as_array(&self, list: ExprRef) -> bool
Whether a list was written ARRAY[...].
Sourcepub fn order_list(&self, slice: Slice) -> &[OrderItem]
pub fn order_list(&self, slice: Slice) -> &[OrderItem]
The entries of an order by list.
Sourcepub fn create_table(&self, index: CreateTableRef) -> CreateTable
pub fn create_table(&self, index: CreateTableRef) -> CreateTable
One CREATE TABLE.
Sourcepub fn create_view(&self, index: CreateViewRef) -> CreateView
pub fn create_view(&self, index: CreateViewRef) -> CreateView
One CREATE VIEW.
Sourcepub fn drop_table(&self, index: DropTableRef) -> DropTable
pub fn drop_table(&self, index: DropTableRef) -> DropTable
One DROP TABLE.
Sourcepub fn sequence(&self, index: SequenceRef) -> Sequence
pub fn sequence(&self, index: SequenceRef) -> Sequence
One CREATE SEQUENCE or DROP SEQUENCE.
Sourcepub fn setting(&self, index: SettingRef) -> Setting
pub fn setting(&self, index: SettingRef) -> Setting
One SET or RESET.
Sourcepub fn column_defs(&self, slice: Slice) -> &[ColumnDef]
pub fn column_defs(&self, slice: Slice) -> &[ColumnDef]
The column definitions of a CREATE TABLE.
Sourcepub fn constraint_list(&self, slice: Slice) -> &[Constraint]
pub fn constraint_list(&self, slice: Slice) -> &[Constraint]
The constraints of a run, in the order written.
Sourcepub fn name_list(&self, slice: Slice) -> &[Slice]
pub fn name_list(&self, slice: Slice) -> &[Slice]
The names of a name list, each of which is itself a run of parts.
Sourcepub fn rows(&self, slice: Slice) -> &[Slice]
pub fn rows(&self, slice: Slice) -> &[Slice]
The rows of a VALUES, each of which is itself a run of expressions.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
How many nodes the whole tree is, across every arena.
The number to watch when the transformer changes. A parse tree of five thousand nodes that becomes an AST of thirty is the twenty precedence levels being thrown away, which is the whole reason this module exists.