Skip to content

Use Array::to_arc instead of make_array(x.to_data()) and x.slice(0, x.len()) #7755

Backlog

Description

@mbutrovich

What is the problem the feature request solves?

arrow-rs adds Array::to_arc in apache/arrow-rs#12420, and it is expected to ship in arrow 60.3.0 or 61.0.0. It returns an ArrayRef that shares the buffers of a &dyn Array. When the &dyn Array is an &ArrayRef, it returns a new reference to the same allocation.

Comet turns a &dyn Array into an ArrayRef with a workaround in two places:

  • make_array(array.to_data()) in unpack_dictionary, for inputs that aren't dictionary encoded:
    fn unpack_dictionary(array: &dyn Array) -> Result<ArrayRef, SparkError> {
    match array.data_type() {
    DataType::Dictionary(_, value_type) => arrow::compute::cast(array, value_type)
    .map_err(|error| SparkError::Internal(error.to_string())),
    _ => Ok(make_array(array.to_data())),
    }
    }
  • input.slice(0, input.len()) in the extrema test helper:
    fn extrema(input: &dyn Array, is_min: bool) -> ArrayRef {
    let ColumnarValue::Array(result) =
    invoke(ColumnarValue::Array(input.slice(0, input.len())), is_min)

make_array(x.to_data()) builds an ArrayData and then rebuilds a typed array from it. slice(0, len) recounts the null buffer's nulls. to_arc clones an arrow-rs array into a new Arc, and for an ArrayRef it only increments the reference count.

Describe the potential solution

After Comet upgrades to an arrow release that includes Array::to_arc, replace both workarounds with x.to_arc(). Comet's native/Cargo.toml depends on arrow 59.2.0 today, so this waits for that upgrade.

Additional context

The same arrow-rs PR switches arrow's own cast, concat, nullif, and shift from these workarounds to to_arc.

Activity

  1. added
    enhancement
    area:expressions
    and removed on Nov 30, 2026
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

    area:expressionsenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions