-
Notifications
You must be signed in to change notification settings - Fork 72
[DF] Add support for CREATE TABLE | VIEW AS statements
#656
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
Merged
jdye64
merged 9 commits into
dask-contrib:datafusion-sql-planner
from
charlesbluca:df-create-table-as
Aug 8, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9cd751d
Add support for CREATE TABLE AS
charlesbluca 01314d2
Actually commit the create_memory_table.rs addition
charlesbluca 81f230b
Add TODO for dialect-based if_not_exists handling
charlesbluca 342ec48
Move shared logic between CTAS plugin and Context.sql to _compute_tab…
charlesbluca d9877fd
Switch out Python-facing panics for PyErr
charlesbluca 666adba
Correct return_futures default value
charlesbluca 604f482
Reimplement original persistance behavior with a TODO
charlesbluca 7a14b89
Replace format! calls with string clones
charlesbluca 34ada7a
Clean up match statements
charlesbluca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| use crate::sql::exceptions::py_type_err; | ||
| use crate::sql::logical::PyLogicalPlan; | ||
| use datafusion_expr::{logical_plan::CreateMemoryTable, logical_plan::CreateView, LogicalPlan}; | ||
| use pyo3::prelude::*; | ||
|
|
||
| #[pyclass(name = "CreateMemoryTable", module = "dask_planner", subclass)] | ||
| #[derive(Clone)] | ||
| pub struct PyCreateMemoryTable { | ||
| create_memory_table: Option<CreateMemoryTable>, | ||
| create_view: Option<CreateView>, | ||
| } | ||
|
|
||
| #[pymethods] | ||
| impl PyCreateMemoryTable { | ||
| #[pyo3(name = "getName")] | ||
| pub fn get_name(&self) -> PyResult<String> { | ||
| Ok(match &self.create_memory_table { | ||
| Some(create_memory_table) => create_memory_table.name.clone(), | ||
| None => match &self.create_view { | ||
| Some(create_view) => create_view.name.clone(), | ||
| None => { | ||
| return Err(py_type_err( | ||
| "Encountered a non CreateMemoryTable/CreateView type in get_input", | ||
| )) | ||
| } | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| #[pyo3(name = "getInput")] | ||
| pub fn get_input(&self) -> PyResult<PyLogicalPlan> { | ||
| Ok(match &self.create_memory_table { | ||
| Some(create_memory_table) => PyLogicalPlan { | ||
| original_plan: (*create_memory_table.input).clone(), | ||
| current_node: None, | ||
| }, | ||
| None => match &self.create_view { | ||
| Some(create_view) => PyLogicalPlan { | ||
| original_plan: (*create_view.input).clone(), | ||
| current_node: None, | ||
| }, | ||
| None => { | ||
| return Err(py_type_err( | ||
| "Encountered a non CreateMemoryTable/CreateView type in get_input", | ||
| )) | ||
| } | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| #[pyo3(name = "getIfNotExists")] | ||
| pub fn get_if_not_exists(&self) -> PyResult<bool> { | ||
| Ok(match &self.create_memory_table { | ||
| Some(create_memory_table) => create_memory_table.if_not_exists, | ||
| None => false, // TODO: in the future we may want to set this based on dialect | ||
| }) | ||
| } | ||
|
|
||
| #[pyo3(name = "getOrReplace")] | ||
| pub fn get_or_replace(&self) -> PyResult<bool> { | ||
| Ok(match &self.create_memory_table { | ||
| Some(create_memory_table) => create_memory_table.or_replace, | ||
| None => match &self.create_view { | ||
| Some(create_view) => create_view.or_replace, | ||
| None => { | ||
| return Err(py_type_err( | ||
| "Encountered a non CreateMemoryTable/CreateView type in get_input", | ||
| )) | ||
| } | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| #[pyo3(name = "isTable")] | ||
| pub fn is_table(&self) -> PyResult<bool> { | ||
| Ok(match &self.create_memory_table { | ||
| Some(_) => true, | ||
| None => false, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<LogicalPlan> for PyCreateMemoryTable { | ||
| type Error = PyErr; | ||
|
|
||
| fn try_from(logical_plan: LogicalPlan) -> Result<Self, Self::Error> { | ||
| Ok(match logical_plan { | ||
| LogicalPlan::CreateMemoryTable(create_memory_table) => PyCreateMemoryTable { | ||
| create_memory_table: Some(create_memory_table), | ||
| create_view: None, | ||
| }, | ||
| LogicalPlan::CreateView(create_view) => PyCreateMemoryTable { | ||
| create_memory_table: None, | ||
| create_view: Some(create_view), | ||
| }, | ||
| _ => return Err(py_type_err("unexpected plan")), | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.