-
Notifications
You must be signed in to change notification settings - Fork 159
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
[FEAT]: sql float operations #2834
Merged
universalmind303
merged 12 commits into
Eventual-Inc:main
from
universalmind303:sql-floats
Sep 16, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4f7fe8d
remove this file
universalmind303 8f1c9e1
Merge branch 'main' of https://github.com/Eventual-Inc/Daft
universalmind303 b116660
Merge branch 'main' of https://github.com/Eventual-Inc/Daft
universalmind303 efa8588
Merge branch 'main' of https://github.com/Eventual-Inc/Daft
universalmind303 1b60c2d
Merge branch 'main' of https://github.com/Eventual-Inc/Daft
universalmind303 a91b79f
Merge branch 'main' of https://github.com/Eventual-Inc/Daft
universalmind303 9b303f3
Merge branch 'main' of https://github.com/Eventual-Inc/Daft
universalmind303 60b4e75
Merge branch 'main' of https://github.com/Eventual-Inc/Daft
universalmind303 102ce6b
feat: sql float ops
universalmind303 9383213
register the module
universalmind303 ceec3bd
Merge branch 'main' of https://github.com/Eventual-Inc/Daft into sql-…
universalmind303 7f0752f
Merge branch 'main' of https://github.com/Eventual-Inc/Daft into sql-…
universalmind303 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 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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,70 @@ | ||
use common_error::{DaftError, DaftResult}; | ||
use daft_core::{ | ||
prelude::{Field, Schema}, | ||
series::Series, | ||
utils::supertype::try_get_supertype, | ||
}; | ||
use daft_dsl::{ | ||
functions::{ScalarFunction, ScalarUDF}, | ||
ExprRef, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] | ||
pub struct FillNan {} | ||
|
||
#[typetag::serde] | ||
impl ScalarUDF for FillNan { | ||
fn as_any(&self) -> &dyn std::any::Any { | ||
self | ||
} | ||
fn name(&self) -> &'static str { | ||
"fill_nan" | ||
} | ||
|
||
fn to_field(&self, inputs: &[ExprRef], schema: &Schema) -> DaftResult<Field> { | ||
match inputs { | ||
[data, fill_value] => match (data.to_field(schema), fill_value.to_field(schema)) { | ||
(Ok(data_field), Ok(fill_value_field)) => { | ||
match (&data_field.dtype.is_floating(), &fill_value_field.dtype.is_floating(), try_get_supertype(&data_field.dtype, &fill_value_field.dtype)) { | ||
(true, true, Ok(dtype)) => Ok(Field::new(data_field.name, dtype)), | ||
_ => Err(DaftError::TypeError(format!( | ||
"Expects input for fill_nan to be float, but received {data_field} and {fill_value_field}", | ||
))), | ||
} | ||
} | ||
(Err(e), _) | (_, Err(e)) => Err(e), | ||
}, | ||
_ => Err(DaftError::SchemaMismatch(format!( | ||
"Expected 2 input args, got {}", | ||
inputs.len() | ||
))), | ||
} | ||
} | ||
|
||
fn evaluate(&self, inputs: &[Series]) -> DaftResult<Series> { | ||
match inputs { | ||
[data, fill_value] => data.fill_nan(fill_value), | ||
_ => Err(DaftError::ValueError(format!( | ||
"Expected 2 input args, got {}", | ||
inputs.len() | ||
))), | ||
} | ||
} | ||
} | ||
|
||
pub fn fill_nan(input: ExprRef, fill_value: ExprRef) -> ExprRef { | ||
ScalarFunction::new(FillNan {}, vec![input, fill_value]).into() | ||
} | ||
|
||
#[cfg(feature = "python")] | ||
use { | ||
daft_dsl::python::PyExpr, | ||
pyo3::{pyfunction, PyResult}, | ||
}; | ||
#[cfg(feature = "python")] | ||
#[pyfunction] | ||
#[pyo3(name = "fill_nan")] | ||
pub fn py_fill_nan(expr: PyExpr, fill_value: PyExpr) -> PyResult<PyExpr> { | ||
Ok(fill_nan(expr.into(), fill_value.into()).into()) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Do we not have a
scalar_udf
macro for this? If we do, maybe we could utilize that to avoid all of this boilerplate...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.
Similarly for the other functions inside of
daft-functions/src/float
as well.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 was trying to come up with a macro for this, but I think the consensus was that it wasn't intuitive & could make things harder to debug later on. So I just stuck with copy and paste.