Skip to content

[SPARK-60117][K8S] Install pyarrow in PySpark Docker image - #59280

Closed
lisancao wants to merge 1 commit into
apache:masterfrom
lisancao:SPARK-k8s-python-pyarrow
Closed

lisancao wants to merge 1 commit into
apache:masterfrom
lisancao:SPARK-k8s-python-pyarrow

Conversation

@lisancao

@lisancao lisancao commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR installs pyarrow>=18.0.0 (PySpark's minimum) in the PySpark Docker image.

Why are the changes needed?

Since 4.2.0, regular Python UDFs are Arrow-optimized by default (SPARK-54555), so a plain @udf fails on the PySpark image with ModuleNotFoundError: No module named 'pyarrow'. The apache/spark images built from it (e.g. apache/spark:4.2.0-scala2.13-java21-python3-ubuntu) have the same problem. I left pandas out since only pandas UDFs need it.

Does this PR introduce any user-facing change?

Yes. Default Python UDFs work on the PySpark image. The image grows by about 160 MB.

How was this patch tested?

Built the images from this branch over the 4.3.0-rc1 distribution and ran a default @udf through Spark Connect: it fails before this change and passes after.

This contribution is my original work, and I license it to the project under the project's open source license.

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

Generated-by: Claude Code (Claude Opus 5.5)

@dongjoon-hyun
dongjoon-hyun marked this pull request as draft October 7, 2026 22:13
@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you. Please file a JIRA ID and use it like the other PRs before converting this PR back from Draft, @lisancao .

@lisancao
lisancao force-pushed the SPARK-k8s-python-pyarrow branch from 89d8250 to c163076 Compare October 10, 2026 01:37
Since Spark 4.2.0 regular Python UDFs are Arrow-optimized by default
(SPARK-54555), so the PySpark image can't run a plain `@udf` without
PyArrow. Install it in the Python binding Dockerfile.

Generated-by: Claude Code (Claude Opus 5.5)
@lisancao
lisancao force-pushed the SPARK-k8s-python-pyarrow branch from c163076 to 320460a Compare October 10, 2026 01:39
@lisancao lisancao changed the title [K8S] Install pyarrow in PySpark K8s Dockerfile [SPARK-60117][K8S] Install pyarrow in PySpark Docker image Oct 10, 2026
@lisancao
lisancao marked this pull request as ready for review October 10, 2026 01:39
@lisancao

Copy link
Copy Markdown
Contributor Author

Hi @dongjoon-hyun Sorry for the delay, it is updated now. Can you take a look?

@holdenk

holdenk commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

So wait @lisancao is this failing all Python UDFs in the container is it just producing an error message and then gracefully falling back? I thought we did auto graceful fallbacks but I could be getting things mixed up.

@lisancao

Copy link
Copy Markdown
Contributor Author

So wait @lisancao is this failing all Python UDFs in the container is it just producing an error message and then gracefully falling back? I thought we did auto graceful fallbacks but I could be getting things mixed up.

Investigated a bit further. The fallback works fine on classic, but on Connect it fails on the server: the PyArrow check passes on the client (pyspark-client ships PyArrow), but PyArrow isn't installed in this image, so if you use it for your Connect server, the Python worker raises error: No module named 'pyarrow'.

The supplement to this, if we don't want to update the docker image (or both) is we could explore a serverside fallback or just make a clearer error for the user advising them to set spark.sql.execution.pythonUDF.arrow.enabled to false if it doesn't have the install

@holdenk

holdenk commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Ah that's a bad one. I think we should fix and install PyArrow in the docker container, but we should also improve the fallback for connect users who have pyarrow on the client but not on the server; if you're open to filing a JIRA for that too (doesn't need to block this PR).

@lisancao

Copy link
Copy Markdown
Contributor Author

Thanks @holdenk, filed SPARK-60241 for the Connect fallback!

@dongjoon-hyun

Copy link
Copy Markdown
Member

@holdenk . This is not a regression because we never install it on the Apache Spark docker images, isn't it?

@holdenk

holdenk commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

So it's a regression because we enabled Arrow by default now and it doesn't fail back gracefully with Spark Connect.

@dongjoon-hyun

Copy link
Copy Markdown
Member

I mean it's not a regression of Apache Spark 4.2.1.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Also, cc @dbtsai , @HyukjinKwon , @asl3 too from the original Apache Spark 4.2.0 PR because we were there together.

@holdenk

holdenk commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

True it's a regression from 4.1 but not 4.2

@dongjoon-hyun

dongjoon-hyun commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

BTW, @holdenk , how does PySpark Connect work for you before (in Spark 4.1) on the default Docker image ?

Screenshot 2026-10-14 at 21 36 19

We didn't have all packages even for PySpark SQL, do we? Given that, when it comes to the Apache Spark Docker images, the required package installation has been always the user's role, hasn't it?

Screenshot 2026-10-14 at 21 37 21

@HyukjinKwon

Copy link
Copy Markdown
Member

@HyukjinKwon

Copy link
Copy Markdown
Member

It should fall back properly. Seems like minimal dep build passes (https://github.com/apache/spark/actions/workflows/build_python_minimum.yml)

@lisancao

Copy link
Copy Markdown
Contributor Author

It should fall back properly. Seems like minimal dep build passes (https://github.com/apache/spark/actions/workflows/build_python_minimum.yml)

@HyukjinKwon if the minimum build shas PyArrow, and CI runs the Connect client and server on the same Python, such issue may not be detected, since server and client match in that case.

My experience was that it only failed when the client has PyArrow and the server's Python doesn't, more nuanced than the original issue described.

@dongjoon-hyun dongjoon-hyun 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.

-1 for adding additional python packages because the image will explode and go stale easily, @lisancao and @holdenk .

As Hyukjin commented in the above, the fallback should work. So, instead of this, I'd recommend to fix the root cause (fallback path) if any regression issues are lingering.

@lisancao

Copy link
Copy Markdown
Contributor Author

-1 for adding additional python packages because the image will explode and go stale easily, @lisancao and @holdenk .

As Hyukjin commented in the above, the fallback should work. So, instead of this, I'd recommend to fix the root cause (fallback path) if any regression issues are lingering.

I agree fallback is higher priority, patching the image itself only solves the problem from a superficial place compared to root cause. I will defer to PMC on best course of action

@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you, @lisancao .

RUN apt-get update && \
apt install -y --no-install-recommends python3 python3-pip && \
# PyArrow is required by Arrow-optimized Python UDFs, the default since Spark 4.2 (SPARK-54555)
pip3 install --break-system-packages --no-cache-dir "pyarrow>=18.0.0" && \

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.

One side note: this doesn't sound like an appropriate approach for installing 3rd-party Python dependencies; --break-system-packages clearly signals the risk. Maybe we shouldn't use the OS Python and instead use another one (e.g., conda, uv, or something else) with the packages required by PySpark?

@spark-test spark-test left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review summary

No PR-caused correctness defect was established. The retained advisory question concerns the ownership boundary for installing third-party packages into OS Python. The pandas concern does not invalidate the default remote worker improvement: client-side fallback is unchanged, while the non-legacy worker conversion uses PyArrow directly.

Findings

0 total: 0 P0, 0 P1, 0 P2, 0 P3.

No findings.

Existing discussions

  • Unresolved decision challenge: Confirm the OS Python dependency installation policy — existing discussion

Verification

  • Reviewed the complete Dockerfile patch, merge-base Dockerfile, and classic/Connect client and worker dependency paths. No image build or Spark tests were run.

PR description suggestions

  • Narrow the user-facing claim to workers serving a separately provisioned Connect client, and clarify that regular UDF creation still checks pandas on the client. The statement that only pandas UDFs need pandas is broader than the current client implementation supports.

@spark-test

Copy link
Copy Markdown
Collaborator

The AI review requested by @HyukjinKwon finished.

Generated by Omnigent on Databricks

@holdenk

holdenk commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

I think we can close this for now, we're in agreement the fallback logic is more important. @lisancao do you want to take on the fallback fix?

@holdenk holdenk closed this Oct 21, 2026
@lisancao

Copy link
Copy Markdown
Contributor Author

I think we can close this for now, we're in agreement the fallback logic is more important. @lisancao do you want to take on the fallback fix?

Yes, happy to. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants