1use std::collections::HashMap;
2
3use crate::expression::Expr;
4
5pub enum Statement {
6 Select(SelectStatement),
7 Where(WhereStatement),
8 Having(HavingStatement),
9 Limit(LimitStatement),
10 Offset(OffsetStatement),
11 OrderBy(OrderByStatement),
12 GroupBy(GroupByStatement),
13 AggregateFunction(AggregationsStatement),
14 WindowFunction(WindowFunctionsStatement),
15 Qualify(QualifyStatement),
16 Into(IntoStatement),
17}
18
19#[derive(Clone)]
20pub enum Distinct {
21 None,
22 DistinctAll,
23 DistinctOn(Vec<String>),
24}
25
26#[derive(Clone)]
27pub struct TableSelection {
28 pub table_name: String,
29 pub columns_names: Vec<String>,
30}
31
32#[derive(Clone, PartialEq)]
33pub enum JoinKind {
34 Cross,
35 Inner,
36 Left,
37 Right,
38 Default,
39}
40
41#[derive(Clone)]
42pub enum JoinOperand {
43 OuterAndInner(String, String),
45 Inner(String),
47}
48
49#[derive(Clone)]
50pub struct Join {
51 pub operand: JoinOperand,
52 pub kind: JoinKind,
53 pub predicate: Option<Box<dyn Expr>>,
54}
55
56#[derive(Clone)]
57pub struct SelectStatement {
58 pub table_selections: Vec<TableSelection>,
59 pub joins: Vec<Join>,
60 pub selected_expr_titles: Vec<String>,
61 pub selected_expr: Vec<Box<dyn Expr>>,
62 pub distinct: Distinct,
63}
64
65#[derive(Clone)]
66pub struct WhereStatement {
67 pub condition: Box<dyn Expr>,
68}
69
70#[derive(Clone)]
71pub struct HavingStatement {
72 pub condition: Box<dyn Expr>,
73}
74
75#[derive(Clone)]
76pub struct LimitStatement {
77 pub count: usize,
78}
79
80#[derive(Clone)]
81pub struct OffsetStatement {
82 pub start: Box<dyn Expr>,
83}
84
85#[derive(Clone, PartialEq)]
86pub enum SortingOrder {
87 Ascending,
88 Descending,
89}
90
91#[derive(Clone, PartialEq)]
92pub enum NullsOrderPolicy {
93 NullsFirst,
94 NullsLast,
95}
96
97#[derive(Clone)]
98pub struct OrderByStatement {
99 pub arguments: Vec<Box<dyn Expr>>,
100 pub sorting_orders: Vec<SortingOrder>,
101 pub nulls_order_policies: Vec<NullsOrderPolicy>,
102}
103
104#[derive(Clone)]
105pub struct GroupByStatement {
106 pub values: Vec<Box<dyn Expr>>,
107 pub has_with_roll_up: bool,
108}
109
110#[derive(Clone)]
111pub struct WindowPartitioningClause {
112 pub expr: Box<dyn Expr>,
113}
114
115#[derive(Clone)]
116pub struct WindowOrderingClause {
117 pub order_by: OrderByStatement,
118}
119
120#[derive(Clone)]
121pub struct WindowDefinition {
122 pub name: Option<String>,
123 pub partitioning_clause: Option<WindowPartitioningClause>,
124 pub ordering_clause: Option<WindowOrderingClause>,
125}
126
127#[derive(Clone)]
128pub enum WindowFunctionKind {
129 AggregatedWindowFunction,
130 PureWindowFunction,
131}
132
133#[derive(Clone)]
134pub struct WindowFunction {
135 pub function_name: String,
136 pub arguments: Vec<Box<dyn Expr>>,
137 pub window_definition: WindowDefinition,
138 pub kind: WindowFunctionKind,
139}
140
141#[derive(Clone)]
142pub enum WindowValue {
143 Function(WindowFunction),
144 Expression(Box<dyn Expr>),
145}
146
147#[derive(Clone)]
148pub struct WindowFunctionsStatement {
149 pub window_values: HashMap<String, WindowValue>,
150}
151
152#[derive(Clone)]
153pub struct QualifyStatement {
154 pub condition: Box<dyn Expr>,
155}
156
157#[derive(Clone)]
158pub enum AggregateValue {
159 Expression(Box<dyn Expr>),
160 Function(String, Vec<Box<dyn Expr>>),
161}
162
163#[derive(Clone)]
164pub struct AggregationsStatement {
165 pub aggregations: HashMap<String, AggregateValue>,
166}
167
168#[derive(Clone)]
169pub struct IntoStatement {
170 pub file_path: String,
171 pub lines_terminated: String,
172 pub fields_terminated: String,
173 pub enclosed: String,
174}