You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "anoopj (via GitHub)" <gi...@apache.org> on 2026/08/26 16:38:05 UTC

[PR] perf(arrow): build repeated constant string/binary columns without per-row clones [iceberg-rust]

anoopj opened a new pull request, #3080:
URL: https://github.com/apache/iceberg-rust/pull/3080

   ## Which issue does this PR close?
   
   Fixes #3079
   
   ## What changes are included in this PR?
   
   `create_primitive_array_repeated` built a throwaway `vec![value.clone(); num_rows]` for the Utf8/Binary/LargeBinary/FixedSizeBinary arms before handing it to the array constructor. For strings that clones the value into num_rows separate heap allocations per batch; the binary arms allocate a throwaway intermediate Vec.
   
   Stream the single value straight into the Arrow buffer via `from_iter_values` with `std::iter::repeat_n` instead.
   
   Benchmarks (release, throwaway harness, old vs new toggled on this file only):
   - leaf create_primitive_array_repeated (Utf8, 8192-row batch): 23.0 -> 4.1 ns/row (5.6x)
   - full scan select(x, _partition) over a real manifest + 262k-row parquet file, string-partitioned: 20.9 -> 5.7 ns/row (3.7x)
   
   Note that the gain is allocation-counts and scales with how much of the projection is the string partition column.
   
   ## Are these changes tested?
   
   New + old tests


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] perf(arrow): build repeated constant string/binary columns without per-row clones [iceberg-rust]

Posted by "laskoviymishka (via GitHub)" <gi...@apache.org>.
laskoviymishka commented on code in PR #3080:
URL: https://github.com/apache/iceberg-rust/pull/3080#discussion_r3866194789


