You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Rich-T-kid (via GitHub)" <gi...@apache.org> on 2026/08/27 20:15:35 UTC
[PR] docs: update primitive docs to focus on vec [arrow-rs]
Rich-T-kid opened a new pull request, #10898:
URL: https://github.com/apache/arrow-rs/pull/10898
# 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.
-->
- Closes #NNN.
# 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.
-->
# 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.
-->
# 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)?
If this PR claims a performance improvement, please include evidence such as benchmark results.
-->
# Are there any user-facing changes?
<!--
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 call them out.
-->
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] docs: update primitive docs to focus on vec [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #10898:
URL: https://github.com/apache/arrow-rs/pull/10898#discussion_r3879445851
##########
arrow-array/src/builder/primitive_builder.rs:
##########
@@ -99,33 +99,44 @@ pub type Decimal256Builder = PrimitiveBuilder<Decimal256Type>;
///
/// # Performance
///
-/// When all values are known upfront, prefer constructing a [`PrimitiveArray`] directly
-/// via [`PrimitiveArray::from`] or [`PrimitiveArray::new`] instead of using this builder.
-/// Direct construction reuses the existing allocation (zero-copy from `Vec`) and avoids
-/// the overhead of per-element bookkeeping, making it significantly faster.
-///
-/// Use [`PrimitiveBuilder`] when values must be appended **incrementally** — for example,
-/// inside a loop where the final size is not known in advance.
-///
-/// # Example
+/// Rust's `Vec` is highly optimized, and Arrow's conversion from `Vec` to
+/// [`PrimitiveArray`] is zero-copy — the array reuses the same underlying allocation
+/// without any data being copied. If your values are already in a `Vec`, or can be
+/// collected into one, prefer constructing a [`PrimitiveArray`] directly:
///
/// ```
/// # use arrow_array::{Int32Array, Array};
-/// // Prefer this when values are known upfront (zero-copy, no per-element overhead):
+/// // Zero-copy: the array reuses the Vec's allocation
/// let array = Int32Array::from(vec![1, 2, 3]);
/// assert_eq!(array.len(), 3);
/// ```
///
+/// Internally, [`PrimitiveBuilder`] is itself backed by a `Vec<T::Native>` and a
+/// [`NullBufferBuilder`], so using one does not unlock any additional performance —
+/// it is simply a convenience wrapper for incremental construction.
+///
+/// # When to use [`PrimitiveBuilder`]
+///
+/// Prefer the builder when your array **may contain nulls but you don't know their
+/// positions upfront**. Managing a `Vec<T>` and a [`NullBufferBuilder`] in parallel
+/// by hand is error-prone; the builder keeps them in sync automatically as you call
+/// [`append_value`](PrimitiveBuilder::append_value) and
+/// [`append_null`](PrimitiveBuilder::append_null).
+///
/// ```
/// # use arrow_array::builder::Int32Builder;
/// # use arrow_array::Array;
-/// // Use the builder when appending values one-by-one:
/// let mut builder = Int32Builder::new();
-/// for v in [1, 2, 3] {
-/// builder.append_value(v);
+/// for (i, v) in [1, 2, 3].iter().enumerate() {
Review Comment:
this is a nice change
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] docs: update primitive docs to focus on vec [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #10898:
URL: https://github.com/apache/arrow-rs/pull/10898
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org