MCPcopy Create free account
hub / github.com/apache/datafusion / split_from_semicolon

Function split_from_semicolon

datafusion-cli/src/helper.rs:184–212  ·  view source on GitHub ↗

Splits a string which consists of multiple queries.

(sql: &str)

Source from the content-addressed store, hash-verified

182
183/// Splits a string which consists of multiple queries.
184pub(crate) fn split_from_semicolon(sql: &str) -> Vec<String> {
185 let mut commands = Vec::new();
186 let mut current_command = String::new();
187 let mut in_single_quote = false;
188 let mut in_double_quote = false;
189
190 for c in sql.chars() {
191 if c == '\'' && !in_double_quote {
192 in_single_quote = !in_single_quote;
193 } else if c == '"' && !in_single_quote {
194 in_double_quote = !in_double_quote;
195 }
196
197 if c == ';' && !in_single_quote && !in_double_quote {
198 if !current_command.trim().is_empty() {
199 commands.push(format!("{};", current_command.trim()));
200 current_command.clear();
201 }
202 } else {
203 current_command.push(c);
204 }
205 }
206
207 if !current_command.trim().is_empty() {
208 commands.push(format!("{};", current_command.trim()));
209 }
210
211 commands
212}
213
214#[cfg(test)]
215mod tests {

Callers 2

exec_from_replFunction · 0.85
validate_inputMethod · 0.85

Calls 5

newFunction · 0.85
trimMethod · 0.80
is_emptyMethod · 0.45
pushMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…