Skip to content

[GLUTEN-12447] Add Arrow large var types support - #13018

Merged
zhouyuan merged 12 commits into
apache:mainfrom
wecharyu:GLUTEN-12447
Nov 27, 2026
Merged

zhouyuan merged 12 commits into
apache:mainfrom
wecharyu:GLUTEN-12447

Conversation

@wecharyu

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Support Spark conf spark.sql.execution.arrow.useLargeVarTypes when building arrow vectors to avoid OversizedAllocationException for very large string/binary columns.

Fix #12447.

How was this patch tested?

UT.

Was this patch authored or co-authored using generative AI tooling?

Generated by GPT-5.6

@wecharyu wecharyu changed the title Gluten 12447 [GLUTEN-12447] Add Arrow large var types support- #12448 Sep 14, 2026
@wecharyu wecharyu changed the title [GLUTEN-12447] Add Arrow large var types support- #12448 [GLUTEN-12447] Add Arrow large var types support Sep 14, 2026
@github-actions github-actions Bot added the VELOX label Sep 14, 2026
@wecharyu

Copy link
Copy Markdown
Contributor Author

@zml1206 @zhouyuan This PR replaced the closed #12448, could you take another look? Thanks!

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.

🟡 Changes recommended

Critical issues remain with Bolt export layout handling, unsupported backend layouts, and SparkArrowUtil visibility.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds support for Spark Arrow large variable-width types to prevent oversized allocations for large string and binary columns.

Changes:

  • Adds large UTF-8/binary schema mappings and vector accessors.
  • Propagates the configuration through Java, JNI, and native export paths.
  • Updates Velox/Bolt interfaces and related tests.

Blocking review findings remain in Bolt export compatibility, backend layout handling, and SparkArrowUtil visibility.

File summaries
File Summary
gluten-arrow/src/test/java/org/apache/gluten/vectorized/ArrowWritableColumnVectorTest.java Tests large dictionary vectors.
gluten-arrow/src/main/scala/org/apache/spark/sql/utils/SparkSchemaUtil.scala Reads the large-variable-type configuration.
gluten-arrow/src/main/scala/org/apache/spark/sql/utils/SparkArrowUtil.scala Maps Spark variable types to large Arrow types.
gluten-arrow/src/main/scala/org/apache/gluten/utils/ArrowUtil.scala Rebuilds imported schemas using configured types.
gluten-arrow/src/main/java/org/apache/gluten/vectorized/ArrowWritableColumnVector.java Adds large vector accessors and writers.
gluten-arrow/src/main/java/org/apache/gluten/vectorized/ArrowColumnVector.java Adds large vector readers.
gluten-arrow/src/main/java/org/apache/gluten/columnarbatch/ColumnarBatchJniWrapper.java Extends JNI export parameters.
gluten-arrow/src/main/java/org/apache/gluten/columnarbatch/ColumnarBatches.java Passes the large-type setting during export.
cpp/velox/utils/VeloxArrowUtils.h Configures large variable-width exports.
cpp/velox/memory/VeloxColumnarBatch.h Extends Velox batch export APIs.
cpp/velox/memory/VeloxColumnarBatch.cc Applies large export options.
cpp/velox/memory/GpuBufferColumnarBatch.h Updates export API signatures.
cpp/velox/memory/GpuBufferColumnarBatch.cc Updates unsupported export implementations.
cpp/core/memory/ColumnarBatch.h Extends the common batch export interface.
cpp/core/memory/ColumnarBatch.cc Updates core batch implementations.
cpp/core/jni/JniWrapper.cc Propagates the JNI option.
cpp/bolt/memory/BoltColumnarBatch.h Updates Bolt export signatures.
cpp/bolt/memory/BoltColumnarBatch.cc Updates Bolt export implementations.
backends-velox/src/test/scala/org/apache/gluten/expression/UDFPartialProjectSuite.scala Tests both configuration modes.
backends-velox/src/main/scala/org/apache/spark/sql/execution/unsafe/UnsafeColumnarBuildSideRelation.scala Uses configured Arrow schemas.
backends-velox/src/main/scala/org/apache/spark/sql/execution/datasources/velox/VeloxFormatWriterInjects.scala Uses configured writer schemas.
backends-velox/src/main/scala/org/apache/spark/sql/execution/ColumnarCachedBatchSerializer.scala Uses configured cache schemas.
backends-velox/src/main/scala/org/apache/spark/sql/execution/ColumnarBuildSideRelation.scala Uses configured build-side schemas.
backends-velox/src/main/scala/org/apache/gluten/execution/RowToVeloxColumnarExec.scala Uses configured row-to-columnar schemas.
backends-velox/src-iceberg/main/scala/org/apache/gluten/connector/write/IcebergDataWriteFactory.scala Uses configured Iceberg writer schemas.
Review details
  • Files reviewed: 25/25 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +74 to 77
