You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by yi...@apache.org on 2026/07/26 20:50:52 UTC

(spark) branch branch-4.x updated: [MINOR][CONNECT] Remove redundant user_context.user_id assignment in execute_command methods

This is an automated email from the ASF dual-hosted git repository.

Yicong-Huang pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.x by this push:
     new 52de4a925260 [MINOR][CONNECT] Remove redundant user_context.user_id assignment in execute_command methods
52de4a925260 is described below

commit 52de4a925260ceaf9455a83d4ca50f2e021cddad
Author: Yash Bapat <yb...@purdue.edu>
AuthorDate: Sun Jul 26 13:50:25 2026 -0700

    [MINOR][CONNECT] Remove redundant user_context.user_id assignment in execute_command methods
    
    ### What changes were proposed in this pull request?
    
    Remove two redundant assignments of `req.user_context.user_id = self._user_id` from `SparkConnectClient.execute_command` and `SparkConnectClient.execute_command_as_iterator`.
    
    Both methods call `_execute_plan_request_with_metadata()` to build the request, and that helper already sets `req.user_context.user_id` under the identical `if self._user_id:` guard. The subsequent reassignments in the two callers are dead code.
    
    ```python
    # _execute_plan_request_with_metadata() already does this:
    if self._user_id:
        req.user_context.user_id = self._user_id
    
    # These lines in execute_command / execute_command_as_iterator were redundant:
    - if self._user_id:
    -     req.user_context.user_id = self._user_id
    ```
    
    Relates to GitHub issue #56408.
    
    ### Why are the changes needed?
    
    Dead code removal / readability improvement. Setting the same protobuf field to the same value twice in sequence is misleading — it implies the first assignment might not be sufficient when it is.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No. The resulting `req.user_context.user_id` value is identical before and after this change.
    
    ### How was this patch tested?
    
    No behavior change; existing Spark Connect unit tests cover `execute_command` / `execute_command_as_iterator` request construction.
    
    > This PR was created with the assistance of Claude (AI). Disclosed per Apache Spark contribution guidelines.
    
    Closes #57493 from ybapat/issue-56408-dup-user-context.
    
    Authored-by: Yash Bapat <yb...@purdue.edu>
    Signed-off-by: Yicong Huang <17...@users.noreply.github.com>
    (cherry picked from commit 12f4f9bd8e38cc8048d7b747ffe38af9462ddc70)
    Signed-off-by: Yicong Huang <17...@users.noreply.github.com>
---
 python/pyspark/sql/connect/client/core.py | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/python/pyspark/sql/connect/client/core.py b/python/pyspark/sql/connect/client/core.py
index be42e8259e83..19618f2d7968 100644
--- a/python/pyspark/sql/connect/client/core.py
+++ b/python/pyspark/sql/connect/client/core.py
@@ -1413,8 +1413,6 @@ class SparkConnectClient(object):
             # when not at debug log level.
             logger.debug(f"Execute command for command {self._proto_to_string(command, True)}")
         req = self._execute_plan_request_with_metadata()
-        if self._user_id:
-            req.user_context.user_id = self._user_id
         self._set_command_in_plan(req.plan, command)
         data, _, metrics, observed_metrics, properties = self._execute_and_fetch(
             req, observations or {}
@@ -1439,8 +1437,6 @@ class SparkConnectClient(object):
                 f"Execute command as iterator for command {self._proto_to_string(command, True)}"
             )
         req = self._execute_plan_request_with_metadata()
-        if self._user_id:
-            req.user_context.user_id = self._user_id
         self._set_command_in_plan(req.plan, command)
         for response in self._execute_and_fetch_as_iterator(req, observations or {}):
             if isinstance(response, dict):


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org