MCPcopy Create free account
hub / github.com/apache/datafusion / intersect_metadata_for_union

Function intersect_metadata_for_union

datafusion/expr/src/expr.rs:648–671  ·  view source on GitHub ↗

Intersects multiple metadata instances for UNION operations. This function implements the intersection strategy used by UNION operations, where only metadata keys that exist in ALL inputs with identical values are preserved in the result. # Union Metadata Behavior Union operations require consistent metadata across all branches: - Only metadata keys present in ALL union branches are kept - For

(
    metadatas: impl IntoIterator<Item = &'a SchemaFieldMetadata>,
)

Source from the content-addressed store, hash-verified

646///
647/// A new `SchemaFieldMetadata` containing only the intersected metadata
648pub fn intersect_metadata_for_union<'a>(
649 metadatas: impl IntoIterator<Item = &'a SchemaFieldMetadata>,
650) -> SchemaFieldMetadata {
651 let mut intersected: Option<SchemaFieldMetadata> = None;
652
653 for metadata in metadatas {
654 // Skip empty metadata (e.g. from NULL literals or computed expressions)
655 // to avoid dropping metadata from branches that have it.
656 if metadata.is_empty() {
657 continue;
658 }
659 match &mut intersected {
660 None => {
661 intersected = Some(metadata.clone());
662 }
663 Some(current) => {
664 // Only keep keys that exist in both with the same value
665 current.retain(|k, v| metadata.get(k) == Some(v));
666 }
667 }
668 }
669
670 intersected.unwrap_or_default()
671}
672
673/// UNNEST expression.
674#[derive(Clone, PartialEq, Eq, PartialOrd, Hash, Debug)]

Calls 3

is_emptyMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45

Tested by 7

no_inputsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…