Enum databend_common_ast::parser::expr::ExprElement
source · pub enum ExprElement {
Show 37 variants
ColumnRef {
column: ColumnRef,
},
DotAccess {
key: ColumnID,
},
IsNull {
not: bool,
},
IsDistinctFrom {
not: bool,
},
InList {
list: Vec<Expr>,
not: bool,
},
InSubquery {
subquery: Box<Query>,
not: bool,
},
Between {
low: Box<Expr>,
high: Box<Expr>,
not: bool,
},
BinaryOp {
op: BinaryOperator,
},
JsonOp {
op: JsonOperator,
},
UnaryOp {
op: UnaryOperator,
},
VariableAccess(String),
Cast {
expr: Box<Expr>,
target_type: TypeName,
},
TryCast {
expr: Box<Expr>,
target_type: TypeName,
},
PgCast {
target_type: TypeName,
},
Extract {
field: IntervalKind,
expr: Box<Expr>,
},
DatePart {
field: IntervalKind,
expr: Box<Expr>,
},
Position {
substr_expr: Box<Expr>,
str_expr: Box<Expr>,
},
SubString {
expr: Box<Expr>,
substring_from: Box<Expr>,
substring_for: Option<Box<Expr>>,
},
Trim {
expr: Box<Expr>,
trim_where: Option<(TrimWhere, Box<Expr>)>,
},
Literal {
value: Literal,
},
CountAll {
window: Option<Window>,
},
Tuple {
exprs: Vec<Expr>,
},
FunctionCall {
func: FunctionCall,
},
Case {
operand: Option<Box<Expr>>,
conditions: Vec<Expr>,
results: Vec<Expr>,
else_result: Option<Box<Expr>>,
},
Exists {
subquery: Query,
not: bool,
},
Subquery {
modifier: Option<SubqueryModifier>,
subquery: Query,
},
MapAccess {
accessor: MapAccessor,
},
ChainFunctionCall {
name: Identifier,
args: Vec<Expr>,
lambda: Option<Lambda>,
},
ListComprehension {
source: Expr,
param: Identifier,
filter: Option<Expr>,
result: Expr,
},
Group(Expr),
Array {
exprs: Vec<Expr>,
},
Map {
kvs: Vec<(Literal, Expr)>,
},
Interval {
expr: Expr,
unit: IntervalKind,
},
DateAdd {
unit: IntervalKind,
interval: Expr,
date: Expr,
},
DateSub {
unit: IntervalKind,
interval: Expr,
date: Expr,
},
DateTrunc {
unit: IntervalKind,
date: Expr,
},
Hole {
name: String,
},
}Expand description
A ‘flattened’ AST of expressions.
This is used to parse expressions in Pratt parser. The Pratt parser is not able to parse expressions by grammar. So we need to extract the expression operands and operators to be the input of Pratt parser, by running a nom parser in advance.
For example, a + b AND c is null is parsed as [col(a), PLUS, col(b), AND, col(c), ISNULL] by nom parsers.
Then the Pratt parser is able to parse the expression into AND(PLUS(col(a), col(b)), ISNULL(col(c))).
Variants§
ColumnRef
Column reference, with indirection like table.column
DotAccess
.a.b after column ref, currently it’ll be taken as column reference
IsNull
IS [NOT] NULL expression
IsDistinctFrom
IS [NOT] DISTINCT FROM expression
InList
[ NOT ] IN (list, ...)
InSubquery
[ NOT ] IN (SELECT ...)
Between
BETWEEN ... AND ...
BinaryOp
Binary operation
Fields
op: BinaryOperatorJsonOp
JSON operation
Fields
op: JsonOperatorUnaryOp
Unary operation
Fields
op: UnaryOperatorVariableAccess(String)
Cast
CAST expression, like CAST(expr AS target_type)
TryCast
TRY_CAST expression`
PgCast
::<type_name> expression
Extract
EXTRACT(IntervalKind FROM
DatePart
DATE_PART(IntervalKind,
Position
POSITION(
SubString
SUBSTRING(
Trim
TRIM([[BOTH | LEADING | TRAILING]
Literal
A literal value, such as string, number, date or NULL
CountAll
Count(*) expression
Tuple
(foo, bar)
FunctionCall
Scalar function call
Fields
func: FunctionCallCase
CASE ... WHEN ... ELSE ... expression
Fields
Exists
EXISTS expression
Subquery
Scalar/ANY/ALL/SOME subquery
MapAccess
Access elements of Array, Object and Variant by index or key, like arr[0], or obj:k1
Fields
accessor: MapAccessorChainFunctionCall
python/rust style function call, like a.foo(b).bar(c) —> bar(foo(a, b), c)
ListComprehension
python/rust list comprehension
Group(Expr)
An expression between parentheses
Array
[1, 2, 3]
Map
{'k1':'v1','k2':'v2'}
Interval
DateAdd
DateSub
DateTrunc
Hole
Implementations§
Trait Implementations§
source§impl Clone for ExprElement
impl Clone for ExprElement
source§fn clone(&self) -> ExprElement
fn clone(&self) -> ExprElement
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for ExprElement
impl Debug for ExprElement
source§impl PartialEq for ExprElement
impl PartialEq for ExprElement
impl StructuralPartialEq for ExprElement
Auto Trait Implementations§
impl Freeze for ExprElement
impl RefUnwindSafe for ExprElement
impl Send for ExprElement
impl Sync for ExprElement
impl Unpin for ExprElement
impl UnwindSafe for ExprElement
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more