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

Extract LogicalPlan::Create* DDL related plan structures into LogicalPlan::Ddl #6121

Merged
merged 4 commits into from
Apr 27, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Apr 25, 2023

Which issue does this PR close?

Part of #1281

Rationale for this change

While reviewing #6096 from @jaylmiller I noticed that the LogicalPlan was getting quite large for the various Catalog manipulation statements

What changes are included in this PR?

Thus I think it is time to finally implement #1281 and isolate these a bit more

Before I went and changed everything though I figured I would put up an RFC that moves the CREATE* DDLs over. I think it looks much nicer.

I will add the DROP variants (like DropTable) as a follow on PR

Are these changes tested?

Covered by existing tests

Are there any user-facing changes?

Yes, this is an API change -- some LogicalPlan variants are now wrapped up another layer of struct

@alamb alamb added the api change Changes the API exposed to users of the crate label Apr 25, 2023
@github-actions github-actions bot added core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules sql SQL Planner labels Apr 25, 2023
@alamb alamb force-pushed the alamb/ddl_in_own_plan branch from 8a86fab to 2dfe8c7 Compare April 25, 2023 20:29
self.create_external_table(&cmd).await
}

LogicalPlan::CreateMemoryTable(CreateMemoryTable {
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 moved this code into separate methods as this particular dispatch method was getting quite large

@@ -628,6 +488,159 @@ impl SessionContext {
self.return_empty_dataframe()
}

async fn create_memory_table(&self, cmd: CreateMemoryTable) -> Result<DataFrame> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved from above

// There is no default plan for "CREATE EXTERNAL
// TABLE" -- it must be handled at a higher level (so
// that the appropriate table can be registered with
LogicalPlan::Ddl(ddl) => {
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 think this reduction of repetition makes the intent of the code clearer

Union, Unnest, UserDefinedLogicalNode, UserDefinedLogicalNodeCore, Values, Window,
WriteOp,
};
pub use logical_plan::*;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this code was just re-exporting all the names in logical_plan anyways so I reduced the duplication


/// Various types of DDL (CREATE / DROP) catalog manipulation
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum DdlStatement {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the new wrapper enum

@@ -1190,28 +1130,6 @@ pub enum JoinConstraint {
Using,
}

/// Creates a catalog (aka "Database").
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to ddl.rs

@alamb alamb marked this pull request as ready for review April 26, 2023 10:35
@alamb
Copy link
Contributor Author

alamb commented Apr 26, 2023

I wonder if you have any thoughts about this change @avantgardnerio @andygrove or @liukun4515

Copy link
Contributor

@crepererum crepererum 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.

Copy link
Contributor

@avantgardnerio avantgardnerio left a comment

Choose a reason for hiding this comment

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

I like it. I've always liked the idea of breaking up DML, DDL, etc - but the one deal breaker for me was that I would definitely like to keep them all as part of the same LogicalPlan so the same planning, optimizing and execution pipeline still works, so that placeholder replacement still works, etc.

This seems to achieve that, so 👍

@alamb alamb merged commit 13c52ce into apache:main Apr 27, 2023
@alamb alamb deleted the alamb/ddl_in_own_plan branch April 27, 2023 20:17
@alamb
Copy link
Contributor Author

alamb commented Apr 27, 2023

I broke the build with this one :sad -- fix #6143

@alamb
Copy link
Contributor Author

alamb commented Apr 27, 2023

FWIW here is the follow on PR to move the DROP variants : #6144

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 core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants