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

dongjoon 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 10b9c61ee9a [SPARK-46083][PYTHON] Make SparkNoSuchElementException as 
a canonical error API
10b9c61ee9a is described below

commit 10b9c61ee9a7712b43956769d1ad61b50c4c0ceb
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Thu Nov 23 22:03:18 2023 -0800

    [SPARK-46083][PYTHON] Make SparkNoSuchElementException as a canonical error 
API
    
    ### What changes were proposed in this pull request?
    
    This PR is a kind of a followup of 
https://github.com/apache/spark/pull/43927 which added 
`SparkNoSuchElementException` into errors. This PR makes 
`SparkNoSuchElementException` as a canonical error API.
    
    ### Why are the changes needed?
    
    For the end users to catch those exceptions properly via 
`pyspark.errors.SparkNoSuchElementException` with/without Spark Connect.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes, it adds a new API `SparkNoSuchElementException` class.
    
    ### How was this patch tested?
    
    Manually tested:
    
    ```bash
    ./bin/pyspark
    ```
    
    ```bash
    ./bin/pyspark --remote local
    ```
    
    ```python
    from pyspark.errors import SparkNoSuchElementException
    
    try:
        spark.conf.get("my_key")
    except SparkNoSuchElementException as e:
        print("caught properly")
    ```
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #43992 from HyukjinKwon/error-SparkNoSuchElementException.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 python/docs/source/reference/pyspark.errors.rst | 1 +
 python/pyspark/errors/__init__.py               | 2 ++
 python/pyspark/errors/exceptions/base.py        | 6 ++++++
 python/pyspark/errors/exceptions/captured.py    | 3 ++-
 python/pyspark/errors/exceptions/connect.py     | 3 ++-
 5 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/python/docs/source/reference/pyspark.errors.rst 
b/python/docs/source/reference/pyspark.errors.rst
index 8723de8ebf2..89ca7373a4f 100644
--- a/python/docs/source/reference/pyspark.errors.rst
+++ b/python/docs/source/reference/pyspark.errors.rst
@@ -47,6 +47,7 @@ Classes
     QueryExecutionException
     SparkRuntimeException
     SparkUpgradeException
+    SparkNoSuchElementException
     StreamingQueryException
     TempTableAlreadyExistsException
     UnknownException
diff --git a/python/pyspark/errors/__init__.py 
b/python/pyspark/errors/__init__.py
index 53d5a266557..6d9d452ddd0 100644
--- a/python/pyspark/errors/__init__.py
+++ b/python/pyspark/errors/__init__.py
@@ -35,6 +35,7 @@ from pyspark.errors.exceptions.base import (  # noqa: F401
     UnknownException,
     SparkRuntimeException,
     SparkUpgradeException,
+    SparkNoSuchElementException,
     PySparkTypeError,
     PySparkValueError,
     PySparkAttributeError,
@@ -62,6 +63,7 @@ __all__ = [
     "UnknownException",
     "SparkRuntimeException",
     "SparkUpgradeException",
+    "SparkNoSuchElementException",
     "PySparkTypeError",
     "PySparkValueError",
     "PySparkAttributeError",
diff --git a/python/pyspark/errors/exceptions/base.py 
b/python/pyspark/errors/exceptions/base.py
index df43dea7042..c63b9dbee87 100644
--- a/python/pyspark/errors/exceptions/base.py
+++ b/python/pyspark/errors/exceptions/base.py
@@ -190,6 +190,12 @@ class SparkUpgradeException(PySparkException):
     """
 
 
+class SparkNoSuchElementException(PySparkException):
+    """
+    Exception thrown for `java.util.NoSuchElementException`.
+    """
+
+
 class UnknownException(PySparkException):
     """
     None of the other exceptions.
diff --git a/python/pyspark/errors/exceptions/captured.py 
b/python/pyspark/errors/exceptions/captured.py
index 6434448af8a..df23be8a979 100644
--- a/python/pyspark/errors/exceptions/captured.py
+++ b/python/pyspark/errors/exceptions/captured.py
@@ -36,6 +36,7 @@ from pyspark.errors.exceptions.base import (
     QueryExecutionException as BaseQueryExecutionException,
     SparkRuntimeException as BaseSparkRuntimeException,
     SparkUpgradeException as BaseSparkUpgradeException,
+    SparkNoSuchElementException as BaseNoSuchElementException,
     StreamingQueryException as BaseStreamingQueryException,
     UnknownException as BaseUnknownException,
 )
@@ -303,7 +304,7 @@ class SparkUpgradeException(CapturedException, 
BaseSparkUpgradeException):
     """
 
 
-class SparkNoSuchElementException(CapturedException, BaseUnknownException):
+class SparkNoSuchElementException(CapturedException, 
BaseNoSuchElementException):
     """
     No such element exception.
     """
diff --git a/python/pyspark/errors/exceptions/connect.py 
b/python/pyspark/errors/exceptions/connect.py
index 80bdea542a9..aaa52f9b20a 100644
--- a/python/pyspark/errors/exceptions/connect.py
+++ b/python/pyspark/errors/exceptions/connect.py
@@ -32,6 +32,7 @@ from pyspark.errors.exceptions.base import (
     StreamingQueryException as BaseStreamingQueryException,
     QueryExecutionException as BaseQueryExecutionException,
     SparkRuntimeException as BaseSparkRuntimeException,
+    SparkNoSuchElementException as BaseNoSuchElementException,
     SparkUpgradeException as BaseSparkUpgradeException,
 )
 
@@ -369,7 +370,7 @@ class SparkException(SparkConnectGrpcException):
     """ """
 
 
-class SparkNoSuchElementException(SparkConnectGrpcException, 
BaseSparkUpgradeException):
+class SparkNoSuchElementException(SparkConnectGrpcException, 
BaseNoSuchElementException):
     """
     No such element exception.
     """


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to