std::shared_ptr<ArrowArray> BoltColumnarBatch::exportArrowArray(bool) {
auto out = std::make_shared<ArrowArray>();
ensureFlattened();
bolt::exportToArrow(rowVector_, *out, rowVector_->pool(), ArrowUtils::getBridgeOptions());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add new backend api supportLargeVarTypes() to disable arrow var type for bolt backend.

iv.handle(),
cSchema.memoryAddress(),
cArray.memoryAddress(),
SparkSchemaUtil.enableLargeVarTypes());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed ArrowUtil.toArrowSchema api, import the native ArrowSchema and ArrowArray together through ArrowAbiUtil so that the schema always describes the actual buffer layout.

Comment on lines +182 to +185
private[utils] def toArrowSchema(
schema: StructType,
timeZoneId: String,
largeVarTypes: Boolean = false): Schema = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the package private declaration.

@github-actions github-actions Bot added the CORE works for Gluten Core label Sep 20, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@wecharyu

Copy link
Copy Markdown
Contributor Author

@zhouyuan Could you take a look again? Added a backend api supportLargeVarTypes() and tested that spark.sql.execution.arrow.useLargeVarTypes works fine for bolt backend.

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions Bot added the stale stale label Nov 7, 2026
@github-actions

Copy link
Copy Markdown

This PR was auto-closed because it has been stalled for 10 days with no activity. Please feel free to reopen if it is still valid. Thanks.

@github-actions github-actions Bot closed this Nov 17, 2026
@zhouyuan

Copy link
Copy Markdown
Member

hi @wecharyu somehow I missed this patch, apologies for the delay, could you please do a rebase? Thanks.

@zhouyuan zhouyuan reopened this Nov 17, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions github-actions Bot removed the stale stale label Nov 18, 2026
@github-actions github-actions Bot added the BOLT label Nov 18, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@wecharyu

Copy link
Copy Markdown
Contributor Author

@zhouyuan No worries at all. I’ve rebased this PR. Gluten now uses Spark’s built-in Arrow reader and writer. #13280 and Spark added support for LargeUtf8 and LargeBinary in 3.5, so this PR enables spark.sql.execution.arrow.useLargeVarTypes only on Spark 3.5 and later. Spark 3.4 continues to use standard 32-bit Arrow offsets.

@zhouyuan zhouyuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

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.

Comment on lines +88 to +89
def dictionary(field: Field): FieldVector = {
provider.lookup(field.getDictionary.getId).getVector

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dictionary#getVector() returns FieldVector in all four Arrow versions used by this PR (15.0.0, 18.1.0, 18.3.0, and 19.0.0).

Comment on lines +45 to +48
case StringType if !largeVarTypes => ArrowType.Utf8.INSTANCE
case BinaryType if !largeVarTypes => ArrowType.Binary.INSTANCE
case StringType if largeVarTypes => ArrowType.LargeUtf8.INSTANCE
case BinaryType if largeVarTypes => ArrowType.LargeBinary.INSTANCE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The ArrowColumnVector missing these accessors is Gluten’s old implementation, which has no callers after #13280.

There are some no used Arrow files (ArrowColumnVector.java, ArrowColumnarMap.java and ArrowColumnarArray.java) could be removed, we can do it in a seprate PR.

auto out = std::make_shared<ArrowSchema>();
ensureFlattened();
velox::exportToArrow(rowVector_, *out, ArrowUtils::getBridgeOptions());
velox::exportToArrow(rowVector_, *out, ArrowUtils::getBridgeOptions(exportToLargeVarTypes));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added test ColumnarBatchTest#testLoadVeloxBatchWithLargeVarTypes.

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@zhouyuan

Copy link
Copy Markdown
Member

@WangGuangxin could you please also take a look?

@zhouyuan
zhouyuan merged commit a86b704 into apache:main Nov 27, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BOLT CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OversizedAllocationException in building arrow vectors

3 participants