Skip to content

[GLUTEN-13706][VL] Fix pandas UDFs on partitions with more than one batch - #13707

Merged
zhouyuan merged 3 commits into
apache:mainfrom
LuciferYang:vl18-c1-arrow-python-reuse
Nov 22, 2026
Merged

zhouyuan merged 3 commits into
apache:mainfrom
LuciferYang:vl18-c1-arrow-python-reuse

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Since #13280, ColumnarArrowEvalPythonExec fails with Cannot retain a released vector once a partition sends more than one batch to Python, i.e. has more than spark.gluten.sql.columnar.maxBatchSize rows (4096 by default). The reader returned every output batch over the same vectors, so closing one batch released the next.

  • Each output batch now owns its vectors: the reader moves the buffers out of the stream's root without copying. An output batch that never reaches its consumer is closed.
  • Scalar iterator UDFs fall back to Spark, as on the Bolt backend. Their output batches can differ in size from the input batches, and the batch-by-batch join then gives wrong rows: a UDF that merged pairs of batches returned 4 of 8 rows.

This reproduces on v1.8.0-rc1 with default settings (a pandas UDF over one 10,000-row partition), so it should block 1.8.0. Draft #13419 also rewrites this reader.

Fixes #13706.

How was this patch tested?

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

Yes. Generated-by: Claude Opus.

Copilot AI balanced review requested due to automatic review settings November 21, 2026 06:57

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot added the VELOX label Nov 21, 2026
Copilot AI balanced review requested due to automatic review settings November 21, 2026 09:15

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@LuciferYang

Copy link
Copy Markdown
Contributor Author

@FelixYBW @jinchengchenghh @zhztheplayer @zhouyuan

This is a regression from #13280, which is in v1.8.0-rc1 but not in v1.7.0. With default settings, a pandas UDF over a partition with more rows than spark.gluten.sql.columnar.maxBatchSize fails with Cannot retain a released vector. I'd treat it as a 1.8.0 blocker, and would like to hear your view first.

@zhouyuan
zhouyuan merged commit 7d73f50 into apache:main Nov 22, 2026
40 checks passed
@LuciferYang

Copy link
Copy Markdown
Contributor Author

Thank you @zhouyuan

@zhztheplayer zhztheplayer 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.

A late minor, thanks.

Comment on lines +133 to +134
unclaimed = new ColumnarBatch(
ArrowColumnVectors.wrap(vectors.asJava).toArray[ColumnVector],

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.

Is this batch only closed in the task completion listener?

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.

No. On the normal path, next() clears unclaimed, and doExecuteColumnar puts the batch's columns into the joined batch. recyclePayload(_.close()) closes the joined batch, and with it these columns, the next time the consumer calls hasNext(). The listener only handles a batch that hasNext() read ahead but next() never returned, which can only happen if the task stops between the two calls, e.g. on failure.

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.

[VL] Pandas UDFs fail with "Cannot retain a released vector" on partitions with more than one batch

4 participants