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

ruifengz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new b348cd12a33 [MINOR][PYTHON][CONNECT] Check `self._session` before call 
`self._session.client`
b348cd12a33 is described below

commit b348cd12a331c9ffc463cd632b2c36dbab2d9208
Author: Ruifeng Zheng <ruife...@apache.org>
AuthorDate: Wed Sep 27 16:54:53 2023 +0800

    [MINOR][PYTHON][CONNECT] Check `self._session` before call 
`self._session.client`
    
    ### What changes were proposed in this pull request?
    In `DataFrame.{schema, explain}`, check `self._session` before call 
`self._session.client`
    
    I don't find other similar places
    
    ### Why are the changes needed?
    we should check `self._session` before call `self._session.client`
    
    ### Does this PR introduce _any_ user-facing change?
    no
    
    ### How was this patch tested?
    ci
    
    ### Was this patch authored or co-authored using generative AI tooling?
    no
    
    Closes #43143 from zhengruifeng/connect_schema_check_session.
    
    Authored-by: Ruifeng Zheng <ruife...@apache.org>
    Signed-off-by: Ruifeng Zheng <ruife...@apache.org>
---
 python/pyspark/sql/connect/dataframe.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/pyspark/sql/connect/dataframe.py 
b/python/pyspark/sql/connect/dataframe.py
index 5e2623336a2..081eabd9837 100644
--- a/python/pyspark/sql/connect/dataframe.py
+++ b/python/pyspark/sql/connect/dataframe.py
@@ -1773,9 +1773,9 @@ class DataFrame:
     @property
     def schema(self) -> StructType:
         if self._plan is not None:
-            query = self._plan.to_proto(self._session.client)
             if self._session is None:
                 raise Exception("Cannot analyze without SparkSession.")
+            query = self._plan.to_proto(self._session.client)
             return self._session.client.schema(query)
         else:
             raise Exception("Empty plan.")
@@ -1903,9 +1903,9 @@ class DataFrame:
             explain_mode = cast(str, extended)
 
         if self._plan is not None:
-            query = self._plan.to_proto(self._session.client)
             if self._session is None:
                 raise Exception("Cannot analyze without SparkSession.")
+            query = self._plan.to_proto(self._session.client)
             return self._session.client.explain_string(query, explain_mode)
         else:
             return ""


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

Reply via email to