MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / execute_select_statement

Function execute_select_statement

crates/gitql-engine/src/engine_executor.rs:78–168  ·  view source on GitHub ↗
(
    env: &mut Environment,
    statement: &SelectStatement,
    alias_table: &HashMap<String, String>,
    data_provider: &Box<dyn DataProvider>,
    gitql_object: &mut GitQLObject,
    hidden_selec

Source from the content-addressed store, hash-verified

76
77#[allow(clippy::borrowed_box)]
78fn execute_select_statement(
79 env: &mut Environment,
80 statement: &SelectStatement,
81 alias_table: &HashMap<String, String>,
82 data_provider: &Box<dyn DataProvider>,
83 gitql_object: &mut GitQLObject,
84 hidden_selections: &HashMap<String, Vec<String>>,
85) -> Result<(), String> {
86 let mut selected_rows_per_table: HashMap<String, Vec<Row>> = HashMap::new();
87 let mut hidden_selection_count_per_table: HashMap<String, usize> = HashMap::new();
88
89 let mut titles: Vec<String> = vec![];
90 let mut hidden_sum = 0;
91
92 for table_selection in &statement.table_selections {
93 // Select objects from the target table
94 let table_name = &table_selection.table_name;
95 let selected_columns = &mut table_selection.columns_names.to_owned();
96
97 // Insert Hidden selection items for this table first
98 let mut hidden_selection_count = 0;
99 if let Some(table_hidden_selection) = hidden_selections.get(table_name) {
100 for hidden_selection in table_hidden_selection {
101 if !selected_columns.contains(hidden_selection) {
102 selected_columns.insert(0, hidden_selection.to_string());
103 hidden_selection_count += 1;
104 }
105 }
106 }
107
108 hidden_selection_count_per_table.insert(table_name.to_string(), hidden_selection_count);
109
110 // Calculate list of titles once per table
111 let mut table_titles = vec![];
112 for selected_column in selected_columns.iter_mut() {
113 table_titles.push(resolve_actual_column_name(alias_table, selected_column));
114 }
115
116 // Call the provider only if table name is not empty
117 let selected_rows: Vec<Row> = if table_name.is_empty() {
118 vec![Row { values: vec![] }]
119 } else {
120 data_provider.provide(table_name, selected_columns)?
121 };
122
123 selected_rows_per_table.insert(table_name.to_string(), selected_rows);
124
125 // Append hidden selection in the right position
126 // at the end all hidden selections will be first
127 let hidden_selection_titles = &table_titles[..hidden_selection_count];
128 titles.splice(hidden_sum..hidden_sum, hidden_selection_titles.to_vec());
129
130 // Non hidden selection should be inserted at the end
131 let selection_titles = &table_titles[hidden_selection_count..];
132 titles.extend_from_slice(selection_titles);
133 hidden_sum += hidden_selection_count;
134 }
135

Callers 1

execute_statementFunction · 0.85

Calls 6

apply_join_operationFunction · 0.85
containsMethod · 0.80
provideMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…