<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_error_classes</id>
	<title>Spark error classes - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_error_classes"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_error_classes&amp;action=history"/>
	<updated>2026-12-06T00:13:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Spark_error_classes&amp;diff=185&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_error_classes&amp;diff=185&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:53Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Spark error classes&lt;br /&gt;
| also_known_as   = Error conditions, error states, SQLSTATE codes&lt;br /&gt;
| field           = SQL query engines&lt;br /&gt;
| key_parts       = Error condition name, sub-condition, SQLSTATE (class and sub-class), message template with parameters&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark SQL ANSI mode]], [[Spark SQL scripting]], [[Spark Connect]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (common/utils/src/main/resources/error/, SparkThrowable.java, python/pyspark/errors/exceptions/base.py, docs/sql-error-conditions.md, SQLConf.scala), SPARK-46810 and the Spark 4.0.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], &amp;#039;&amp;#039;&amp;#039;error classes&amp;#039;&amp;#039;&amp;#039; (now documented as &amp;#039;&amp;#039;&amp;#039;error conditions&amp;#039;&amp;#039;&amp;#039;) are the structured identifiers that Spark attaches to user-facing errors: a stable name such as &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt;, an optional sub-condition, a five-character SQLSTATE code and a message template with named parameters.&amp;lt;ref name=&amp;quot;readme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/resources/error/README.md |title=Guidelines for Throwing User-Facing Errors (common/utils/src/main/resources/error/README.md at v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; They let programs and people identify an error without parsing its message text, which can change between releases. The Spark documentation lists them on the &amp;quot;Error Conditions&amp;quot; page, ordered by SQLSTATE.&amp;lt;ref name=&amp;quot;docs&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-error-conditions.html |title=Error Conditions (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Error class or error condition? ==&lt;br /&gt;
Spark uses the terms of the SQL standard, in which an &amp;quot;error class&amp;quot; is only the first two characters of a SQLSTATE. Spark&amp;#039;s contributor guide defines a hierarchy of three levels: the error state (SQLSTATE), the error condition, and the error sub-condition. The SQLSTATE in turn has two parts, a class (for example &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt;) and a sub-class (for example &amp;lt;code&amp;gt;K01&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark historically called a name like &amp;lt;code&amp;gt;DATATYPE_MISSING_SIZE&amp;lt;/code&amp;gt; an &amp;quot;error class&amp;quot; as well, which clashed with the standard meaning. SPARK-46810, &amp;quot;Clarify error class terminology&amp;quot;, fixed in Spark 4.0.0, settled on &amp;quot;error condition&amp;quot; for these names in user-facing documentation.&amp;lt;ref name=&amp;quot;jira46810&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-46810 |title=SPARK-46810: Clarify error class terminology |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The guide notes that the code still calls the field &amp;lt;code&amp;gt;errorClass&amp;lt;/code&amp;gt; in many places, so the same string is an &amp;quot;error condition&amp;quot; in the docs and an &amp;quot;error class&amp;quot; in the code.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The public APIs followed the rename. In Spark 4.3.0 the Java and Scala interface &amp;lt;code&amp;gt;SparkThrowable&amp;lt;/code&amp;gt; exposes &amp;lt;code&amp;gt;getCondition()&amp;lt;/code&amp;gt; and marks &amp;lt;code&amp;gt;getErrorClass()&amp;lt;/code&amp;gt; as deprecated.&amp;lt;ref name=&amp;quot;throwable&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/java/org/apache/spark/SparkThrowable.java |title=SparkThrowable.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In PySpark, SPARK-50915 added &amp;lt;code&amp;gt;PySparkException.getCondition()&amp;lt;/code&amp;gt; and deprecated &amp;lt;code&amp;gt;getErrorClass()&amp;lt;/code&amp;gt; as of 4.0.0.&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pybase&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/errors/exceptions/base.py |title=pyspark/errors/exceptions/base.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How are Spark errors structured? ==&lt;br /&gt;
Spark defines its errors in three JSON files in the source tree: &amp;lt;code&amp;gt;error-conditions.json&amp;lt;/code&amp;gt; (the conditions, their messages and SQLSTATEs), &amp;lt;code&amp;gt;error-states.json&amp;lt;/code&amp;gt; (the SQLSTATE values) and &amp;lt;code&amp;gt;error-classes.json&amp;lt;/code&amp;gt; (the two-character SQLSTATE classes).&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt; An error condition is unique, stays the same across releases, and has a message template whose parameters are written in angle brackets, such as &amp;lt;code&amp;gt;&amp;amp;lt;relationName&amp;amp;gt;&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some conditions have sub-conditions that add detail. For example &amp;lt;code&amp;gt;UNRESOLVED_COLUMN&amp;lt;/code&amp;gt; (SQLSTATE &amp;lt;code&amp;gt;42703&amp;lt;/code&amp;gt;) has the sub-conditions &amp;lt;code&amp;gt;WITH_SUGGESTION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;WITHOUT_SUGGESTION&amp;lt;/code&amp;gt;, and the full name is written &amp;lt;code&amp;gt;UNRESOLVED_COLUMN.WITH_SUGGESTION&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;errjson&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/resources/error/error-conditions.json |title=error-conditions.json (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Errors that have not yet been given a proper name use a legacy condition with the prefix &amp;lt;code&amp;gt;_LEGACY_ERROR_TEMP_&amp;lt;/code&amp;gt; and a number. The contributor guide asks that no new uncategorized errors be added and that existing ones be converted.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is a SQLSTATE in Spark? ==&lt;br /&gt;
A SQLSTATE is a five-character code that identifies an error category across SQL engines; the first two characters are the class and the last three the sub-class.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt; Spark&amp;#039;s &amp;lt;code&amp;gt;error-states.json&amp;lt;/code&amp;gt; records, for each state, its description, whether it comes from the SQL standard and which other systems use it. For example &amp;lt;code&amp;gt;22003&amp;lt;/code&amp;gt; (&amp;quot;numeric value out of range&amp;quot;) comes from SQL/Foundation, while &amp;lt;code&amp;gt;42P01&amp;lt;/code&amp;gt; (&amp;quot;undefined table&amp;quot;) originates in PostgreSQL.&amp;lt;ref name=&amp;quot;states&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/resources/error/error-states.json |title=error-states.json (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 4.0.0 made a SQLSTATE mandatory for error conditions (SPARK-45581) and exposed it in error messages (SPARK-45595).&amp;lt;ref name=&amp;quot;r400&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Error condition !! SQLSTATE !! Typical cause&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;22012&amp;lt;/code&amp;gt; || Division by zero in [[Spark SQL ANSI mode|ANSI mode]]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ARITHMETIC_OVERFLOW&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;22003&amp;lt;/code&amp;gt; || Numeric overflow in ANSI mode&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CAST_INVALID_INPUT&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;22018&amp;lt;/code&amp;gt; || A string that cannot be cast to the target type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;TABLE_OR_VIEW_NOT_FOUND&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;42P01&amp;lt;/code&amp;gt; || A table or view name that does not resolve&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;UNRESOLVED_COLUMN&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;42703&amp;lt;/code&amp;gt; || A column, variable or parameter name that does not resolve&lt;br /&gt;
|}&lt;br /&gt;
Source: &amp;lt;code&amp;gt;error-conditions.json&amp;lt;/code&amp;gt; at v4.3.0.&amp;lt;ref name=&amp;quot;errjson&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to search Spark error conditions ==&lt;br /&gt;
The &amp;quot;Error Conditions&amp;quot; page of the Spark documentation is generated from &amp;lt;code&amp;gt;error-conditions.json&amp;lt;/code&amp;gt; and lists every condition with its SQLSTATE and message, sorted by SQLSTATE and then by name.&amp;lt;ref name=&amp;quot;docs&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/docs/_plugins/build-error-docs.py |title=docs/_plugins/build-error-docs.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Searching that page, or the JSON file at the matching release tag, for the condition name shown in brackets at the start of an error message (for example &amp;lt;code&amp;gt;[CAST_INVALID_INPUT]&amp;lt;/code&amp;gt;) gives the message template and SQLSTATE for that release.&lt;br /&gt;
&lt;br /&gt;
Programs can read the same fields from the exception. Every Spark exception that implements &amp;lt;code&amp;gt;SparkThrowable&amp;lt;/code&amp;gt; provides &amp;lt;code&amp;gt;getCondition()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;getSqlState()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;getMessageParameters()&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;throwable&amp;quot; /&amp;gt; PySpark exceptions provide methods of the same names.&amp;lt;ref name=&amp;quot;pybase&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.errors import PySparkException&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    spark.sql(&amp;quot;SELECT 1 / 0&amp;quot;).collect()   # ANSI mode is on by default in Spark 4&lt;br /&gt;
except PySparkException as e:&lt;br /&gt;
    print(e.getCondition())          # DIVIDE_BY_ZERO&lt;br /&gt;
    print(e.getSqlState())           # 22012&lt;br /&gt;
    print(e.getMessageParameters())  # e.g. {&amp;#039;config&amp;#039;: &amp;#039;&amp;quot;spark.sql.ansi.enabled&amp;quot;&amp;#039;}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Branching on &amp;lt;code&amp;gt;getCondition()&amp;lt;/code&amp;gt; or on the SQLSTATE class is more robust than matching message text. The contributor guide shows a check of the form &amp;lt;code&amp;gt;getSqlState.startsWith(&amp;quot;42&amp;quot;)&amp;lt;/code&amp;gt; to catch all syntax and analysis errors.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt; In [[Spark SQL scripting]], condition handlers can name an error condition such as &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt; or a SQLSTATE directly.&amp;lt;ref name=&amp;quot;scripting&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-scripting.html |title=SQL Scripting (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How are error messages formatted? ==&lt;br /&gt;
&amp;lt;code&amp;gt;spark.sql.error.messageFormat&amp;lt;/code&amp;gt; sets how the Thrift Server and the SQL command-line interface print errors. The default, &amp;lt;code&amp;gt;PRETTY&amp;lt;/code&amp;gt;, prints the error condition, message and query context and shows stack traces only for internal errors (SQLSTATE &amp;lt;code&amp;gt;XX***&amp;lt;/code&amp;gt;); &amp;lt;code&amp;gt;DEBUG&amp;lt;/code&amp;gt; always adds stack traces; &amp;lt;code&amp;gt;MINIMAL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;STANDARD&amp;lt;/code&amp;gt; produce JSON, with &amp;lt;code&amp;gt;STANDARD&amp;lt;/code&amp;gt; adding a &amp;lt;code&amp;gt;message&amp;lt;/code&amp;gt; field.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[Spark SQL ANSI mode]]&lt;br /&gt;
* [[Spark SQL scripting]]&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Spark 3 to Spark 4 migration]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>