apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.87k stars 1.11k forks source link

Support autocomplet for datafusion-cli #8783

Open Weijun-H opened 8 months ago

Weijun-H commented 8 months ago

Is your feature request related to a problem or challenge?

Currently, the DataFusion CLI lacks autocompletion support, which can be a hindrance to users trying to efficiently navigate and execute commands. Autocompletion is a standard feature in modern CLIs that significantly improves user productivity by suggesting and completing commands, options, and arguments as users type.

Describe the solution you'd like

extend current Completer

impl Completer for CliHelper {
    type Candidate = Pair;

    fn complete(
        &self,
        line: &str,
        pos: usize,
        ctx: &Context<'_>,
    ) -> std::result::Result<(usize, Vec<Pair>), ReadlineError> {
        if is_open_quote_for_location(line, pos) {
            self.completer.complete(line, pos, ctx)
        } else {
            Ok((0, Vec::with_capacity(0)))
        }
    }
}

then search the most possible command based on input (maybe build up Trie index for it?)

Describe alternatives you've considered

No response

Additional context

#1251

Jefffrey commented 8 months ago

Related: #2652

alamb commented 8 months ago

I think this is a pretty tricky feature to do completely -- perhaps we can take a look at other systems (especially ones based on sqlparser-rs) and see what they do