This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 182c7a95b3 Fix clippy warning in fixed_size_binary_array.rs (#9712)
182c7a95b3 is described below
commit 182c7a95b38565e81c76d0c15ee6d1819933a16b
Author: Adam Gutglick <[email protected]>
AuthorDate: Thu Apr 16 12:33:15 2026 +0100
Fix clippy warning in fixed_size_binary_array.rs (#9712)
# Which issue does this PR close?
- Closes #NNN.
# Rationale for this change
This is a future lint, so I took to the opportunity to make this it
clear that the length validation only needs to happen in one case.
# What changes are included in this PR?
Minor changes to validation in `FixedSizeBinaryArray::try_new`.
# Are these changes tested?
Added some assertions to existing tests.
# Are there any user-facing changes?
None
---
arrow-array/src/array/fixed_size_binary_array.rs | 44 ++++++++++++++----------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/arrow-array/src/array/fixed_size_binary_array.rs
b/arrow-array/src/array/fixed_size_binary_array.rs
index 72e6d022a5..e8272be5d6 100644
--- a/arrow-array/src/array/fixed_size_binary_array.rs
+++ b/arrow-array/src/array/fixed_size_binary_array.rs
@@ -94,27 +94,31 @@ impl FixedSizeBinaryArray {
ArrowError::InvalidArgumentError(format!("Size cannot be negative,
got {size}"))
})?;
- let len = if s == 0 {
- if !values.is_empty() {
- return Err(ArrowError::InvalidArgumentError(
- "Buffer cannot have non-zero length if the item size is
zero".to_owned(),
- ));
+ let len = match values.len().checked_div(s) {
+ Some(len) => {
+ if let Some(n) = nulls.as_ref() {
+ if n.len() != len {
+ return Err(ArrowError::InvalidArgumentError(format!(
+ "Incorrect length of null buffer for
FixedSizeBinaryArray, expected {} got {}",
+ len,
+ n.len(),
+ )));
+ }
+ }
+
+ len
}
+ None => {
+ if !values.is_empty() {
+ return Err(ArrowError::InvalidArgumentError(
+ "Buffer cannot have non-zero length if the item size
is zero".to_owned(),
+ ));
+ }
- // If the item size is zero, try to determine the length from the
null buffer
- nulls.as_ref().map(|n| n.len()).unwrap_or(0)
- } else {
- values.len() / s
- };
- if let Some(n) = nulls.as_ref() {
- if n.len() != len {
- return Err(ArrowError::InvalidArgumentError(format!(
- "Incorrect length of null buffer for FixedSizeBinaryArray,
expected {} got {}",
- len,
- n.len(),
- )));
+ // If the item size is zero, try to determine the length from
the null buffer
+ nulls.as_ref().map(|n| n.len()).unwrap_or(0)
}
- }
+ };
Ok(Self {
data_type,
@@ -1032,10 +1036,14 @@ mod tests {
let zero_sized = FixedSizeBinaryArray::new(0, Buffer::default(), None);
assert_eq!(zero_sized.len(), 0);
+ assert_eq!(zero_sized.null_count(), 0);
+ assert_eq!(zero_sized.values().len(), 0);
let nulls = NullBuffer::new_null(3);
let zero_sized_with_nulls = FixedSizeBinaryArray::new(0,
Buffer::default(), Some(nulls));
assert_eq!(zero_sized_with_nulls.len(), 3);
+ assert_eq!(zero_sized_with_nulls.null_count(), 3);
+ assert_eq!(zero_sized_with_nulls.values().len(), 0);
let zero_sized_with_non_empty_buffer_err =
FixedSizeBinaryArray::try_new(0, buffer, None).unwrap_err();