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

Add Create Schema functionality in SQL #1959

Merged
merged 7 commits into from
Mar 17, 2022

Conversation

matthewmturner
Copy link
Contributor

Which issue does this PR close?

Task 1 for #1877

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added datafusion Changes in the datafusion crate sql SQL Planner labels Mar 8, 2022
@matthewmturner
Copy link
Contributor Author

I'm working on this and im wondering why register_schema isnt a trait method for CatalogProvider. For example register_table is part of SchemaProvider trait and i consider a schema to be the equivalent for a catalog.

@matthewmturner
Copy link
Contributor Author

This has surprisingly been a bit of a pain. Currently having issues with getting the schema registration to work. At the moment its not clear to me what the issue is.

"test".into(),
Arc::new(DataFrameImpl::new(self.state.clone(), &plan)),
)?;
let schem_reg_res = catalog.register_schema(&schema_name, schema);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not clear to me why registering schema here isnt working. I reregister the catalog below just in case but still has no effect. I wasnt expecting to have to reregister. Still digging deep into the implementations to get better idea whats going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(i know theres a lot of fluff right now that im using for debugging purposes)

@matthewmturner
Copy link
Contributor Author

Got this working. Just need to resolve conflicts.

@alamb do you have preference on whether to leave this PR as is or if i can also add CREATE CATALOG on here? I see sql-parser has a CreateDatabase statement already that i was thinking i could use. Or do you think that would get confusing? i.e. CREATE DATABASE would call ctx.register_catalog and then be visible as a catalog.

@matthewmturner matthewmturner marked this pull request as ready for review March 14, 2022 16:21
@matthewmturner
Copy link
Contributor Author

Ah need to do ballista update still

@alamb
Copy link
Contributor

alamb commented Mar 14, 2022

@alamb do you have preference on whether to leave this PR as is or if i can also add CREATE CATALOG on here?

I suggest we do it in a follow on PR to keep this one smaller.

I see sql-parser has a CreateDatabase statement already that i was thinking i could use. Or do you think that would get confusing? i.e. CREATE DATABASE would call ctx.register_catalog and then be visible as a catalog

seems reasonable

(sorry for the delayed replies -- I am only inline intermittently this week)

@matthewmturner
Copy link
Contributor Author

@alamb i believe this is ready now

@yjshen yjshen added enhancement New feature or request api change Changes the API exposed to users of the crate labels Mar 16, 2022
table: parts[2],
},
_ => Self::Bare { table: s },
}
}
Copy link
Contributor

@doki23 doki23 Mar 17, 2022

Choose a reason for hiding this comment

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

👍🏻! It's helpful to me!

Copy link
Contributor

@doki23 doki23 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks good to me -- thanks @doki23 and @matthewmturner !

@@ -2907,6 +2947,29 @@ mod tests {
assert_eq!(Weak::strong_count(&catalog_weak), 0);
}

#[tokio::test]
async fn sql_create_schema() -> Result<()> {
// the information schema used to introduce cyclic Arcs
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure what this comment means

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops that may have been straggling comment from a copy paste, sry about that. i can remove in subsequent PR

if_not_exists,
..
}) => {
// sqlparser doesnt accept database / catalog as parameter to CREATE SCHEMA
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe worth a ticket to sqlparser to support this? Or maybe just a PR :)


let schema = catalog.schema(&schema_name);

match (if_not_exists, schema) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate datafusion Changes in the datafusion crate enhancement New feature or request sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants