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 JdbcDialect.classifyException #48433

Open
wants to merge 1 commit 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 @@ -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,
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