Encapsulate metadata for literals on to a FieldMetadata structure#16317
Encapsulate metadata for literals on to a FieldMetadata structure#16317alamb merged 4 commits intoapache:mainfrom
FieldMetadata structure#16317Conversation
9752ed6 to
a916b4c
Compare
FieldMetadata structure
|
I also found we can further unify the metadata handling for Expr::Alias as well, but would like to propose doing that as a follow on PR: |
| /// A constant value along with associated metadata | ||
| Literal(ScalarValue, Option<BTreeMap<String, String>>), | ||
| /// A constant value along with associated [`FieldMetadata`]. | ||
| Literal(ScalarValue, Option<FieldMetadata>), |
There was a problem hiding this comment.
The point of this PR is to put all metadata handling in a Struct to make it easier to work with (and more efficient)
| metadata | ||
| .map(|m| m.into_iter().collect::<HashMap<String, String>>()), | ||
| ))) | ||
| Ok(Transformed::yes(lit_with_metadata(utf8_val, metadata))) |
There was a problem hiding this comment.
this is a pretty good example of the kind of simplification this PR allows (don't have to translate back/forth between HashMap / BTreeMap in various places)
| false => Some(new_metadata), | ||
| }; | ||
|
|
||
| let metadata = metadata.as_ref().map(|m| FieldMetadata::from(m.clone())); |
There was a problem hiding this comment.
I remove this clone in a follow on PR:
timsaucer
left a comment
There was a problem hiding this comment.
Thank you. This is a very nice cleanup of the prior code.
|
Here is a follow on PR to also use the same structure in |
Which issue does this PR close?
Related to Support metadata on literal values #15797
Follow on to feat: add metadata to literal expressions #16170
This is an updated version of Encapsulate FieldMetadata timsaucer/datafusion#2
Rationale for this change
As discussed on #16170 (comment), we made an initial PR to add metadata to Expr::Literal as part of DataFusion 48, but the API could use a bit of fine tuning to:
What changes are included in this PR?
FieldMetadataArcto make it fast to cloneAre these changes tested?
Are there any user-facing changes?