-
Notifications
You must be signed in to change notification settings - Fork 175
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
[CHORE] Rust Logical plan skeleton #1192
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1192 +/- ##
=======================================
Coverage 88.40% 88.41%
=======================================
Files 55 55
Lines 5606 5617 +11
=======================================
+ Hits 4956 4966 +10
- Misses 650 651 +1 |
|
||
#[derive(Clone)] | ||
pub struct LogicalPlanBuilder { | ||
_plan: Arc<LogicalPlan>, |
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.
Probably don't need the underscore prefix to denote that the field is private, since struct fields are private by default and would only be made public with the pub plan
qualifier.
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.
I needed to do it for clippy since the field is not yet used 😅
src/daft-plan/src/builder.rs
Outdated
// Create a new LogicalPlanBuilder for a Source node. | ||
pub fn new_plan_from_source(filepaths: Vec<String>, schema: SchemaRef) -> LogicalPlanBuilder { | ||
let source_info = source_info::SourceInfo::FilesInfo(source_info::FilesInfo { | ||
filepaths, | ||
schema: schema.clone(), | ||
}); | ||
let source_node = LogicalPlan::Source(ops::Source { | ||
schema, | ||
source_info: source_info.into(), | ||
filters: vec![], // Will be populated by plan optimizer. | ||
limit: None, // Will be populated by plan optimizer. | ||
}); | ||
LogicalPlanBuilder { | ||
_plan: source_node.into(), | ||
} | ||
} |
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.
Nit: Since this is a creator for LogicalPlanBuilder
, it would probably make more sense to have this as a from_source
method.
We should also probably have FilesInfo::new()
and Source::new()
constructor methods for those structs, especially the latter which will always set empty fields that will be populated later.
// Create a new LogicalPlanBuilder for a Source node. | |
pub fn new_plan_from_source(filepaths: Vec<String>, schema: SchemaRef) -> LogicalPlanBuilder { | |
let source_info = source_info::SourceInfo::FilesInfo(source_info::FilesInfo { | |
filepaths, | |
schema: schema.clone(), | |
}); | |
let source_node = LogicalPlan::Source(ops::Source { | |
schema, | |
source_info: source_info.into(), | |
filters: vec![], // Will be populated by plan optimizer. | |
limit: None, // Will be populated by plan optimizer. | |
}); | |
LogicalPlanBuilder { | |
_plan: source_node.into(), | |
} | |
} | |
impl LogicalPlanBuilder { | |
// Create a new LogicalPlanBuilder for a Source node. | |
pub fn from_source(filepaths: Vec<String>, schema: SchemaRef) -> Self { | |
let source_info = source_info::SourceInfo::FilesInfo(source_info::FilesInfo::new(filepaths, schema); | |
let source_node = LogicalPlan::Source(ops::Source::new(schema, source_info.into()); | |
Self { | |
_plan: source_node.into(), | |
} | |
} |
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.
Done! I also made from_source
take a Source struct.
src/daft-plan/src/pyapi.rs
Outdated
|
||
#[pyclass] | ||
#[derive(Clone)] | ||
pub struct PyLogicalPlanBuilder { |
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.
Could we expose the LogicalPlanBuilder
directly via pyo3 rather than wrapping, similar to what we did for the ImageMode
enum?
Daft/src/daft-core/src/datatypes/image_mode.rs
Lines 27 to 58 in bc11e57
#[cfg_attr(feature = "python", pyclass)] | |
pub enum ImageMode { | |
L = 1, | |
LA = 2, | |
RGB = 3, | |
RGBA = 4, | |
L16 = 5, | |
LA16 = 6, | |
RGB16 = 7, | |
RGBA16 = 8, | |
RGB32F = 9, | |
RGBA32F = 10, | |
} | |
#[cfg(feature = "python")] | |
#[pymethods] | |
impl ImageMode { | |
/// Create an ImageMode from its string representation. | |
/// | |
/// Args: | |
/// mode: String representation of the mode. This is the same as the enum | |
/// attribute name, e.g. ``ImageMode.from_mode_string("RGB")`` would | |
/// return ``ImageMode.RGB``. | |
#[staticmethod] | |
pub fn from_mode_string(mode: &str) -> PyResult<Self> { | |
Self::from_str(mode).map_err(|e| PyValueError::new_err(e.to_string())) | |
} | |
pub fn __str__(&self) -> PyResult<String> { | |
Ok(self.to_string()) | |
} | |
} |
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.
Thank you for this! Done, and removed the pyapi module entirely.
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.
LGTM!
#[cfg(feature = "python")] | ||
use daft_core::python::schema::PySchema; | ||
#[cfg(feature = "python")] | ||
use pyo3::prelude::*; |
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.
Also, if the number of these use
s increases, we can have a single attribute specification apply to an entire block of imports using this syntax:
Daft/src/daft-core/src/array/ops/cast.rs
Lines 27 to 40 in d032844
#[cfg(feature = "python")] | |
use { | |
crate::array::pseudo_arrow::PseudoArrowArray, | |
crate::datatypes::{ListArray, PythonArray}, | |
crate::ffi, | |
crate::with_match_numeric_daft_types, | |
log, | |
ndarray::IntoDimension, | |
num_traits::{NumCast, ToPrimitive}, | |
numpy::{PyArray3, PyReadonlyArrayDyn}, | |
pyo3::prelude::*, | |
std::iter, | |
std::ops::Deref, | |
}; |
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.
Actually, I think you were the one to make that change in your Duration
dtype PR, I didn't know about that syntax until I saw your change! 😄
Skeleton for new logical plan in Rust. Includes the following building blocks:
Next steps (separate PRs):