(
env: &mut Environment,
data_provider: &Box<dyn DataProvider>,
select_query: SelectQuery,
)
| 74 | |
| 75 | #[allow(clippy::borrowed_box)] |
| 76 | fn evaluate_select_query( |
| 77 | env: &mut Environment, |
| 78 | data_provider: &Box<dyn DataProvider>, |
| 79 | select_query: SelectQuery, |
| 80 | ) -> Result<EvaluationResult, String> { |
| 81 | let mut gitql_object = GitQLObject::default(); |
| 82 | let mut alias_table: HashMap<String, String> = select_query.alias_table; |
| 83 | |
| 84 | let hidden_selections_map = select_query.hidden_selections; |
| 85 | let hidden_selections: Vec<String> = |
| 86 | hidden_selections_map.values().flatten().cloned().collect(); |
| 87 | let mut statements_map = select_query.statements; |
| 88 | let has_group_by_statement = statements_map.contains_key("group"); |
| 89 | |
| 90 | let mut distinct: Option<Distinct> = None; |
| 91 | for logical_node_name in FIXED_LOGICAL_PLAN { |
| 92 | if let Some(statement) = statements_map.get_mut(logical_node_name) { |
| 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 | if let Statement::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 | return Ok(EvaluationResult::SelectedGroups(gitql_object)); |
| 107 | } |
| 108 | |
| 109 | distinct = Some(select_statement.distinct.to_owned()); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Apply the distinct operation after executing statements |
| 115 | if let Some(distinct) = distinct { |
| 116 | apply_distinct_operator(&distinct, &mut gitql_object, &hidden_selections); |
| 117 | } |
| 118 | |
| 119 | // Remove Hidden Selection from the rows after executing the query plan |
| 120 | remove_hidden_selected_from_groups( |
| 121 | &mut gitql_object.titles, |
| 122 | &mut gitql_object.groups, |
| 123 | &hidden_selections, |
| 124 | ); |
| 125 | |
| 126 | let number_of_groups = gitql_object.groups.len(); |
| 127 | if number_of_groups > 0 { |
| 128 | let main_group: &mut Group = &mut gitql_object.groups[0]; |
| 129 | |
| 130 | // If there are many groups that mean group by is executed before. |
| 131 | // must merge each group into only one element |
| 132 | if number_of_groups > 1 { |
| 133 | for group in gitql_object.groups.iter_mut() { |
no test coverage detected
searching dependent graphs…