Skip to content

Add arrow_metadata(<expr>) UDF #19356

Closed

Description

@adriangb

As discussed in #19335 it would be nice to have a function arrow_metadata similar to arrow_typeof that returns the metadata from it's input field as a Map<String, String> column. Ideally it could support two signatures arrow_metadata(column_or_expr) -> Map<String, String> and arrow_metadata(column_or_expr, 'key') -> String.

Activity

  1. Jefffrey commented on Dec 17, 2025

    @Jefffrey
    Contributor

    Existing reference:

    /// UDF to extract metadata from a field for testing purposes
    /// Usage: get_metadata(expr, 'key') -> returns the metadata value or NULL
    #[derive(Debug, PartialEq, Eq, Hash)]
    struct GetMetadataUdf {
    signature: Signature,
    }
    impl GetMetadataUdf {
    fn new() -> Self {
    Self {
    signature: Signature::any(2, Volatility::Immutable),
    }
    }
    }
    impl ScalarUDFImpl for GetMetadataUdf {
    fn as_any(&self) -> &dyn Any {
    self
    }
    fn name(&self) -> &str {
    "get_metadata"
    }
    fn signature(&self) -> &Signature {
    &self.signature
    }
    fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
    Ok(DataType::Utf8)
    }
    fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
    // Get the metadata key from the second argument (must be a string literal)
    let key = match &args.args[1] {
    ColumnarValue::Scalar(ScalarValue::Utf8(Some(k))) => k.clone(),
    _ => {
    return exec_err!("get_metadata second argument must be a string literal")
    }
    };
    // Get metadata from the first argument's field
    let metadata_value = args.arg_fields[0].metadata().get(&key).cloned();
    // Return as a scalar (same value for all rows)
    Ok(ColumnarValue::Scalar(ScalarValue::Utf8(metadata_value)))
    }
    }

    As part of this issue, we should remove the above UDF and use the new arrow_metadata() UDF directly in the tests

  2. added a commit that references this issue on Dec 23, 2025
    d844f86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions