## Licensed to the Apache Software Foundation (ASF) under one or more# contributor license agreements. See the NOTICE file distributed with# this work for additional information regarding copyright ownership.# The ASF licenses this file to You under the Apache License, Version 2.0# (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#fromtypingimportDict,Optional,castfrompyspark.errors.utilsimportErrorClassesReader
[docs]classPySparkException(Exception):""" Base Exception for handling errors generated from PySpark. """def__init__(self,message:Optional[str]=None,error_class:Optional[str]=None,message_parameters:Optional[Dict[str,str]]=None,):# `message` vs `error_class` & `message_parameters` are mutually exclusive.assert(messageisnotNoneand(error_classisNoneandmessage_parametersisNone))or(messageisNoneand(error_classisnotNoneandmessage_parametersisnotNone))self.error_reader=ErrorClassesReader()ifmessageisNone:self.message=self.error_reader.get_error_message(cast(str,error_class),cast(Dict[str,str],message_parameters))else:self.message=messageself.error_class=error_classself.message_parameters=message_parameters
[docs]defgetErrorClass(self)->Optional[str]:""" Returns an error class as a string. .. versionadded:: 3.4.0 See Also -------- :meth:`PySparkException.getMessageParameters` :meth:`PySparkException.getSqlState` """returnself.error_class
[docs]defgetMessageParameters(self)->Optional[Dict[str,str]]:""" Returns a message parameters as a dictionary. .. versionadded:: 3.4.0 See Also -------- :meth:`PySparkException.getErrorClass` :meth:`PySparkException.getSqlState` """returnself.message_parameters
[docs]defgetSqlState(self)->None:""" Returns an SQLSTATE as a string. Errors generated in Python have no SQLSTATE, so it always returns None. .. versionadded:: 3.4.0 See Also -------- :meth:`PySparkException.getErrorClass` :meth:`PySparkException.getMessageParameters` """returnNone
[docs]classAnalysisException(PySparkException):""" Failed to analyze a SQL query plan. """
classSessionNotSameException(PySparkException):""" Performed the same operation on different SparkSession. """
[docs]classTempTableAlreadyExistsException(AnalysisException):""" Failed to create temp view since it is already exists. """
[docs]classParseException(AnalysisException):""" Failed to parse a SQL command. """
[docs]classIllegalArgumentException(PySparkException):""" Passed an illegal or inappropriate argument. """
classArithmeticException(PySparkException):""" Arithmetic exception thrown from Spark with an error class. """classUnsupportedOperationException(PySparkException):""" Unsupported operation exception thrown from Spark with an error class. """classArrayIndexOutOfBoundsException(PySparkException):""" Array index out of bounds exception thrown from Spark with an error class. """classDateTimeException(PySparkException):""" Datetime exception thrown from Spark with an error class. """classNumberFormatException(IllegalArgumentException):""" Number format exception thrown from Spark with an error class. """
[docs]classStreamingQueryException(PySparkException):""" Exception that stopped a :class:`StreamingQuery`. """
[docs]classQueryExecutionException(PySparkException):""" Failed to execute a query. """
[docs]classPythonException(PySparkException):""" Exceptions thrown from Python workers. """
classSparkRuntimeException(PySparkException):""" Runtime exception thrown from Spark with an error class. """
[docs]classSparkUpgradeException(PySparkException):""" Exception thrown because of Spark upgrade. """
[docs]classUnknownException(PySparkException):""" None of the above exceptions. """
classPySparkValueError(PySparkException,ValueError):""" Wrapper class for ValueError to support error classes. """classPySparkTypeError(PySparkException,TypeError):""" Wrapper class for TypeError to support error classes. """classPySparkAttributeError(PySparkException,AttributeError):""" Wrapper class for AttributeError to support error classes. """classPySparkRuntimeError(PySparkException,RuntimeError):""" Wrapper class for RuntimeError to support error classes. """classPySparkAssertionError(PySparkException,AssertionError):""" Wrapper class for AssertionError to support error classes. """classPySparkNotImplementedError(PySparkException,NotImplementedError):""" Wrapper class for NotImplementedError to support error classes. """