Skip to content

minor: drive-by refactors for dicts in substring & filter - #10264

Merged
alamb merged 1 commit into
apache:mainfrom
Jefffrey:drive-by-refactors1
Jul 2, 2026
Merged

alamb merged 1 commit into
apache:mainfrom
Jefffrey:drive-by-refactors1

Conversation

@Jefffrey

@Jefffrey Jefffrey commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Some drive-by simplifications whilst I was checking some parts of the codebase.

What changes are included in this PR?

In substring utilize as_any_dictionary() to cut down on lines of code (and also codegen)

In filter, follow similar approach to take when reconstructing a dictionary

Are these changes tested?

Existing tests

Are there any user-facing changes?

No

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jul 2, 2026
// Keys were valid before, filtered subset is therefore still valid
DictionaryArray::from(unsafe { builder.build_unchecked() })
let new_keys = filter_primitive(array.keys(), predicate);
unsafe { DictionaryArray::new_unchecked(new_keys, array.values().clone()) }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see

fn take_dict<T: ArrowDictionaryKeyType, I: ArrowPrimitiveType>(
values: &DictionaryArray<T>,
indices: &PrimitiveArray<I>,
) -> Result<DictionaryArray<T>, ArrowError> {
let new_keys = take_primitive(values.keys(), indices)?;
Ok(unsafe { DictionaryArray::new_unchecked(new_keys, values.values().clone()) })
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is much nicer (and will save a few small allocations, etc)

UInt64: UInt64Type
)
DataType::Dictionary(_, _) => {
let dictionary = array.as_any_dictionary();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice win to use as_any_dictionary() here to dynamically dispatch since we dont need the keys

(i asked codex to look for other places to do this, but the places it identified seemed unsuitable as they still needed keys; so i guess this was the last easy win for this type of refactor)

Ok(Arc::new(dictionary.with_values(values)))
}
DataType::LargeBinary => {
byte_substring(array.as_binary::<i64>(), start, length.map(|e| e as i64))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here just using the more ergonomic as_binary() etc. cast methods

)
fixed_size_binary_substring(array.as_fixed_size_binary(), old_len, start, length)
}
DataType::LargeUtf8 => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i notice we dont actually support views here; i suppose can raise that as a separate issue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though dictionaries of views is likely not super common (as a StringView/ButeView is pretty close to a dictionary already)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i meant the regular path (since this is not only for dict encoded)

@Jefffrey
Jefffrey marked this pull request as ready for review July 2, 2026 08:17

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Jefffrey

// Keys were valid before, filtered subset is therefore still valid
DictionaryArray::from(unsafe { builder.build_unchecked() })
let new_keys = filter_primitive(array.keys(), predicate);
unsafe { DictionaryArray::new_unchecked(new_keys, array.values().clone()) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is much nicer (and will save a few small allocations, etc)

)
fixed_size_binary_substring(array.as_fixed_size_binary(), old_len, start, length)
}
DataType::LargeUtf8 => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though dictionaries of views is likely not super common (as a StringView/ButeView is pretty close to a dictionary already)

@alamb
alamb merged commit af1c24a into apache:main Jul 2, 2026
30 checks passed
@Jefffrey
Jefffrey deleted the drive-by-refactors1 branch July 2, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants