Skip to content

Commit

Permalink
Minor: Change no-statement error message to be clearer (apache#11394)
Browse files Browse the repository at this point in the history
* Change no-statement error message to be clearer and add tests for said change

* Run fmt to pass CI
  • Loading branch information
itsjunetime authored Jul 10, 2024
1 parent 32cb3c5 commit cc7484e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datafusion/core/src/execution/session_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions datafusion/core/tests/sql/sql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit cc7484e

Please sign in to comment.