-
Notifications
You must be signed in to change notification settings - Fork 72
Minor code cleanup in row_type() #504
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 all commits
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 |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| use pyo3::create_exception; | ||
| use datafusion::error::DataFusionError; | ||
| use pyo3::{create_exception, PyErr}; | ||
|
|
||
| create_exception!(rust, ParsingException, pyo3::exceptions::PyException); | ||
|
|
||
| pub fn py_type_err(e: DataFusionError) -> PyErr { | ||
| PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!("{:?}", e)) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,11 @@ pub mod projection; | |
|
|
||
| pub use datafusion_expr::LogicalPlan; | ||
|
|
||
| use datafusion::common::Result; | ||
| use datafusion::prelude::Column; | ||
| use pyo3::ffi::Py_FatalError; | ||
|
|
||
| use crate::sql::exceptions::py_type_err; | ||
| use pyo3::prelude::*; | ||
|
|
||
| #[pyclass(name = "LogicalPlan", module = "dask_planner", subclass)] | ||
|
|
@@ -140,19 +143,15 @@ impl PyLogicalPlan { | |
| } | ||
|
|
||
| #[pyo3(name = "getRowType")] | ||
| pub fn row_type(&self) -> RelDataType { | ||
| let fields: &Vec<DFField> = self.original_plan.schema().fields(); | ||
| let mut rel_fields: Vec<RelDataTypeField> = Vec::new(); | ||
| for i in 0..fields.len() { | ||
| rel_fields.push( | ||
| RelDataTypeField::from( | ||
| fields[i].clone(), | ||
| self.original_plan.schema().as_ref().clone(), | ||
| ) | ||
| .unwrap(), | ||
| ); | ||
| } | ||
| RelDataType::new(false, rel_fields) | ||
| pub fn row_type(&self) -> PyResult<RelDataType> { | ||
| let schema = self.original_plan.schema(); | ||
| let mut rel_fields: Vec<RelDataTypeField> = schema | ||
| .fields() | ||
| .iter() | ||
| .map(|f| RelDataTypeField::from(f, schema.as_ref())) | ||
| .collect::<Result<Vec<_>>>() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The iterator is over items of type
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. much neater code here. Really like the turbofish use. |
||
| .map_err(|e| py_type_err(e))?; | ||
| Ok(RelDataType::new(false, rel_fields)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyO3 will automatically wrap any return type from an annotated function with
PyResult<T>but maybe it is best to explicitly lay that out. I like that better too.