Skip to content

GH-50596: [C++] AppendScalar implementation uses polymorphism - #50652

Open
KHARSHAVARDHAN-eng wants to merge 1 commit into
apache:mainfrom
KHARSHAVARDHAN-eng:gh-50596-append-scalar-polymorphism
Open

GH-50596: [C++] AppendScalar implementation uses polymorphism#50652
KHARSHAVARDHAN-eng wants to merge 1 commit into
apache:mainfrom
KHARSHAVARDHAN-eng:gh-50596-append-scalar-polymorphism

Conversation

@KHARSHAVARDHAN-eng

@KHARSHAVARDHAN-eng KHARSHAVARDHAN-eng commented Jul 27, 2026

Copy link
Copy Markdown

Summary

ArrayBuilder::AppendScalar and AppendScalars previously relied on the
centralized AppendScalarImpl visitor to dispatch scalar appends based on
the 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

  • Remove the centralized AppendScalarImpl visitor.
  • Implement AppendScalar and AppendScalars on the relevant builder
    classes.
  • Retain the existing dispatch semantics while replacing visitor-based
    dispatch with virtual method polymorphism.

Testing

  • Built arrow-array-test.
  • Ran the full arrow-array-test suite.
  • All 1047 tests passed.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #50596 has been automatically assigned in GitHub to PR creator.

@KHARSHAVARDHAN-eng
KHARSHAVARDHAN-eng force-pushed the gh-50596-append-scalar-polymorphism branch from fd0653f to 4841ad1 Compare August 3, 2026 14:49
@kou
kou requested a lite review from Copilot August 13, 2026 21:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AppendScalarImpl visitor from ArrayBuilder and switches the base implementation to a NotImplemented fallback.
  • Adds AppendScalar / AppendScalars overrides 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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants