Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Change no-statement error message to be clearer #11394

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for adding additional test coverage

);
}

#[tokio::test]
async fn ddl_can_not_be_planned_by_session_state() {
let ctx = SessionContext::new();
Expand Down
Loading