Skip to content

panic: 'StructArray::new' on zero-field (empty) structs in ScalarValue::compact and ScalarValue::new_default #24581

Description

@unikdahal

Describe the bug

Calling ScalarValue::compact() or ScalarValue::new_default() on a zero-field struct schema (DataType::Struct(Fields::empty())) causes a panic during Arrow struct construction.

In datafusion/common/src/scalar/mod.rs:

• compact_view_buffers and ScalarValue::new_default unconditionally call StructArray::new(...). When a struct has zero fields, no child arrays exist to infer the row length from, leading to a panic in arrow-rs

To Reproduce

use std::sync::Arc;
use arrow::array::StructArray;
use datafusion_common::ScalarValue;
let mut scalar = ScalarValue::Struct(Arc::new(StructArray::new_empty_fields(3, None)));
scalar.compact(); // Panics in StructArray::new

Expected behavior

Zero-field structs should be constructed using StructArray::new_empty_fields(length, nulls) instead of StructArray::new(...).

Additional context

Affects downstream consumers (e.g., Comet) when accumulators call ScalarValue::compact() on empty struct columns or nested containers (List<Struct<>>).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions