Skip to content

StringViewArrayBuilder::with_capacity uses wrong capacity #21864

@Rafferty97

Description

@Rafferty97

Describe the bug

When reading the implementation of StringViewArrayBuilder::with_capacity at datafusion/functions/src/strings.rs:136:

    pub fn with_capacity(_item_capacity: usize, data_capacity: usize) -> Self {
        let builder = StringViewBuilder::with_capacity(data_capacity);
        Self {
            builder,
            block: String::new(),
        }
    }

I could be mistaken, but I think that item_capacity should be passed to the inner with_capacity call rather than data_capacity. The StringViewBuilder::with_capacity call reserves space for the string offsets, which is proportional to the number of strings, not the total number of bytes used by those strings.

Obviously this is just a performance bug, not a correctness issue.

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions