j1wonpark opened a new pull request, #59548: URL: https://github.com/apache/spark/pull/59548
### What changes were proposed in this pull request? Set `CurrentUserContext` to the Spark Connect session user in `SessionHolder.withSession`, and restore the previous value on both normal and exceptional completion. An empty session user preserves the existing fallback behavior. This addresses [SPARK-56891](https://issues.apache.org/jira/browse/SPARK-56891) using the existing SQL user context instead of a new SparkContext local property, following the approach suggested in #55917. It covers both execute and analyze paths and does not authenticate the session user. ### Why are the changes needed? Spark Connect retains a session user ID but does not propagate it to the SQL user context. Consequently, `user()`, `current_user()`, and `session_user()` return the server user even when the session specifies a different user. Using `CurrentUserContext`, as Hive Thriftserver does, allows these functions to reflect the Connect session user. ### Does this PR introduce _any_ user-facing change? Yes. For a Connect session with user ID `alice` and no pre-existing SQL user context, the following query returns `alice` in all three columns instead of the server user: ```sql SELECT user(), current_user(), session_user(); ``` The session user ID is not necessarily an authenticated identity; identity verification remains the responsibility of the authentication layer. ### How was this patch tested? Added seven tests covering: - SQL user functions through actual ExecutePlan and AnalyzePlan RPCs, including sequential requests for different users. - Context restoration after normal and exceptional completion, with and without a previous value. - Existing fallback behavior for an empty session user. Before the patch, six tests failed because the session user was not propagated; the fallback test passed. All seven passed after the patch. Ran the following checks: ```bash SPARK_LOCAL_IP=localhost build/sbt \ 'connect/testOnly *SparkConnectCurrentUserSuite *SparkConnectSessionHolderSuite *SparkConnectServiceSuite' \ 'connect/Compile/scalastyle' \ 'connect/Test/scalastyle' ``` All 51 executed tests passed. Two existing Python tests were canceled because the Pandas UDF test prerequisites were unavailable. Both scalastyle checks passed. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-6) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
