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 cc7484e0b7 Minor: Change no-statement error message to be clearer
(#11394)
cc7484e0b7 is described below
commit cc7484e0b73fe0b36e5f76741399c95e5e7ff1c7
Author: June <[email protected]>
AuthorDate: Wed Jul 10 13:11:48 2024 -0600
Minor: Change no-statement error message to be clearer (#11394)
* Change no-statement error message to be clearer and add tests for said
change
* Run fmt to pass CI
---
datafusion/core/src/execution/session_state.rs | 2 +-
datafusion/core/tests/sql/sql_api.rs | 34 ++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/datafusion/core/src/execution/session_state.rs
b/datafusion/core/src/execution/session_state.rs
index c123ebb22e..60745076c2 100644
--- a/datafusion/core/src/execution/session_state.rs
+++ b/datafusion/core/src/execution/session_state.rs
@@ -555,7 +555,7 @@ impl SessionState {
}
let statement = statements.pop_front().ok_or_else(|| {
DataFusionError::NotImplemented(
- "The context requires a statement!".to_string(),
+ "No SQL statements were provided in the query
string".to_string(),
)
})?;
Ok(statement)
diff --git a/datafusion/core/tests/sql/sql_api.rs
b/datafusion/core/tests/sql/sql_api.rs
index 4a6424fc24..e7c40d2c8a 100644
--- a/datafusion/core/tests/sql/sql_api.rs
+++ b/datafusion/core/tests/sql/sql_api.rs
@@ -113,6 +113,40 @@ async fn unsupported_statement_returns_error() {
ctx.sql_with_options(sql, options).await.unwrap();
}
+#[tokio::test]
+async fn empty_statement_returns_error() {
+ let ctx = SessionContext::new();
+ ctx.sql("CREATE TABLE test (x int)").await.unwrap();
+
+ let state = ctx.state();
+
+ // Give it an empty string which contains no statements
+ let plan_res = state.create_logical_plan("").await;
+ assert_eq!(
+ plan_res.unwrap_err().strip_backtrace(),
+ "This feature is not implemented: No SQL statements were provided in
the query string"
+ );
+}
+
+#[tokio::test]
+async fn multiple_statements_returns_error() {
+ let ctx = SessionContext::new();
+ ctx.sql("CREATE TABLE test (x int)").await.unwrap();
+
+ let state = ctx.state();
+
+ // Give it a string that contains multiple statements
+ let plan_res = state
+ .create_logical_plan(
+ "INSERT INTO test (x) VALUES (1); INSERT INTO test (x) VALUES (2)",
+ )
+ .await;
+ assert_eq!(
+ plan_res.unwrap_err().strip_backtrace(),
+ "This feature is not implemented: The context currently only supports
a single SQL statement"
+ );
+}
+
#[tokio::test]
async fn ddl_can_not_be_planned_by_session_state() {
let ctx = SessionContext::new();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]