Skip to main content

Ast

Struct Ast 

Source
pub struct Ast {
Show 36 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 copies: Vec<CopyTo>, 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.

§copies: Vec<CopyTo>

The COPY ... TO 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

Source

pub fn expr_span(&self, expr: ExprRef) -> Span

The source range of an expression.

Source

pub fn query_span(&self, query: QueryRef) -> Span

The source range of a query.

Source

pub fn string(&self, index: StrRef) -> &str

The text behind a StrRef, or the empty string for NONE.

Source

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.

Source

pub fn name(&self, slice: Slice) -> impl Iterator<Item = &str>

The parts of a name, outermost first.

Source

pub fn name_text(&self, slice: Slice) -> String

A name written back out with dots between the parts, for error messages and tests.

Source

pub fn expr(&self, index: ExprRef) -> Expr

One expression.

Source

pub fn source(&self, index: SourceRef) -> Source

One from item.

Source

pub fn query(&self, index: QueryRef) -> Query

One query.

Source

pub fn select(&self, index: SelectRef) -> Select

One select block.

Source

pub fn window(&self, index: WindowRef) -> WindowSpec

One window.

Source

pub fn cte(&self, index: u32) -> Cte

One materialised WITH definition.

Source

pub fn cte_list(&self, slice: Slice) -> &[u32]

The materialised WITH definitions a query introduces, outermost first.

Source

pub fn expr_list(&self, slice: Slice) -> &[ExprRef] ⓘ

The expressions of a list.

Source

pub fn source_list(&self, slice: Slice) -> &[SourceRef] ⓘ

The from items of a list.

Source

pub fn target_list(&self, slice: Slice) -> &[Target]

The entries of a target list.

Source

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.

Source

pub fn aggregate_order(&self, call: ExprRef) -> &[OrderItem]

The ORDER BY written inside a call, empty when it has none.

Source

pub fn written_as_array(&self, list: ExprRef) -> bool

Whether a list was written ARRAY[...].

Source

pub fn order_list(&self, slice: Slice) -> &[OrderItem]

The entries of an order by list.

Source

pub fn arm_list(&self, slice: Slice) -> &[CaseArm]

The arms of a case.

Source

pub fn create_table(&self, index: CreateTableRef) -> CreateTable

One CREATE TABLE.

Source

pub fn create_view(&self, index: CreateViewRef) -> CreateView

One CREATE VIEW.

Source

pub fn drop_table(&self, index: DropTableRef) -> DropTable

One DROP TABLE.

Source

pub fn schema(&self, index: SchemaRef) -> Schema

One CREATE SCHEMA or DROP SCHEMA.

Source

pub fn sequence(&self, index: SequenceRef) -> Sequence

One CREATE SEQUENCE or DROP SEQUENCE.

Source

pub fn type_def(&self, index: TypeRef) -> TypeDef

One CREATE TYPE or DROP TYPE.

Source

pub fn index(&self, index: IndexRef) -> Index

The CREATE INDEX or DROP INDEX at an index.

Source

pub fn alter(&self, index: AlterRef) -> Alter

One ALTER TABLE or ALTER VIEW.

Source

pub fn insert(&self, index: InsertRef) -> Insert

One INSERT.

Source

pub fn setting(&self, index: SettingRef) -> Setting

One SET or RESET.

Source

pub fn attach(&self, index: AttachRef) -> Attach

An ATTACH by index.

Source

pub fn column_defs(&self, slice: Slice) -> &[ColumnDef]

The column definitions of a CREATE TABLE.

Source

pub fn constraint_list(&self, slice: Slice) -> &[Constraint]

The constraints of a run, in the order written.

Source

pub fn name_list(&self, slice: Slice) -> &[Slice]

The names of a name list, each of which is itself a run of parts.

Source

pub fn rows(&self, slice: Slice) -> &[Slice]

The rows of a VALUES, each of which is itself a run of expressions.

Source

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.

Trait Implementations§

Source§

impl Clone for Ast

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ast

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Ast

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Ast

Source§

impl PartialEq for Ast

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Ast

Auto Trait Implementations§

§

impl Freeze for Ast

§

impl RefUnwindSafe for Ast

§

impl Send for Ast

§

impl Sync for Ast

§

impl Unpin for Ast

§

impl UnsafeUnpin for Ast

§

impl UnwindSafe for Ast

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.