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

Function exec_from_lines

datafusion-cli/src/exec.rs:67–108  ·  view source on GitHub ↗

run and execute SQL statements and commands from a file, against a context with the given print options

(
    ctx: &dyn CliSessionContext,
    reader: &mut BufReader<File>,
    print_options: &PrintOptions,
)

Source from the content-addressed store, hash-verified

65
66/// run and execute SQL statements and commands from a file, against a context with the given print options
67pub async fn exec_from_lines(
68 ctx: &dyn CliSessionContext,
69 reader: &mut BufReader<File>,
70 print_options: &PrintOptions,
71) -> Result<()> {
72 let mut query = "".to_owned();
73
74 for line in reader.lines() {
75 match line {
76 Ok(line) if line.starts_with("#!") => {
77 continue;
78 }
79 Ok(line) if line.starts_with("--") => {
80 continue;
81 }
82 Ok(line) => {
83 let line = line.trim_end();
84 query.push_str(line);
85 if line.ends_with(';') {
86 match exec_and_print(ctx, print_options, query).await {
87 Ok(_) => {}
88 Err(err) => eprintln!("{err}"),
89 }
90 query = "".to_string();
91 } else {
92 query.push('\n');
93 }
94 }
95 _ => {
96 break;
97 }
98 }
99 }
100
101 // run the left over query if the last statement doesn't contain ‘;’
102 // ignore if it only consists of '\n'
103 if query.contains(|c| c != '\n') {
104 exec_and_print(ctx, print_options, query).await?;
105 }
106
107 Ok(())
108}
109
110pub async fn exec_from_files(
111 ctx: &dyn CliSessionContext,

Callers 2

executeMethod · 0.85
exec_from_filesFunction · 0.85

Calls 4

exec_and_printFunction · 0.85
to_stringMethod · 0.45
pushMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…