This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 47d5d1fe1a feat: Error when a SHOW command is passed in with an 
accompanying non-existant variable (#11540)
47d5d1fe1a is described below

commit 47d5d1fe1ac7d2eb363d4b2b52268629e89b64f9
Author: June <[email protected]>
AuthorDate: Mon Jul 22 06:32:12 2024 -0600

    feat: Error when a SHOW command is passed in with an accompanying 
non-existant variable (#11540)
    
    * feat: Error when a SHOW command is passed in with an accompanying 
non-existant variable
    
    * fix: Run fmt
    
    * Switch to 'query error' instead of 'statement error' in sqllogictest test 
to see if that fixes CI
    
    * Move some errors in sqllogictest to line above to maybe fix CI
    
    * Fix (hopefully final) failing information_schema slt test due to 
multiline error message/placement
---
 datafusion/sql/src/statement.rs                          | 16 ++++++++++++++++
 .../sqllogictest/test_files/information_schema.slt       | 11 ++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs
index 6df2508630..8eb4113f80 100644
--- a/datafusion/sql/src/statement.rs
+++ b/datafusion/sql/src/statement.rs
@@ -1146,6 +1146,22 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             // we could introduce alias in OptionDefinition if this string 
matching thing grows
             format!("{base_query} WHERE name = 
'datafusion.execution.time_zone'")
         } else {
+            // These values are what are used to make the information_schema 
table, so we just
+            // check here, before actually planning or executing the query, if 
it would produce no
+            // results, and error preemptively if it would (for a better UX)
+            let is_valid_variable = self
+                .context_provider
+                .options()
+                .entries()
+                .iter()
+                .any(|opt| opt.key == variable);
+
+            if !is_valid_variable {
+                return plan_err!(
+                    "'{variable}' is not a variable which can be viewed with 
'SHOW'"
+                );
+            }
+
             format!("{base_query} WHERE name = '{variable}'")
         };
 
diff --git a/datafusion/sqllogictest/test_files/information_schema.slt 
b/datafusion/sqllogictest/test_files/information_schema.slt
index c8c0d1d45b..1c6ffd44b1 100644
--- a/datafusion/sqllogictest/test_files/information_schema.slt
+++ b/datafusion/sqllogictest/test_files/information_schema.slt
@@ -370,9 +370,12 @@ datafusion.execution.time_zone +00:00 The default time 
zone Some functions, e.g.
 
 
 # show empty verbose
-query TTT
+statement error DataFusion error: Error during planning: '' is not a variable 
which can be viewed with 'SHOW'
 SHOW VERBOSE
-----
+
+# show nonsense verbose
+statement error DataFusion error: Error during planning: 'nonsense' is not a 
variable which can be viewed with 'SHOW'
+SHOW NONSENSE VERBOSE
 
 # information_schema_describe_table
 
@@ -508,9 +511,7 @@ SHOW columns from datafusion.public.t2
 
 
 # show_non_existing_variable
-# FIXME
-# currently we cannot know whether a variable exists, this will output 0 row 
instead
-statement ok
+statement error DataFusion error: Error during planning: 'something_unknown' 
is not a variable which can be viewed with 'SHOW'
 SHOW SOMETHING_UNKNOWN;
 
 statement ok


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to