Skip to content

Commit c939ee7

Browse files
committed
Fix the order of applying distinct operator plan
1 parent 3bab236 commit c939ee7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/gitql-engine/src/engine.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashMap;
22
use std::vec;
33

44
use gitql_ast::statement::DescribeStatement;
5+
use gitql_ast::statement::Distinct;
56
use gitql_ast::statement::DoStatement;
67
use gitql_ast::statement::GQLQuery;
78
use gitql_ast::statement::GlobalVariableStatement;
@@ -90,6 +91,7 @@ fn evaluate_select_query(
9091
let mut statements_map = query.statements;
9192
let has_group_by_statement = statements_map.contains_key("group");
9293

94+
let mut distinct: Option<Distinct> = None;
9395
for logical_node_name in FIXED_LOGICAL_PLAN {
9496
if let Some(statement) = statements_map.get_mut(logical_node_name) {
9597
match logical_node_name {
@@ -115,12 +117,7 @@ fn evaluate_select_query(
115117
return Ok(EvaluationResult::SelectedGroups(gitql_object));
116118
}
117119

118-
// Apply the distinct operation object is not empty too.
119-
apply_distinct_operator(
120-
&select_statement.distinct,
121-
&mut gitql_object,
122-
&hidden_selections,
123-
);
120+
distinct = Some(select_statement.distinct.to_owned());
124121
}
125122
_ => {
126123
execute_statement(
@@ -137,6 +134,11 @@ fn evaluate_select_query(
137134
}
138135
}
139136

137+
// Apply the distinct operation after executing statements
138+
if let Some(distinct) = distinct {
139+
apply_distinct_operator(&distinct, &mut gitql_object, &hidden_selections);
140+
}
141+
140142
// Remove Hidden Selection from the rows after executing the query plan
141143
remove_hidden_selected_from_groups(
142144
&mut gitql_object.titles,

0 commit comments

Comments
 (0)