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

improve error message for invalid create table statement #1294

Merged
merged 2 commits into from
Nov 15, 2021

Conversation

houqp
Copy link
Member

@houqp houqp commented Nov 14, 2021

Rationale for this change

We show Only SELECT statements are implemented when user entered an invalid create table query in datafusion-cli, which is misleading.

What changes are included in this PR?

Change the error message to make it match the features we have today.

Are there any user-facing changes?

no

@houqp houqp added the bug Something isn't working label Nov 14, 2021
@houqp houqp requested a review from Dandandan November 14, 2021 07:50
@github-actions github-actions bot added datafusion Changes in the datafusion crate sql SQL Planner labels Nov 14, 2021
{
let plan = self.query_to_plan(query)?;
} => {
if columns.is_empty()
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: I prefer match guard to if here. Just like other options(or_replace, if_not_exists, etc) are being pattern matched.
Because it feel like bit confusing to see different error messages across different create table variants.

❯ create table a;
NotImplemented("Unsupported SQL statement: CreateTable { or_replace: false, temporary: false, external: false, if_not_exists: false, name: ObjectName([Ident { value: \"a\", quote_style: None }]), columns: [], constraints: [], hive_distribution: NONE, hive_formats: Some(HiveFormat { row_format: None, storage: None, location: None }), table_properties: [], with_options: [], file_format: None, location: None, query: None, without_rowid: false, like: None }")
❯ create table if not exists a as select 1 as col1;
NotImplemented("Unsupported SQL statement: CreateTable { or_replace: false, temporary: false, external: false, if_not_exists: true, name: ObjectName([Ident { value: \"a\", quote_style: None }]), columns: [], constraints: [], hive_distribution: NONE, hive_formats: Some(HiveFormat { row_format: None, storage: None, location: None }), table_properties: [], with_options: [], file_format: None, location: None, query: Some(Query { with: None, body: Select(Select { distinct: false, top: None, projection: [ExprWithAlias { expr: Value(Number(\"1\", false)), alias: Ident { value: \"col1\", quote_style: None } }], from: [], lateral_views: [], selection: None, group_by: [], cluster_by: [], distribute_by: [], sort_by: [], having: None }), order_by: [], limit: None, offset: None, fetch: None }), without_rowid: false, like: None }")
❯ create table a(id string) as select 1 as col1;
NotImplemented("Only `CREATE TABLE table_name AS SELECT ...` statement is supported")

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, I have pushed a new commit to address this.

"Only SELECT statements are implemented".to_string(),
)),
_ => Err(DataFusionError::NotImplemented(format!(
"Unsupported 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.

❤️

@alamb alamb merged commit ab72703 into apache:master Nov 15, 2021
@houqp houqp deleted the qp_create_table branch November 15, 2021 21:26
matthewmturner pushed a commit to matthewmturner/arrow-datafusion that referenced this pull request Nov 16, 2021
* improve error message for invalid create table statement

* handle different create table cases using match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datafusion Changes in the datafusion crate sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants