-
Notifications
You must be signed in to change notification settings - Fork 71
[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
Changes from 2 commits
9cd751d
01314d2
81f230b
342ec48
d9877fd
666adba
604f482
7a14b89
34ada7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| 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> { | ||
| match &self.create_memory_table { | ||
| Some(create_memory_table) => Ok(format!("{}", create_memory_table.name)), | ||
| None => match &self.create_view { | ||
| Some(create_view) => Ok(format!("{}", create_view.name)), | ||
charlesbluca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| None => panic!("Encountered a non CreateMemoryTable/CreateView type in get_name"), | ||
|
||
| }, | ||
| } | ||
| } | ||
|
|
||
| #[pyo3(name = "getInput")] | ||
| pub fn get_input(&self) -> PyResult<PyLogicalPlan> { | ||
| Ok(PyLogicalPlan { | ||
| original_plan: match &self.create_memory_table { | ||
| Some(create_memory_table) => (*create_memory_table.input).clone(), | ||
| None => match &self.create_view { | ||
| Some(create_view) => (*create_view.input).clone(), | ||
| None => { | ||
| panic!("Encountered a non CreateMemoryTable/CreateView type in get_input") | ||
| } | ||
| }, | ||
| }, | ||
| current_node: None, | ||
| }) | ||
| } | ||
|
|
||
| #[pyo3(name = "getIfNotExists")] | ||
| pub fn get_if_not_exists(&self) -> PyResult<bool> { | ||
| match &self.create_memory_table { | ||
| Some(create_memory_table) => Ok(create_memory_table.if_not_exists), | ||
| None => Ok(false), | ||
charlesbluca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| #[pyo3(name = "getOrReplace")] | ||
| pub fn get_or_replace(&self) -> PyResult<bool> { | ||
| match &self.create_memory_table { | ||
| Some(create_memory_table) => Ok(create_memory_table.or_replace), | ||
| None => match &self.create_view { | ||
| Some(create_view) => Ok(create_view.or_replace), | ||
| None => panic!("Encountered a non CreateMemoryTable/CreateView type in get_name"), | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<LogicalPlan> for PyCreateMemoryTable { | ||
| type Error = PyErr; | ||
|
|
||
| fn try_from(logical_plan: LogicalPlan) -> Result<Self, Self::Error> { | ||
| match logical_plan { | ||
| LogicalPlan::CreateMemoryTable(create_memory_table) => Ok(PyCreateMemoryTable { | ||
| create_memory_table: Some(create_memory_table), | ||
| create_view: None, | ||
| }), | ||
| LogicalPlan::CreateView(create_view) => Ok(PyCreateMemoryTable { | ||
| create_memory_table: None, | ||
| create_view: Some(create_view), | ||
| }), | ||
| _ => Err(py_type_err("unexpected plan")), | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.