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

Function exec_from_repl

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

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

(
    ctx: &dyn CliSessionContext,
    print_options: &mut PrintOptions,
)

Source from the content-addressed store, hash-verified

127
128/// run and execute SQL statements and commands against a context with the given print options
129pub async fn exec_from_repl(
130 ctx: &dyn CliSessionContext,
131 print_options: &mut PrintOptions,
132) -> rustyline::Result<()> {
133 let mut rl = Editor::new()?;
134 rl.set_helper(Some(CliHelper::new(
135 &ctx.task_ctx().session_config().options().sql_parser.dialect,
136 print_options.color,
137 )));
138 rl.load_history(".history").ok();
139
140 loop {
141 match rl.readline("> ") {
142 Ok(line) if line.starts_with('\\') => {
143 rl.add_history_entry(line.trim_end())?;
144 let command = line.split_whitespace().collect::<Vec<_>>().join(" ");
145 if let Ok(cmd) = &command[1..].parse::<Command>() {
146 match cmd {
147 Command::Quit => break,
148 Command::OutputFormat(subcommand) => {
149 if let Some(subcommand) = subcommand {
150 if let Ok(command) = subcommand.parse::<OutputFormat>() {
151 if let Err(e) = command.execute(print_options).await {
152 eprintln!("{e}")
153 }
154 } else {
155 eprintln!(
156 "'\\{}' is not a valid command, you can use '\\?' to see all commands",
157 &line[1..]
158 );
159 }
160 } else {
161 println!("Output format is {:?}.", print_options.format);
162 }
163 }
164 _ => {
165 if let Err(e) = cmd.execute(ctx, print_options).await {
166 eprintln!("{e}")
167 }
168 }
169 }
170 } else {
171 eprintln!(
172 "'\\{}' is not a valid command, you can use '\\?' to see all commands",
173 &line[1..]
174 );
175 }
176 }
177 Ok(line) => {
178 let lines = split_from_semicolon(&line);
179 for line in lines {
180 rl.add_history_entry(line.trim_end())?;
181 tokio::select! {
182 res = exec_and_print(ctx, print_options, line) => match res {
183 Ok(_) => {}
184 Err(err) => eprintln!("{err}"),
185 },
186 _ = signal::ctrl_c() => {

Callers 2

main_innerFunction · 0.85
mainFunction · 0.85

Calls 9

newFunction · 0.85
split_from_semicolonFunction · 0.85
session_configMethod · 0.80
set_dialectMethod · 0.80
reset_hintMethod · 0.80
optionsMethod · 0.45
task_ctxMethod · 0.45
joinMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…