Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b73cd9

Browse files
committed
Update the structure of Statements to use taged union
1 parent1a22951 commit6b73cd9

File tree

8 files changed

+91
-285
lines changed

8 files changed

+91
-285
lines changed

‎crates/gitql-ast/src/query.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub enum Query {
1212
}
1313

1414
pubstructSelectQuery{
15-
pubstatements:HashMap<&'staticstr,Box<dynStatement>>,
15+
pubstatements:HashMap<&'staticstr,Statement>,
1616
pubalias_table:HashMap<String,String>,
1717
pubhas_aggregation_function:bool,
1818
pubhas_group_by_statement:bool,

‎crates/gitql-ast/src/statement.rs‎

Lines changed: 12 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
use std::any::Any;
21
use std::collections::HashMap;
32

4-
use dyn_clone::DynClone;
5-
63
usecrate::expression::Expr;
74

8-
pubenumStatementKind{
9-
Select,
10-
Where,
11-
Having,
12-
Limit,
13-
Offset,
14-
OrderBy,
15-
GroupBy,
16-
AggregateFunction,
17-
WindowFunction,
18-
Qualify,
19-
Into,
20-
}
21-
22-
dyn_clone::clone_trait_object!(Statement);
23-
24-
pubtraitStatement:DynClone{
25-
fnkind(&self) ->StatementKind;
26-
fnas_any(&self) ->&dynAny;
5+
pubenumStatement{
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),
2717
}
2818

2919
#[derive(Clone)]
@@ -72,76 +62,26 @@ pub struct SelectStatement {
7262
pubdistinct:Distinct,
7363
}
7464

75-
implStatementforSelectStatement{
76-
fnas_any(&self) ->&dynAny{
77-
self
78-
}
79-
80-
fnkind(&self) ->StatementKind{
81-
StatementKind::Select
82-
}
83-
}
84-
8565
#[derive(Clone)]
8666
pubstructWhereStatement{
8767
pubcondition:Box<dynExpr>,
8868
}
8969

90-
implStatementforWhereStatement{
91-
fnas_any(&self) ->&dynAny{
92-
self
93-
}
94-
95-
fnkind(&self) ->StatementKind{
96-
StatementKind::Where
97-
}
98-
}
99-
10070
#[derive(Clone)]
10171
pubstructHavingStatement{
10272
pubcondition:Box<dynExpr>,
10373
}
10474

105-
implStatementforHavingStatement{
106-
fnas_any(&self) ->&dynAny{
107-
self
108-
}
109-
110-
fnkind(&self) ->StatementKind{
111-
StatementKind::Having
112-
}
113-
}
114-
11575
#[derive(Clone)]
11676
pubstructLimitStatement{
11777
pubcount:usize,
11878
}
11979

120-
implStatementforLimitStatement{
121-
fnas_any(&self) ->&dynAny{
122-
self
123-
}
124-
125-
fnkind(&self) ->StatementKind{
126-
StatementKind::Limit
127-
}
128-
}
129-
13080
#[derive(Clone)]
13181
pubstructOffsetStatement{
13282
pubstart:Box<dynExpr>,
13383
}
13484

135-
implStatementforOffsetStatement{
136-
fnas_any(&self) ->&dynAny{
137-
self
138-
}
139-
140-
fnkind(&self) ->StatementKind{
141-
StatementKind::Offset
142-
}
143-
}
144-
14585
#[derive(Clone,PartialEq)]
14686
pubenumSortingOrder{
14787
Ascending,
@@ -161,32 +101,12 @@ pub struct OrderByStatement {
161101
pubnulls_order_policies:Vec<NullsOrderPolicy>,
162102
}
163103

164-
implStatementforOrderByStatement{
165-
fnas_any(&self) ->&dynAny{
166-
self
167-
}
168-
169-
fnkind(&self) ->StatementKind{
170-
StatementKind::OrderBy
171-
}
172-
}
173-
174104
#[derive(Clone)]
175105
pubstructGroupByStatement{
176106
pubvalues:Vec<Box<dynExpr>>,
177107
pubhas_with_roll_up:bool,
178108
}
179109

180-
implStatementforGroupByStatement{
181-
fnas_any(&self) ->&dynAny{
182-
self
183-
}
184-
185-
fnkind(&self) ->StatementKind{
186-
StatementKind::GroupBy
187-
}
188-
}
189-
190110
#[derive(Clone)]
191111
pubstructWindowPartitioningClause{
192112
pubexpr:Box<dynExpr>,
@@ -229,31 +149,11 @@ pub struct WindowFunctionsStatement {
229149
pubwindow_values:HashMap<String,WindowValue>,
230150
}
231151

232-
implStatementforWindowFunctionsStatement{
233-
fnas_any(&self) ->&dynAny{
234-
self
235-
}
236-
237-
fnkind(&self) ->StatementKind{
238-
StatementKind::WindowFunction
239-
}
240-
}
241-
242152
#[derive(Clone)]
243153
pubstructQualifyStatement{
244154
pubcondition:Box<dynExpr>,
245155
}
246156

247-
implStatementforQualifyStatement{
248-
fnas_any(&self) ->&dynAny{
249-
self
250-
}
251-
252-
fnkind(&self) ->StatementKind{
253-
StatementKind::Qualify
254-
}
255-
}
256-
257157
#[derive(Clone)]
258158
pubenumAggregateValue{
259159
Expression(Box<dynExpr>),
@@ -265,30 +165,10 @@ pub struct AggregationsStatement {
265165
pubaggregations:HashMap<String,AggregateValue>,
266166
}
267167

268-
implStatementforAggregationsStatement{
269-
fnas_any(&self) ->&dynAny{
270-
self
271-
}
272-
273-
fnkind(&self) ->StatementKind{
274-
StatementKind::AggregateFunction
275-
}
276-
}
277-
278168
#[derive(Clone)]
279169
pubstructIntoStatement{
280170
pubfile_path:String,
281171
publines_terminated:String,
282172
pubfields_terminated:String,
283173
pubenclosed:String,
284174
}
285-
286-
implStatementforIntoStatement{
287-
fnas_any(&self) ->&dynAny{
288-
self
289-
}
290-
291-
fnkind(&self) ->StatementKind{
292-
StatementKind::Into
293-
}
294-
}

‎crates/gitql-engine/src/engine.rs‎

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use gitql_ast::query::GlobalVariableDeclQuery;
77
use gitql_ast::query::Query;
88
use gitql_ast::query::SelectQuery;
99
use gitql_ast::statement::Distinct;
10-
use gitql_ast::statement::SelectStatement;
10+
use gitql_ast::statement::Statement;
1111
use gitql_core::environment::Environment;
1212
use gitql_core::object::GitQLObject;
1313
use gitql_core::object::Group;
@@ -90,42 +90,23 @@ fn evaluate_select_query(
9090
letmut distinct:Option<Distinct> =None;
9191
for logical_node_nameinFIXED_LOGICAL_PLAN{
9292
ifletSome(statement) = statements_map.get_mut(logical_node_name){
93-
match logical_node_name{
94-
"select" =>{
95-
// Select statement should be performed on all repositories, can be executed in parallel
96-
let select_statement = statement
97-
.as_any()
98-
.downcast_ref::<SelectStatement>()
99-
.unwrap();
100-
101-
execute_statement(
102-
env,
103-
statement,
104-
data_provider,
105-
&mut gitql_object,
106-
&mut alias_table,
107-
&hidden_selections_map,
108-
has_group_by_statement,
109-
)?;
110-
111-
// If the main group is empty, no need to perform other statements
112-
if gitql_object.is_empty() || gitql_object.groups[0].is_empty(){
113-
returnOk(EvaluationResult::SelectedGroups(gitql_object));
114-
}
115-
116-
distinct =Some(select_statement.distinct.to_owned());
117-
}
118-
_ =>{
119-
execute_statement(
120-
env,
121-
statement,
122-
data_provider,
123-
&mut gitql_object,
124-
&mut alias_table,
125-
&hidden_selections_map,
126-
has_group_by_statement,
127-
)?;
93+
execute_statement(
94+
env,
95+
statement,
96+
data_provider,
97+
&mut gitql_object,
98+
&mut alias_table,
99+
&hidden_selections_map,
100+
has_group_by_statement,
101+
)?;
102+
103+
ifletStatement::Select(select_statement) = statement{
104+
// If the main group is empty, no need to perform other statements
105+
if gitql_object.is_empty() || gitql_object.groups[0].is_empty(){
106+
returnOk(EvaluationResult::SelectedGroups(gitql_object));
128107
}
108+
109+
distinct =Some(select_statement.distinct.to_owned());
129110
}
130111
}
131112
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp