feat: Implement Scalar::From<HashMap<K, V>> - #1541
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1541 +/- ##
==========================================
- Coverage 83.93% 83.92% -0.02%
==========================================
Files 120 120
Lines 32962 32930 -32
Branches 32962 32930 -32
==========================================
- Hits 27668 27637 -31
- Misses 3925 3927 +2
+ Partials 1369 1366 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@Fokko could you fill in the description of the PR please when you get a chance. |
| } | ||
| } | ||
|
|
||
| impl From<Infallible> for Error { |
There was a problem hiding this comment.
I'm not exactly clear what this is doing here, or why we need it? Could you add a comment?
There was a problem hiding this comment.
Good one, I've added a comment, let me know if it makes sense 👍
| fn try_from(opt: Option<Vec<T>>) -> Result<Self, Self::Error> { | ||
| match opt { | ||
| Some(vec) => vec.try_into(), | ||
| None => Ok(Self::Null(ArrayType::new(T::to_data_type(), false).into())), |
There was a problem hiding this comment.
what is the false here? Not nullable?
There was a problem hiding this comment.
would this depend on if T is an Option?
There was a problem hiding this comment.
Yes, exactly! So, if T is wrapped with an Option, then it needs to be set to true. For example, here:
delta-kernel-rs/kernel/src/expressions/scalars.rs
Lines 565 to 576 in 87d2844
T itself cannot be an option, since there is no corresponding Null scalar, so we can assume that they are all not-null.
There was a problem hiding this comment.
Hrmm, we already have:
impl<T> TryFrom<Vec<T>> for Scalarimpl<K, V> TryFrom<HashMap<K, Option<V>>> for Scalarimpl<T: Into<Scalar> + ToDataType> From<Option<T>> for Scalar
If we just added impl<T:TryInto<Scalar> + ToDataType> TryFrom<Option<T>> for Scalar would that get us what we want without having to special case Vec and HashMap?
| in_commit_timestamp, | ||
| operation: Some(operation.unwrap_or_else(|| UNKNOWN_OPERATION.to_string())), | ||
| operation_parameters: None, | ||
| operation_parameters: Some(HashMap::new()), |
| fn try_from(opt: Option<Vec<T>>) -> Result<Self, Self::Error> { | ||
| match opt { | ||
| Some(vec) => vec.try_into(), | ||
| None => Ok(Self::Null(ArrayType::new(T::to_data_type(), false).into())), |
There was a problem hiding this comment.
Hrmm, we already have:
impl<T> TryFrom<Vec<T>> for Scalarimpl<K, V> TryFrom<HashMap<K, Option<V>>> for Scalarimpl<T: Into<Scalar> + ToDataType> From<Option<T>> for Scalar
If we just added impl<T:TryInto<Scalar> + ToDataType> TryFrom<Option<T>> for Scalar would that get us what we want without having to special case Vec and HashMap?
|
Unfortunately, this approach doesn't work due to Rust's trait coherence rules. The standard library has a blanket Adding a generic The special-case implementations for |
Got it, thanks for the explanation |
This PR extends the
IntoEngineDataderive macro to work with structs containingHashMapandOption<Vec<T>>fields by implementing the necessaryTryFromconversions forScalar. This is foundational work to support reading arbitrary fields fromCommitInfo.This resolves #1083.
What changes are proposed in this pull request?
How was this change tested?