Skip to content

Conversation

@doki23
Copy link
Contributor

@doki23 doki23 commented Nov 13, 2022

Which issue does this PR close?

Closes #4183

What changes are included in this PR?

Most changes are in planner of creating memory table.

Are these changes tested?

Yes.

Are there any user-facing changes?

Users can create a table with a specified schema with a values query.

@github-actions github-actions bot added core Core DataFusion crate sql SQL Planner labels Nov 13, 2022
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.

Thank you @doki23 -- this looks like a nice improvement! I have a few suggestions -- the only thing I think is needed prior to merge is a test for mismatched column count.

We can file a follow up to support specifying column types from a create table as select as a follow on PR

SetExpr::Values(_) => {
let schema = self.build_schema(columns)?.to_dfschema_ref()?;
if schema.fields().len() != input_schema.fields().len() {
return Err(DataFusionError::Plan("Mismatch between schema and batches".to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest adding test for this situation (incorrect length)

Comment on lines 205 to 208
_ => return Err(DataFusionError::Plan(
"You can only specify schema when create table with a `values` statement"
.to_string()
))
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why not support queries as well? Why only VALUES -- the code you have written should work for a CREATE TABLE AS SELECT as well

Copy link
Contributor Author

@doki23 doki23 Nov 16, 2022

Choose a reason for hiding this comment

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

It's because SELECT has its own schema, but surely, it makes sense if someone wants to cast these types. I'll consider your suggestions and add some tests in this situation.

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@doki23
Copy link
Contributor Author

doki23 commented Nov 16, 2022

Thank you @doki23 -- this looks like a nice improvement! I have a few suggestions -- the only thing I think is needed prior to merge is a test for mismatched column count.

We can file a follow up to support specifying column types from a create table as select as a follow on PR

I'm going to do it in this pr, here's no need to file a follow up issue @alamb .

@doki23 doki23 requested a review from alamb November 16, 2022 04:38
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.

Thank you @doki23 -- this looks great!

let ctx = SessionContext::new();
register_aggregate_simple_csv(&ctx).await?;

let sql = "CREATE TABLE my_table(c1 float, c2 double, c3 boolean, c4 varchar) \
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

let ctx = SessionContext::new();
register_aggregate_simple_csv(&ctx).await?;

let sql = "CREATE TABLE my_table(c1 float, c2 double, c3 boolean, c4 varchar) \
Copy link
Contributor

Choose a reason for hiding this comment

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

its-so-beautiful-crying-gif

@alamb alamb changed the title create table with schema Support create table with explicit column definitions Nov 16, 2022
@alamb
Copy link
Contributor

alamb commented Nov 16, 2022

I took the liberty of merging this PR up to master and fixing the clippy issue so we can get it merged. Thanks again @doki23

@alamb
Copy link
Contributor

alamb commented Nov 16, 2022

BTW I also made a small change to one of the tests to satisfy clippy a2172db

@alamb
Copy link
Contributor

alamb commented Nov 16, 2022

Thanks again @doki23

@alamb alamb merged commit 74199d6 into apache:master Nov 16, 2022
@ursabot
Copy link

ursabot commented Nov 16, 2022

Benchmark runs are scheduled for baseline = 88c1201 and contender = 74199d6. 74199d6 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@doki23 doki23 deleted the create_table_with_columns_def branch March 24, 2023 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supporting specifying schema when create tables

3 participants