This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch branch-53
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/branch-53 by this push:
new ab7507fca4 [branch-53] cli: Fix datafusion-cli hint edge cases
(#20609) (#20887)
ab7507fca4 is described below
commit ab7507fca44e42cf57fa5880af8c8b46d86227ae
Author: Andrew Lamb <[email protected]>
AuthorDate: Wed Mar 11 20:17:38 2026 -0400
[branch-53] cli: Fix datafusion-cli hint edge cases (#20609) (#20887)
- Part of https://github.com/apache/datafusion/issues/19692
This PR:
- Backports https://github.com/apache/datafusion/pull/20609 from
@comphead to the branch-53 line
Co-authored-by: Oleks V <[email protected]>
---
datafusion-cli/src/exec.rs | 1 +
datafusion-cli/src/helper.rs | 33 +++++++++++++++++++++------------
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/datafusion-cli/src/exec.rs b/datafusion-cli/src/exec.rs
index 0cb21e751c..09347d6d7d 100644
--- a/datafusion-cli/src/exec.rs
+++ b/datafusion-cli/src/exec.rs
@@ -196,6 +196,7 @@ pub async fn exec_from_repl(
}
Err(ReadlineError::Interrupted) => {
println!("^C");
+ rl.helper().unwrap().reset_hint();
continue;
}
Err(ReadlineError::Eof) => {
diff --git a/datafusion-cli/src/helper.rs b/datafusion-cli/src/helper.rs
index c53272ee19..f01d0891b9 100644
--- a/datafusion-cli/src/helper.rs
+++ b/datafusion-cli/src/helper.rs
@@ -19,6 +19,7 @@
//! and auto-completion for file name during creating external table.
use std::borrow::Cow;
+use std::cell::Cell;
use crate::highlighter::{Color, NoSyntaxHighlighter, SyntaxHighlighter};
@@ -40,6 +41,10 @@ pub struct CliHelper {
completer: FilenameCompleter,
dialect: Dialect,
highlighter: Box<dyn Highlighter>,
+ /// Tracks whether to show the default hint. Set to `false` once the user
+ /// types anything, so the hint doesn't reappear after deleting back to
+ /// an empty line. Reset to `true` when the line is submitted.
+ show_hint: Cell<bool>,
}
impl CliHelper {
@@ -53,6 +58,7 @@ impl CliHelper {
completer: FilenameCompleter::new(),
dialect: *dialect,
highlighter,
+ show_hint: Cell::new(true),
}
}
@@ -62,6 +68,11 @@ impl CliHelper {
}
}
+ /// Re-enable the default hint for the next prompt.
+ pub fn reset_hint(&self) {
+ self.show_hint.set(true);
+ }
+
fn validate_input(&self, input: &str) -> Result<ValidationResult> {
if let Some(sql) = input.strip_suffix(';') {
let dialect = match dialect_from_str(self.dialect) {
@@ -119,12 +130,11 @@ impl Hinter for CliHelper {
type Hint = String;
fn hint(&self, line: &str, _pos: usize, _ctx: &Context<'_>) ->
Option<String> {
- if line.trim().is_empty() {
- let suggestion = Color::gray(DEFAULT_HINT_SUGGESTION);
- Some(suggestion)
- } else {
- None
+ if !line.is_empty() {
+ self.show_hint.set(false);
}
+ (self.show_hint.get() && line.trim().is_empty())
+ .then(|| Color::gray(DEFAULT_HINT_SUGGESTION))
}
}
@@ -133,12 +143,9 @@ impl Hinter for CliHelper {
fn is_open_quote_for_location(line: &str, pos: usize) -> bool {
let mut sql = line[..pos].to_string();
sql.push('\'');
- if let Ok(stmts) = DFParser::parse_sql(&sql)
- && let Some(Statement::CreateExternalTable(_)) = stmts.back()
- {
- return true;
- }
- false
+ DFParser::parse_sql(&sql).is_ok_and(|stmts| {
+ matches!(stmts.back(), Some(Statement::CreateExternalTable(_)))
+ })
}
impl Completer for CliHelper {
@@ -161,7 +168,9 @@ impl Completer for CliHelper {
impl Validator for CliHelper {
fn validate(&self, ctx: &mut ValidationContext<'_>) ->
Result<ValidationResult> {
let input = ctx.input().trim_end();
- self.validate_input(input)
+ let result = self.validate_input(input);
+ self.reset_hint();
+ result
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]