Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-49942][SQL] Rename errorClass to condition in classifyException() #48433

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ object JdbcUtils extends Logging with SQLConfHelper {
}

def classifyException[T](
errorClass: String,
condition: String,
messageParameters: Map[String, String],
dialect: JdbcDialect,
description: String,
Expand All @@ -1269,7 +1269,7 @@ object JdbcUtils extends Logging with SQLConfHelper {
} catch {
case e: SparkThrowable with Throwable => throw e
case e: Throwable =>
throw dialect.classifyException(e, errorClass, messageParameters, description, isRuntime)
throw dialect.classifyException(e, condition, messageParameters, description, isRuntime)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ case class JDBCTable(ident: Identifier, schema: StructType, jdbcOptions: JDBCOpt
properties: util.Map[String, String]): Unit = {
JdbcUtils.withConnection(jdbcOptions) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.CREATE_INDEX",
condition = "FAILED_JDBC.CREATE_INDEX",
messageParameters = Map(
"url" -> jdbcOptions.getRedactUrl(),
"indexName" -> toSQLId(indexName),
Expand All @@ -87,7 +87,7 @@ case class JDBCTable(ident: Identifier, schema: StructType, jdbcOptions: JDBCOpt
override def dropIndex(indexName: String): Unit = {
JdbcUtils.withConnection(jdbcOptions) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.DROP_INDEX",
condition = "FAILED_JDBC.DROP_INDEX",
messageParameters = Map(
"url" -> jdbcOptions.getRedactUrl(),
"indexName" -> toSQLId(indexName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class JDBCTableCatalog extends TableCatalog
JdbcUtils.withConnection(options) { conn =>
val schemaPattern = if (namespace.length == 1) namespace.head else null
val rs = JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.GET_TABLES",
condition = "FAILED_JDBC.GET_TABLES",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"namespace" -> toSQLId(namespace.toSeq)),
Expand All @@ -89,7 +89,7 @@ class JDBCTableCatalog extends TableCatalog
val writeOptions = new JdbcOptionsInWrite(
options.parameters + (JDBCOptions.JDBC_TABLE_NAME -> getTableName(ident)))
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.TABLE_EXISTS",
condition = "FAILED_JDBC.TABLE_EXISTS",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"tableName" -> toSQLId(ident)),
Expand All @@ -116,7 +116,7 @@ class JDBCTableCatalog extends TableCatalog
checkNamespace(oldIdent.namespace())
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.RENAME_TABLE",
condition = "FAILED_JDBC.RENAME_TABLE",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"oldName" -> toSQLId(oldIdent),
Expand All @@ -134,7 +134,7 @@ class JDBCTableCatalog extends TableCatalog
val optionsWithTableName = new JDBCOptions(
options.parameters + (JDBCOptions.JDBC_TABLE_NAME -> getTableName(ident)))
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.LOAD_TABLE",
condition = "FAILED_JDBC.LOAD_TABLE",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"tableName" -> toSQLId(ident)),
Expand Down Expand Up @@ -191,7 +191,7 @@ class JDBCTableCatalog extends TableCatalog
val schema = CatalogV2Util.v2ColumnsToStructType(columns)
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.CREATE_TABLE",
condition = "FAILED_JDBC.CREATE_TABLE",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"tableName" -> toSQLId(ident)),
Expand All @@ -209,7 +209,7 @@ class JDBCTableCatalog extends TableCatalog
checkNamespace(ident.namespace())
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.ALTER_TABLE",
condition = "FAILED_JDBC.ALTER_TABLE",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"tableName" -> toSQLId(ident)),
Expand All @@ -226,7 +226,7 @@ class JDBCTableCatalog extends TableCatalog
case Array(db) =>
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.NAMESPACE_EXISTS",
condition = "FAILED_JDBC.NAMESPACE_EXISTS",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"namespace" -> toSQLId(namespace.toSeq)),
Expand All @@ -242,7 +242,7 @@ class JDBCTableCatalog extends TableCatalog
override def listNamespaces(): Array[Array[String]] = {
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.LIST_NAMESPACES",
condition = "FAILED_JDBC.LIST_NAMESPACES",
messageParameters = Map("url" -> options.getRedactUrl()),
dialect,
description = s"Failed list namespaces",
Expand Down Expand Up @@ -295,7 +295,7 @@ class JDBCTableCatalog extends TableCatalog
}
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.CREATE_NAMESPACE",
condition = "FAILED_JDBC.CREATE_NAMESPACE",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"namespace" -> toSQLId(db)),
Expand All @@ -321,7 +321,7 @@ class JDBCTableCatalog extends TableCatalog
if (set.property() == SupportsNamespaces.PROP_COMMENT) {
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.CREATE_NAMESPACE_COMMENT",
condition = "FAILED_JDBC.CREATE_NAMESPACE_COMMENT",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"namespace" -> toSQLId(db)),
Expand All @@ -339,7 +339,7 @@ class JDBCTableCatalog extends TableCatalog
if (unset.property() == SupportsNamespaces.PROP_COMMENT) {
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.REMOVE_NAMESPACE_COMMENT",
condition = "FAILED_JDBC.REMOVE_NAMESPACE_COMMENT",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"namespace" -> toSQLId(db)),
Expand Down Expand Up @@ -368,7 +368,7 @@ class JDBCTableCatalog extends TableCatalog
case Array(db) if namespaceExists(namespace) =>
JdbcUtils.withConnection(options) { conn =>
JdbcUtils.classifyException(
errorClass = "FAILED_JDBC.DROP_NAMESPACE",
condition = "FAILED_JDBC.DROP_NAMESPACE",
messageParameters = Map(
"url" -> options.getRedactUrl(),
"namespace" -> toSQLId(db)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private case class DB2Dialect() extends JdbcDialect with SQLConfHelper with NoLe
}
override def classifyException(
e: Throwable,
errorClass: String,
condition: String,
messageParameters: Map[String, String],
description: String,
isRuntime: Boolean): Throwable with SparkThrowable = {
Expand All @@ -167,13 +167,13 @@ private case class DB2Dialect() extends JdbcDialect with SQLConfHelper with NoLe
namespace = messageParameters.get("namespace").toArray,
details = sqlException.getMessage,
cause = Some(e))
case "42710" if errorClass == "FAILED_JDBC.RENAME_TABLE" =>
case "42710" if condition == "FAILED_JDBC.RENAME_TABLE" =>
val newTable = messageParameters("newName")
throw QueryCompilationErrors.tableAlreadyExistsError(newTable)
case _ =>
super.classifyException(e, errorClass, messageParameters, description, isRuntime)
super.classifyException(e, condition, messageParameters, description, isRuntime)
}
case _ => super.classifyException(e, errorClass, messageParameters, description, isRuntime)
case _ => super.classifyException(e, condition, messageParameters, description, isRuntime)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private[sql] case class H2Dialect() extends JdbcDialect with NoLegacyJDBCError {

override def classifyException(
e: Throwable,
errorClass: String,
condition: String,
messageParameters: Map[String, String],
description: String,
isRuntime: Boolean): Throwable with SparkThrowable = {
Expand Down Expand Up @@ -230,21 +230,21 @@ private[sql] case class H2Dialect() extends JdbcDialect with NoLegacyJDBCError {
throw new NoSuchNamespaceException(errorClass = "SCHEMA_NOT_FOUND",
messageParameters = Map("schemaName" -> quotedName))
// INDEX_ALREADY_EXISTS_1
case 42111 if errorClass == "FAILED_JDBC.CREATE_INDEX" =>
case 42111 if condition == "FAILED_JDBC.CREATE_INDEX" =>
val indexName = messageParameters("indexName")
val tableName = messageParameters("tableName")
throw new IndexAlreadyExistsException(
indexName = indexName, tableName = tableName, cause = Some(e))
// INDEX_NOT_FOUND_1
case 42112 if errorClass == "FAILED_JDBC.DROP_INDEX" =>
case 42112 if condition == "FAILED_JDBC.DROP_INDEX" =>
val indexName = messageParameters("indexName")
val tableName = messageParameters("tableName")
throw new NoSuchIndexException(indexName, tableName, cause = Some(e))
case _ => // do nothing
}
case _ => // do nothing
}
super.classifyException(e, errorClass, messageParameters, description, isRuntime)
super.classifyException(e, condition, messageParameters, description, isRuntime)
}

override def compileExpression(expr: Expression): Option[String] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,15 +738,15 @@ abstract class JdbcDialect extends Serializable with Logging {
/**
* Gets a dialect exception, classifies it and wraps it by `AnalysisException`.
* @param e The dialect specific exception.
* @param errorClass The error class assigned in the case of an unclassified `e`
* @param condition The error condition assigned in the case of an unclassified `e`
* @param messageParameters The message parameters of `errorClass`
* @param description The error description
* @param isRuntime Whether the exception is a runtime exception or not.
* @return `SparkThrowable + Throwable` or its sub-class.
*/
def classifyException(
e: Throwable,
errorClass: String,
condition: String,
messageParameters: Map[String, String],
description: String,
isRuntime: Boolean): Throwable with SparkThrowable = {
Expand All @@ -759,7 +759,7 @@ abstract class JdbcDialect extends Serializable with Logging {
* @param e The dialect specific exception.
* @return `AnalysisException` or its sub-class.
*/
@deprecated("Please override the classifyException method with an error class", "4.0.0")
@deprecated("Please override the classifyException method with an error condition", "4.0.0")
def classifyException(message: String, e: Throwable): AnalysisException = {
new AnalysisException(
errorClass = "FAILED_JDBC.UNCLASSIFIED",
Expand Down Expand Up @@ -850,18 +850,18 @@ trait NoLegacyJDBCError extends JdbcDialect {

override def classifyException(
e: Throwable,
errorClass: String,
condition: String,
messageParameters: Map[String, String],
description: String,
isRuntime: Boolean): Throwable with SparkThrowable = {
if (isRuntime) {
new SparkRuntimeException(
errorClass = errorClass,
errorClass = condition,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a plan to rename the errorClass argument to condition in SparkRuntimeException and AnalysisException?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

messageParameters = messageParameters,
cause = e)
} else {
new AnalysisException(
errorClass = errorClass,
errorClass = condition,
messageParameters = messageParameters,
cause = Some(e))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr

override def classifyException(
e: Throwable,
errorClass: String,
condition: String,
messageParameters: Map[String, String],
description: String,
isRuntime: Boolean): Throwable with SparkThrowable = {
Expand All @@ -217,13 +217,13 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
namespace = messageParameters.get("namespace").toArray,
details = sqlException.getMessage,
cause = Some(e))
case 15335 if errorClass == "FAILED_JDBC.RENAME_TABLE" =>
case 15335 if condition == "FAILED_JDBC.RENAME_TABLE" =>
val newTable = messageParameters("newName")
throw QueryCompilationErrors.tableAlreadyExistsError(newTable)
case _ =>
super.classifyException(e, errorClass, messageParameters, description, isRuntime)
super.classifyException(e, condition, messageParameters, description, isRuntime)
}
case _ => super.classifyException(e, errorClass, messageParameters, description, isRuntime)
case _ => super.classifyException(e, condition, messageParameters, description, isRuntime)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,30 +350,30 @@ private case class MySQLDialect() extends JdbcDialect with SQLConfHelper with No

override def classifyException(
e: Throwable,
errorClass: String,
condition: String,
messageParameters: Map[String, String],
description: String,
isRuntime: Boolean): Throwable with SparkThrowable = {
e match {
case sqlException: SQLException =>
sqlException.getErrorCode match {
// ER_DUP_KEYNAME
case 1050 if errorClass == "FAILED_JDBC.RENAME_TABLE" =>
case 1050 if condition == "FAILED_JDBC.RENAME_TABLE" =>
val newTable = messageParameters("newName")
throw QueryCompilationErrors.tableAlreadyExistsError(newTable)
case 1061 if errorClass == "FAILED_JDBC.CREATE_INDEX" =>
case 1061 if condition == "FAILED_JDBC.CREATE_INDEX" =>
val indexName = messageParameters("indexName")
val tableName = messageParameters("tableName")
throw new IndexAlreadyExistsException(indexName, tableName, cause = Some(e))
case 1091 if errorClass == "FAILED_JDBC.DROP_INDEX" =>
case 1091 if condition == "FAILED_JDBC.DROP_INDEX" =>
val indexName = messageParameters("indexName")
val tableName = messageParameters("tableName")
throw new NoSuchIndexException(indexName, tableName, cause = Some(e))
case _ =>
super.classifyException(e, errorClass, messageParameters, description, isRuntime)
super.classifyException(e, condition, messageParameters, description, isRuntime)
}
case unsupported: UnsupportedOperationException => throw unsupported
case _ => super.classifyException(e, errorClass, messageParameters, description, isRuntime)
case _ => super.classifyException(e, condition, messageParameters, description, isRuntime)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,20 @@ private case class OracleDialect() extends JdbcDialect with SQLConfHelper with N

override def classifyException(
e: Throwable,
errorClass: String,
condition: String,
messageParameters: Map[String, String],
description: String,
isRuntime: Boolean): Throwable with SparkThrowable = {
e match {
case sqlException: SQLException =>
sqlException.getErrorCode match {
case 955 if errorClass == "FAILED_JDBC.RENAME_TABLE" =>
case 955 if condition == "FAILED_JDBC.RENAME_TABLE" =>
val newTable = messageParameters("newName")
throw QueryCompilationErrors.tableAlreadyExistsError(newTable)
case _ =>
super.classifyException(e, errorClass, messageParameters, description, isRuntime)
super.classifyException(e, condition, messageParameters, description, isRuntime)
}
case _ => super.classifyException(e, errorClass, messageParameters, description, isRuntime)
case _ => super.classifyException(e, condition, messageParameters, description, isRuntime)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private case class PostgresDialect()

override def classifyException(
e: Throwable,
errorClass: String,
condition: String,
messageParameters: Map[String, String],
description: String,
isRuntime: Boolean): Throwable with SparkThrowable = {
Expand All @@ -268,23 +268,23 @@ private case class PostgresDialect()
sqlException.getSQLState match {
// https://www.postgresql.org/docs/14/errcodes-appendix.html
case "42P07" =>
if (errorClass == "FAILED_JDBC.CREATE_INDEX") {
if (condition == "FAILED_JDBC.CREATE_INDEX") {
throw new IndexAlreadyExistsException(
indexName = messageParameters("indexName"),
tableName = messageParameters("tableName"),
cause = Some(e))
} else if (errorClass == "FAILED_JDBC.RENAME_TABLE") {
} else if (condition == "FAILED_JDBC.RENAME_TABLE") {
val newTable = messageParameters("newName")
throw QueryCompilationErrors.tableAlreadyExistsError(newTable)
} else {
val tblRegexp = pgAlreadyExistsRegex.findFirstMatchIn(sqlException.getMessage)
if (tblRegexp.nonEmpty) {
throw QueryCompilationErrors.tableAlreadyExistsError(tblRegexp.get.group(1))
} else {
super.classifyException(e, errorClass, messageParameters, description, isRuntime)
super.classifyException(e, condition, messageParameters, description, isRuntime)
}
}
case "42704" if errorClass == "FAILED_JDBC.DROP_INDEX" =>
case "42704" if condition == "FAILED_JDBC.DROP_INDEX" =>
val indexName = messageParameters("indexName")
val tableName = messageParameters("tableName")
throw new NoSuchIndexException(indexName, tableName, cause = Some(e))
Expand All @@ -294,10 +294,10 @@ private case class PostgresDialect()
details = sqlException.getMessage,
cause = Some(e))
case _ =>
super.classifyException(e, errorClass, messageParameters, description, isRuntime)
super.classifyException(e, condition, messageParameters, description, isRuntime)
}
case unsupported: UnsupportedOperationException => throw unsupported
case _ => super.classifyException(e, errorClass, messageParameters, description, isRuntime)
case _ => super.classifyException(e, condition, messageParameters, description, isRuntime)
}
}

Expand Down