You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/07/24 01:16:38 UTC
(datafusion) 01/01: fix: fixed decode buffer size estimate for BinaryViewArray (#23765)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-23765-d7ec10596b7fcf155ea011827890c42c453126b3
in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit abaaa0a3336f09a7bfef272a1cad9c04d894491c
Author: Lining Pan <li...@outlook.com>
AuthorDate: Thu Jul 23 21:16:16 2026 -0400
fix: fixed decode buffer size estimate for BinaryViewArray (#23765)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #23763.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
Previously, output buffer size may be underestimated if the
BinaryViewArray is significantly deduplicated.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
Estimate size by adding up the length of each view.
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
Yes
## Are there any user-facing changes?
No
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
---
datafusion/functions/src/encoding/inner.rs | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/datafusion/functions/src/encoding/inner.rs b/datafusion/functions/src/encoding/inner.rs
index 027ec8e5e5..5d4740d80b 100644
--- a/datafusion/functions/src/encoding/inner.rs
+++ b/datafusion/functions/src/encoding/inner.rs
@@ -292,9 +292,10 @@ fn decode_array(array: &ArrayRef, encoding: Encoding) -> Result<ColumnarValue> {
}
DataType::BinaryView => {
let array = array.as_binary_view();
- // Don't know if there is a more strict upper bound we can infer
- // for view arrays byte data size.
- encoding.decode_array::<_, i32>(&array, array.get_buffer_memory_size())
+ encoding.decode_array::<_, i32>(
+ &array,
+ array.lengths().map(|l| l as usize).sum::<usize>(),
+ )
}
DataType::LargeBinary => {
let array = array.as_binary::<i64>();
@@ -528,7 +529,7 @@ where
#[cfg(test)]
mod tests {
- use arrow::array::BinaryArray;
+ use arrow::array::{ArrayBuilder, BinaryArray, BinaryViewBuilder};
use arrow_buffer::OffsetBuffer;
use super::*;
@@ -553,4 +554,14 @@ mod tests {
let size = estimate_byte_data_size(&array);
assert_eq!(size, 31);
}
+
+ #[test]
+ fn test_estimate_view_size() {
+ let mut builder = BinaryViewBuilder::new().with_deduplicate_strings();
+ for _ in 0..1000 {
+ builder.append_value([65u8; 64]);
+ }
+ let arr = ArrayBuilder::finish(&mut builder);
+ decode_array(&arr, Encoding::Base64).unwrap();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org