From d5bcf1528f3f88f8b507818e7525b10f94158748 Mon Sep 17 00:00:00 2001 From: Puskar Basu Date: Thu, 29 May 2025 14:32:00 +0530 Subject: [PATCH] DuckDB meta queries will also show suggested table names --- internal/interactive/interactive_client.go | 14 ++++++++++++-- internal/interactive/interactive_helpers.go | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/internal/interactive/interactive_client.go b/internal/interactive/interactive_client.go index b358f47f..533166ba 100644 --- a/internal/interactive/interactive_client.go +++ b/internal/interactive/interactive_client.go @@ -477,6 +477,9 @@ func (c *InteractiveClient) queryCompleter(d prompt.Document) []prompt.Suggest { case isFirstWord(text): suggestions := c.getFirstWordSuggestions(text) s = append(s, suggestions...) + case isDuckDbMetaQuery(text): + tableSuggestions := c.getTableSuggestions(lastWord(text)) + s = append(s, tableSuggestions...) case metaquery.IsMetaQuery(text): suggestions := metaquery.Complete(&metaquery.CompleterInput{ Query: text, @@ -497,8 +500,15 @@ func (c *InteractiveClient) getFirstWordSuggestions(word string) []prompt.Sugges var s []prompt.Suggest // add all we know that can be the first words - // "select", "with" - s = append(s, prompt.Suggest{Text: "select", Output: "select"}, prompt.Suggest{Text: "with", Output: "with"}) + // "select", "with", "describe", "show", "summarize" + s = append(s, + prompt.Suggest{Text: "select", Output: "select"}, + prompt.Suggest{Text: "with", Output: "with"}, + prompt.Suggest{Text: "describe", Output: "describe"}, + prompt.Suggest{Text: "show", Output: "show"}, + prompt.Suggest{Text: "summarize", Output: "summarize"}, + prompt.Suggest{Text: "explain", Output: "explain"}, + ) // metaqueries s = append(s, metaquery.PromptSuggestions()...) return s diff --git a/internal/interactive/interactive_helpers.go b/internal/interactive/interactive_helpers.go index 99bb80ea..2c867b11 100644 --- a/internal/interactive/interactive_helpers.go +++ b/internal/interactive/interactive_helpers.go @@ -76,6 +76,21 @@ func lastWord(text string) string { return text[strings.LastIndex(text, " "):] } +// isDuckDbMetaQuery returns true if the input string equals 'describe', 'show', or 'summarize' +func isDuckDbMetaQuery(s string) bool { + ts := strings.ToLower(strings.TrimSpace(s)) + switch { + case ts == "describe": + return true + case ts == "show": + return true + case ts == "summarize": + return true + default: + return false + } +} + // // keeping this around because we may need // to revisit exit on non-darwin platforms.