pub struct FieldMetadata { /* private fields */ }Expand description
Literal metadata
Stores metadata associated with a literal expressions
and is designed to be fast to clone.
This structure is used to store metadata associated with a literal expression, and it
corresponds to the metadata field on Field.
§Example: Create FieldMetadata from a Field
// Create a new `FieldMetadata` instance from a `Field`
let metadata = FieldMetadata::new_from_field(&field);
// There is also a `From` impl:
let metadata = FieldMetadata::from(&field);§Example: Update a Field with FieldMetadata
// Add any metadata from `FieldMetadata` to `Field`
let updated_field = metadata.add_to_field(field);Implementations§
Source§impl FieldMetadata
 
impl FieldMetadata
Sourcepub fn merge_options(
    m: Option<&FieldMetadata>,
    n: Option<&FieldMetadata>,
) -> Option<FieldMetadata>
 
pub fn merge_options( m: Option<&FieldMetadata>, n: Option<&FieldMetadata>, ) -> Option<FieldMetadata>
Merges two optional FieldMetadata instances, overwriting any existing
keys in m with keys from n if present.
This function is commonly used in alias operations, particularly for literals with metadata. When creating an alias expression, the metadata from the original expression (such as a literal) is combined with any metadata specified on the alias.
§Arguments
- m- The first metadata (typically from the original expression like a literal)
- n- The second metadata (typically from the alias definition)
§Merge Strategy
- If both metadata instances exist, they are merged with ntaking precedence
- Keys from nwill overwrite keys frommif they have the same name
- If only one metadata instance exists, it is returned unchanged
- If neither exists, Noneis returned
§Example usage
use datafusion_expr::expr::FieldMetadata;
use std::collections::BTreeMap;
// Create metadata for a literal expression
let literal_metadata = Some(FieldMetadata::from(BTreeMap::from([
    ("source".to_string(), "constant".to_string()),
    ("type".to_string(), "int".to_string()),
])));
// Create metadata for an alias
let alias_metadata = Some(FieldMetadata::from(BTreeMap::from([
    ("description".to_string(), "answer".to_string()),
    ("source".to_string(), "user".to_string()), // This will override literal's "source"
])));
// Merge the metadata
let merged = FieldMetadata::merge_options(
    literal_metadata.as_ref(),
    alias_metadata.as_ref(),
);
// Result contains: {"source": "user", "type": "int", "description": "answer"}
assert!(merged.is_some());Sourcepub fn new_from_field(field: &Field) -> Self
 
pub fn new_from_field(field: &Field) -> Self
Create a new metadata instance from a Field’s metadata.
Sourcepub fn new(inner: BTreeMap<String, String>) -> Self
 
pub fn new(inner: BTreeMap<String, String>) -> Self
Create a new metadata instance from a map of string keys to string values.
Sourcepub fn inner(&self) -> &BTreeMap<String, String>
 
pub fn inner(&self) -> &BTreeMap<String, String>
Get the inner metadata as a reference to a BTreeMap.
Sourcepub fn extend(&mut self, other: Self)
 
pub fn extend(&mut self, other: Self)
Adds metadata from other into self, overwriting any existing keys.
Sourcepub fn to_hashmap(&self) -> HashMap<String, String>
 
pub fn to_hashmap(&self) -> HashMap<String, String>
Convert this FieldMetadata into a HashMap<String, String>
Sourcepub fn add_to_field(&self, field: Field) -> Field
 
pub fn add_to_field(&self, field: Field) -> Field
Updates the metadata on the Field with this metadata, if it is not empty.
Trait Implementations§
Source§impl Clone for FieldMetadata
 
impl Clone for FieldMetadata
Source§fn clone(&self) -> FieldMetadata
 
fn clone(&self) -> FieldMetadata
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FieldMetadata
 
impl Debug for FieldMetadata
Source§impl Default for FieldMetadata
 
impl Default for FieldMetadata
Source§impl From<&Field> for FieldMetadata
 
impl From<&Field> for FieldMetadata
Source§impl Hash for FieldMetadata
 
impl Hash for FieldMetadata
Source§impl PartialEq for FieldMetadata
 
impl PartialEq for FieldMetadata
Source§impl PartialOrd for FieldMetadata
 
impl PartialOrd for FieldMetadata
impl Eq for FieldMetadata
impl StructuralPartialEq for FieldMetadata
Auto Trait Implementations§
impl Freeze for FieldMetadata
impl RefUnwindSafe for FieldMetadata
impl Send for FieldMetadata
impl Sync for FieldMetadata
impl Unpin for FieldMetadata
impl UnwindSafe for FieldMetadata
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
 
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more