##########
crates/iceberg/src/arrow/value.rs:
##########
@@ -864,24 +864,24 @@ pub(crate) fn create_primitive_array_repeated(
         (DataType::Float64, Some(PrimitiveLiteral::Double(value))) => {
             Arc::new(Float64Array::from(vec![value.0; num_rows]))
         }
-        (DataType::Utf8, Some(PrimitiveLiteral::String(value))) => {
-            Arc::new(StringArray::from(vec![value.clone(); num_rows]))
-        }
-        (DataType::Binary, Some(PrimitiveLiteral::Binary(value))) => {
-            Arc::new(BinaryArray::from_vec(vec![value; num_rows]))
-        }
-        (DataType::LargeBinary, Some(PrimitiveLiteral::Binary(value))) => {
-            Arc::new(LargeBinaryArray::from_vec(vec![value; num_rows]))
-        }
-        (DataType::FixedSizeBinary(len), Some(PrimitiveLiteral::Binary(value))) => {
-            let repeated: Vec<&[u8]> = vec![value.as_slice(); num_rows];
-            Arc::new(FixedSizeBinaryArray::try_from_iter(repeated.into_iter()).map_err(|e| {
-                Error::new(
-                    ErrorKind::DataInvalid,
-                    format!("Failed to create FixedSizeBinary({len}) array: {e}"),
-                )
-            })?)
-        }
+        (DataType::Utf8, Some(PrimitiveLiteral::String(value))) => Arc::new(
+            StringArray::from_iter_values(std::iter::repeat_n(value.as_str(), num_rows)),
+        ),
+        (DataType::Binary, Some(PrimitiveLiteral::Binary(value))) => Arc::new(
+            BinaryArray::from_iter_values(std::iter::repeat_n(value.as_slice(), num_rows)),
+        ),
+        (DataType::LargeBinary, Some(PrimitiveLiteral::Binary(value))) => Arc::new(
+            LargeBinaryArray::from_iter_values(std::iter::repeat_n(value.as_slice(), num_rows)),
+        ),
+        (DataType::FixedSizeBinary(len), Some(PrimitiveLiteral::Binary(value))) => Arc::new(
+            FixedSizeBinaryArray::try_from_iter(std::iter::repeat_n(value.as_slice(), num_rows))

Review Comment:
   I think there's a subtle edge worth nailing down while we're touching this arm. `try_from_iter` infers the fixed width from the data it's handed, not from the `len` we matched on — so with `num_rows == 0` the iterator is empty and we get back a `FixedSizeBinary(0)` array no matter what the schema declared, and an empty batch over a `fixed[n]` partition column (any filter that drops all rows) would then hand a type-mismatched array to `RecordBatch::try_new`. Same story if a literal's length doesn't equal `*len` — `len` only feeds the error string today, so a wrong-width value silently produces the wrong type rather than erroring.
   
   Both are pre-existing rather than introduced here, but the new empty-batch test only covers `Utf8`. Extending `test_create_string_array_repeated_empty` to `FixedSizeBinary(4) + num_rows=0` and asserting `data_type()` would either prove it's fine or pin it down, and a `value.len() == *len` guard before `try_from_iter` would close the wrong-width case. wdyt?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] perf(arrow): build repeated constant string/binary columns without per-row clones [iceberg-rust]

Posted by "laskoviymishka (via GitHub)" <gi...@apache.org>.
laskoviymishka merged PR #3080:
URL: https://github.com/apache/iceberg-rust/pull/3080


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] perf(arrow): build repeated constant string/binary columns without per-row clones [iceberg-rust]

Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #3080:
URL: https://github.com/apache/iceberg-rust/pull/3080#discussion_r3873791649


##########
crates/iceberg/src/arrow/value.rs:
##########
@@ -864,24 +864,24 @@ pub(crate) fn create_primitive_array_repeated(
         (DataType::Float64, Some(PrimitiveLiteral::Double(value))) => {
             Arc::new(Float64Array::from(vec![value.0; num_rows]))
         }
-        (DataType::Utf8, Some(PrimitiveLiteral::String(value))) => {
-            Arc::new(StringArray::from(vec![value.clone(); num_rows]))
-        }
-        (DataType::Binary, Some(PrimitiveLiteral::Binary(value))) => {
-            Arc::new(BinaryArray::from_vec(vec![value; num_rows]))
-        }
-        (DataType::LargeBinary, Some(PrimitiveLiteral::Binary(value))) => {
-            Arc::new(LargeBinaryArray::from_vec(vec![value; num_rows]))
-        }
-        (DataType::FixedSizeBinary(len), Some(PrimitiveLiteral::Binary(value))) => {
-            let repeated: Vec<&[u8]> = vec![value.as_slice(); num_rows];
-            Arc::new(FixedSizeBinaryArray::try_from_iter(repeated.into_iter()).map_err(|e| {
-                Error::new(
-                    ErrorKind::DataInvalid,
-                    format!("Failed to create FixedSizeBinary({len}) array: {e}"),
-                )
-            })?)
-        }
+        (DataType::Utf8, Some(PrimitiveLiteral::String(value))) => Arc::new(
+            StringArray::from_iter_values(std::iter::repeat_n(value.as_str(), num_rows)),
+        ),
+        (DataType::Binary, Some(PrimitiveLiteral::Binary(value))) => Arc::new(
+            BinaryArray::from_iter_values(std::iter::repeat_n(value.as_slice(), num_rows)),
+        ),
+        (DataType::LargeBinary, Some(PrimitiveLiteral::Binary(value))) => Arc::new(
+            LargeBinaryArray::from_iter_values(std::iter::repeat_n(value.as_slice(), num_rows)),
+        ),
+        (DataType::FixedSizeBinary(len), Some(PrimitiveLiteral::Binary(value))) => Arc::new(
+            FixedSizeBinaryArray::try_from_iter(std::iter::repeat_n(value.as_slice(), num_rows))

Review Comment:
   Thanks. I think both are valid findings and pre-existing as you noted. 
   
   >  Wrong-width literal
   
   I added a guard on `len` before `try_from_iter` so a mismatched-width literal errors with the constraint, and added a test. 
   
   > Empty batch
   
   I looked into `try_from_iter` in arrow 58.3. It doesn't come back as `FixedSizeBinary(0)`; it has an explicit `if len == 0 { return Err(""..) }` guard. So num_rows == 0 over a fixed[n] column surfaces as a hard `DataInvalid` error. So it's a loud failure. R
   
    I added a test that pins this "empty -> Err" behavior. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org