GH-50596: [C++] AppendScalar implementation uses polymorphism - #50652
Open
KHARSHAVARDHAN-eng wants to merge 1 commit into
Open
GH-50596: [C++] AppendScalar implementation uses polymorphism#50652KHARSHAVARDHAN-eng wants to merge 1 commit into
KHARSHAVARDHAN-eng wants to merge 1 commit into
Conversation
|
|
KHARSHAVARDHAN-eng
force-pushed
the
gh-50596-append-scalar-polymorphism
branch
from
July 27, 2026 15:05
c896c6d to
fd0653f
Compare
KHARSHAVARDHAN-eng
force-pushed
the
gh-50596-append-scalar-polymorphism
branch
from
August 3, 2026 14:49
fd0653f to
4841ad1
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors C++ ArrayBuilder::AppendScalar / AppendScalars away from the centralized visitor-based implementation and into per-builder virtual overrides, aligning scalar appends with the existing builder polymorphism.
Changes:
- Removes the centralized
AppendScalarImplvisitor fromArrayBuilderand switches the base implementation to a NotImplemented fallback. - Adds
AppendScalar/AppendScalarsoverrides across primitive, binary, decimal, nested, and union builders. - Introduces shared helper implementations for decimal builder scalar appends.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/src/arrow/array/builder_base.cc | Removes visitor-based append implementation; base AppendScalar(s) now delegates to overrides / NotImplemented. |
| cpp/src/arrow/array/builder_primitive.h | Adds polymorphic scalar append support for NullBuilder, NumericBuilder, and BooleanBuilder. |
| cpp/src/arrow/array/builder_binary.h | Adds polymorphic scalar append support for binary-like builders (templated base + declarations for view/fixed-size). |
| cpp/src/arrow/array/builder_binary.cc | Implements scalar append logic for BinaryViewBuilder and FixedSizeBinaryBuilder. |
| cpp/src/arrow/array/builder_decimal.h | Declares scalar append overrides for decimal builders. |
| cpp/src/arrow/array/builder_decimal.cc | Implements decimal scalar append via shared helpers. |
| cpp/src/arrow/array/builder_nested.h | Declares scalar append overrides for list-like, map, fixed-size list, and struct builders. |
| cpp/src/arrow/array/builder_nested.cc | Implements scalar append for nested builders and relocates template instantiations. |
| cpp/src/arrow/array/builder_union.h | Declares scalar append overrides for dense/sparse union builders. |
| cpp/src/arrow/array/builder_union.cc | Implements scalar append logic for dense/sparse union builders. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+77
to
81
| if (scalar.type->id() == Type::NA) { | ||
| return AppendNulls(n_repeats); | ||
| } | ||
| if (scalar.type->id() != type()->id()) { | ||
| return Status::Invalid("Cannot append scalar of type ", scalar.type->ToString(), |
Comment on lines
88
to
+92
| if (scalars.empty()) return Status::OK(); | ||
| const auto ty = type(); | ||
| for (const auto& scalar : scalars) { | ||
| if (!scalar->type->Equals(ty)) { | ||
| return Status::Invalid("Cannot append scalar of type ", scalar->type->ToString(), | ||
| " to builder for type ", type()->ToString()); | ||
| } | ||
| RETURN_NOT_OK(AppendScalar(*scalar, 1)); | ||
| } | ||
|
|
||
| using Iterator = DerefConstIterator<ScalarVector::const_iterator>; | ||
| return AppendScalarImpl<Iterator>{Iterator{scalars.begin()}, Iterator{scalars.end()}, | ||
| /*n_repeats=*/1, this} | ||
| .Convert(); | ||
| return Status::OK(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ArrayBuilder::AppendScalarandAppendScalarspreviously relied on thecentralized
AppendScalarImplvisitor to dispatch scalar appends based onthe scalar type.
This refactors scalar appending to use virtual method polymorphism within
the builder hierarchy, moving the implementation into the appropriate
builder classes while preserving the existing behavior.
Implementation
AppendScalarImplvisitor.AppendScalarandAppendScalarson the relevant builderclasses.
dispatch with virtual method polymorphism.
Testing
arrow-array-test.arrow-array-testsuite.