Skip to content

Commit

Permalink
Use getCondition instead of deprecated getErrorClass from SparkThrowable
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Oct 11, 2024
1 parent e6cd0ff commit 469131b
Show file tree
Hide file tree
Showing 51 changed files with 152 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class CloneIcebergByNameSuite extends CloneIcebergSuiteBase
val e = intercept[DeltaIllegalStateException] {
runCreateOrReplace("SHALLOW", sourceIdentifier)
}
assert(e.getErrorClass == "DELTA_MISSING_ICEBERG_CLASS")
assert(e.getCondition == "DELTA_MISSING_ICEBERG_CLASS")
}
} finally {
ConvertUtils.icebergSparkTableClassPath = validIcebergSparkTableClassPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ trait ConvertIcebergToDeltaSuiteBase
val e = intercept[DeltaIllegalStateException] {
convert(s"iceberg.`$tablePath`")
}
assert(e.getErrorClass == "DELTA_MISSING_ICEBERG_CLASS")
assert(e.getCondition == "DELTA_MISSING_ICEBERG_CLASS")
}
} finally {
ConvertUtils.icebergSparkTableClassPath = validIcebergSparkTableClassPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ class DeltaFormatSharingSourceSuite
var e = intercept[StreamingQueryException] {
processAllAvailableInStream(0)
}
assert(e.getCause.asInstanceOf[DeltaIllegalStateException].getErrorClass
assert(e.getCause.asInstanceOf[DeltaIllegalStateException].getCondition
== "DELTA_SCHEMA_CHANGED_WITH_STARTING_OPTIONS")
assert(e.getMessage.contains("Detected schema change in version 3"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ConcurrentWriteException(message: String)
def this(messageParameters: Array[String]) = {
this(DeltaThrowableHelper.getMessage("DELTA_CONCURRENT_WRITE", messageParameters))
}
override def getErrorClass: String = "DELTA_CONCURRENT_WRITE"
override def getCondition: String = "DELTA_CONCURRENT_WRITE"
override def getMessage: String = message
}

Expand All @@ -65,7 +65,7 @@ class MetadataChangedException(message: String)
def this(messageParameters: Array[String]) = {
this(DeltaThrowableHelper.getMessage("DELTA_METADATA_CHANGED", messageParameters))
}
override def getErrorClass: String = "DELTA_METADATA_CHANGED"
override def getCondition: String = "DELTA_METADATA_CHANGED"
override def getMessage: String = message
}

Expand All @@ -84,7 +84,7 @@ class ProtocolChangedException(message: String)
def this(messageParameters: Array[String]) = {
this(DeltaThrowableHelper.getMessage("DELTA_PROTOCOL_CHANGED", messageParameters))
}
override def getErrorClass: String = "DELTA_PROTOCOL_CHANGED"
override def getCondition: String = "DELTA_PROTOCOL_CHANGED"
override def getMessage: String = message
}

Expand All @@ -102,7 +102,7 @@ class ConcurrentAppendException(message: String)
def this(messageParameters: Array[String]) = {
this(DeltaThrowableHelper.getMessage("DELTA_CONCURRENT_APPEND", messageParameters))
}
override def getErrorClass: String = "DELTA_CONCURRENT_APPEND"
override def getCondition: String = "DELTA_CONCURRENT_APPEND"
override def getMessage: String = message
}

Expand All @@ -120,7 +120,7 @@ class ConcurrentDeleteReadException(message: String)
def this(messageParameters: Array[String]) = {
this(DeltaThrowableHelper.getMessage("DELTA_CONCURRENT_DELETE_READ", messageParameters))
}
override def getErrorClass: String = "DELTA_CONCURRENT_DELETE_READ"
override def getCondition: String = "DELTA_CONCURRENT_DELETE_READ"
override def getMessage: String = message
}

Expand All @@ -138,7 +138,7 @@ class ConcurrentDeleteDeleteException(message: String)
def this(messageParameters: Array[String]) = {
this(DeltaThrowableHelper.getMessage("DELTA_CONCURRENT_DELETE_DELETE", messageParameters))
}
override def getErrorClass: String = "DELTA_CONCURRENT_DELETE_DELETE"
override def getCondition: String = "DELTA_CONCURRENT_DELETE_DELETE"
override def getMessage: String = message
}

Expand All @@ -156,6 +156,6 @@ class ConcurrentTransactionException(message: String)
def this(messageParameters: Array[String]) = {
this(DeltaThrowableHelper.getMessage("DELTA_CONCURRENT_TRANSACTION", messageParameters))
}
override def getErrorClass: String = "DELTA_CONCURRENT_TRANSACTION"
override def getCondition: String = "DELTA_CONCURRENT_TRANSACTION"
override def getMessage: String = message
}
28 changes: 14 additions & 14 deletions spark/src/main/scala/org/apache/spark/sql/delta/DeltaErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3693,7 +3693,7 @@ class DeltaColumnMappingUnsupportedException(
extends ColumnMappingUnsupportedException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

class DeltaFileNotFoundException(
Expand All @@ -3702,7 +3702,7 @@ class DeltaFileNotFoundException(
extends FileNotFoundException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

class DeltaFileAlreadyExistsException(
Expand All @@ -3711,7 +3711,7 @@ class DeltaFileAlreadyExistsException(
extends FileAlreadyExistsException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

class DeltaIOException(
Expand All @@ -3721,7 +3721,7 @@ class DeltaIOException(
extends IOException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters), cause)
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

class DeltaIllegalStateException(
Expand All @@ -3731,7 +3731,7 @@ class DeltaIllegalStateException(
extends IllegalStateException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters), cause)
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass

override def getMessageParameters: java.util.Map[String, String] = {
DeltaThrowableHelper.getParameterNames(errorClass, null)
Expand All @@ -3745,7 +3745,7 @@ class DeltaIndexOutOfBoundsException(
extends IndexOutOfBoundsException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

/** Thrown when the protocol version of a table is greater than supported by this client. */
Expand All @@ -3765,15 +3765,15 @@ case class InvalidProtocolVersionException(
supportedReaderVersions.sorted.mkString(", "),
supportedWriterVersions.sorted.mkString(", "))))
with DeltaThrowable {
override def getErrorClass: String = "DELTA_INVALID_PROTOCOL_VERSION"
override def getCondition: String = "DELTA_INVALID_PROTOCOL_VERSION"
}

class ProtocolDowngradeException(oldProtocol: Protocol, newProtocol: Protocol)
extends RuntimeException(DeltaThrowableHelper.getMessage(
errorClass = "DELTA_INVALID_PROTOCOL_DOWNGRADE",
messageParameters = Array(s"(${oldProtocol.simpleString})", s"(${newProtocol.simpleString})")
)) with DeltaThrowable {
override def getErrorClass: String = "DELTA_INVALID_PROTOCOL_DOWNGRADE"
override def getCondition: String = "DELTA_INVALID_PROTOCOL_DOWNGRADE"
}

class DeltaTableFeatureException(
Expand All @@ -3795,7 +3795,7 @@ class DeltaRuntimeException(
extends RuntimeException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass

override def getMessageParameters: java.util.Map[String, String] =
DeltaThrowableHelper.getParameterNames(errorClass, null)
Expand All @@ -3809,7 +3809,7 @@ class DeltaSparkException(
extends SparkException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters), cause)
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

class DeltaNoSuchTableException(
Expand All @@ -3818,7 +3818,7 @@ class DeltaNoSuchTableException(
extends AnalysisException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

class DeltaCommandUnsupportedWithDeletionVectorsException(
Expand All @@ -3827,7 +3827,7 @@ class DeltaCommandUnsupportedWithDeletionVectorsException(
extends UnsupportedOperationException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

sealed trait DeltaTablePropertyValidationFailedSubClass {
Expand Down Expand Up @@ -3867,7 +3867,7 @@ class DeltaTablePropertyValidationFailedException(
subClass.tag).zip(subClass.messageParameters(table)).toMap.asJava
}

override def getErrorClass: String =
override def getCondition: String =
"DELTA_VIOLATE_TABLE_PROPERTY_VALIDATION_FAILED." + subClass.tag
}

Expand All @@ -3884,7 +3884,7 @@ class DeltaChecksumException(
extends ChecksumException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters), pos)
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DeltaIllegalArgumentException(
extends IllegalArgumentException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters), cause)
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
def getMessageParametersArray: Array[String] = messageParameters

override def getMessageParameters: java.util.Map[String, String] = {
Expand All @@ -66,7 +66,7 @@ class DeltaUnsupportedOperationException(
extends UnsupportedOperationException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass
def getMessageParametersArray: Array[String] = messageParameters

override def getMessageParameters: java.util.Map[String, String] = {
Expand All @@ -93,7 +93,7 @@ class DeltaArithmeticException(
extends ArithmeticException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters))
with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass

override def getMessageParameters: java.util.Map[String, String] = {
DeltaThrowableHelper.getParameterNames(errorClass, errorSubClass = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ trait DeltaThrowable extends SparkThrowable {
// Portable error identifier across SQL engines
// If null, error class or SQLSTATE is not set
override def getSqlState: String =
DeltaThrowableHelper.getSqlState(this.getErrorClass.split('.').head)
DeltaThrowableHelper.getSqlState(this.getCondition.split('.').head)

// True if this error is an internal error.
override def isInternalError: Boolean = DeltaThrowableHelper.isInternalError(this.getErrorClass)
override def isInternalError: Boolean = DeltaThrowableHelper.isInternalError(this.getCondition)
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ object GeneratedColumn extends DeltaLogging with AnalysisHelper {
} catch {
case ex: AnalysisException =>
// Improve error message if possible
if (ex.getErrorClass == "UNRESOLVED_COLUMN.WITH_SUGGESTION") {
if (ex.getCondition == "UNRESOLVED_COLUMN.WITH_SUGGESTION") {
throw DeltaErrors.generatedColumnsReferToWrongColumns(ex)
}
throw ex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ trait DeltaLogging
var data = Map[String, Any]("exceptionMessage" -> e.getMessage)
e condDo {
case sparkEx: SparkThrowable
if sparkEx.getErrorClass != null && sparkEx.getErrorClass.nonEmpty =>
if sparkEx.getCondition != null && sparkEx.getCondition.nonEmpty =>
data ++= Map(
"errorClass" -> sparkEx.getErrorClass,
"errorClass" -> sparkEx.getCondition,
"sqlState" -> sparkEx.getSqlState
)
case NonFatal(e) if e.getCause != null =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class DeltaInvariantViolationException(
messageParameters: Array[String])
extends InvariantViolationException(
DeltaThrowableHelper.getMessage(errorClass, messageParameters)) with DeltaThrowable {
override def getErrorClass: String = errorClass
override def getCondition: String = errorClass

override def getMessageParameters: util.Map[String, String] = {
DeltaThrowableHelper.getParameterNames(errorClass, errorSubClass = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class DeltaExtensionAndCatalogSuite extends SparkFunSuite {
DeltaLog.forTable(spark, path)
}
assert(e.isInstanceOf[DeltaAnalysisException])
assert(e.getErrorClass() == "DELTA_CONFIGURE_SPARK_SESSION_WITH_EXTENSION_AND_CATALOG")
assert(e.getCondition() == "DELTA_CONFIGURE_SPARK_SESSION_WITH_EXTENSION_AND_CATALOG")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion spark/src/test/scala/io/delta/tables/DeltaTableSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ class DeltaTableHadoopOptionsSuite extends QueryTest
// update the protocol again with invalid feature name.
assert(intercept[DeltaTableFeatureException] {
table.addFeatureSupport("__invalid_feature__")
}.getErrorClass === "DELTA_UNSUPPORTED_FEATURES_IN_CONFIG")
}.getCondition === "DELTA_UNSUPPORTED_FEATURES_IN_CONFIG")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ trait CloneTableSuiteBase extends QueryTest
target,
isShallow,
tableProperties = Map(DeltaConfigs.ENABLE_DELETION_VECTORS_CREATION.key -> "false"))()
}.getErrorClass === "DELTA_ADDING_DELETION_VECTORS_DISALLOWED"
}.getCondition === "DELTA_ADDING_DELETION_VECTORS_DISALLOWED"
}

for(targetExists <- BOOLEAN_DOMAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ trait DeltaAlterTableByPathTests extends DeltaAlterTableTestBase {
val e = intercept[DeltaAnalysisException] {
sql(s"alter table $identifier set location '$path'")
}
assert(e.getErrorClass == "DELTA_CANNOT_SET_LOCATION_ON_PATH_IDENTIFIER")
assert(e.getCondition == "DELTA_CANNOT_SET_LOCATION_ON_PATH_IDENTIFIER")
assert(e.getSqlState == "42613")
assert(e.getMessage == "[DELTA_CANNOT_SET_LOCATION_ON_PATH_IDENTIFIER] " +
"Cannot change the location of a path based table.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,14 @@ trait DeltaCDCColumnMappingSuiteBase extends DeltaCDCSuiteBase
f
}
val (end, readSchemaJson) = if (bySchemaChange) {
assert(e.getErrorClass == "DELTA_CHANGE_DATA_FEED_INCOMPATIBLE_SCHEMA_CHANGE")
assert(e.getCondition == "DELTA_CHANGE_DATA_FEED_INCOMPATIBLE_SCHEMA_CHANGE")
val Seq(_, end, readSchemaJson, readSchemaVersion, incompatibleVersion, _, _, _, _) =
e.getMessageParametersArray.toSeq
assert(incompatibleVersion.toLong == expectedIncompatSchemaVersion)
assert(readSchemaVersion.toLong == expectedReadSchemaVersion)
(end, readSchemaJson)
} else {
assert(e.getErrorClass == "DELTA_CHANGE_DATA_FEED_INCOMPATIBLE_DATA_SCHEMA")
assert(e.getCondition == "DELTA_CHANGE_DATA_FEED_INCOMPATIBLE_DATA_SCHEMA")
val Seq(_, end, readSchemaJson, readSchemaVersion, incompatibleVersion, config) =
e.getMessageParametersArray.toSeq
assert(incompatibleVersion.toLong == expectedIncompatSchemaVersion)
Expand Down Expand Up @@ -688,7 +688,7 @@ trait DeltaCDCColumnMappingScalaSuiteBase extends DeltaCDCColumnMappingSuiteBase
EndingVersion("1"),
readerOptions = Map(DeltaOptions.VERSION_AS_OF -> "0")).collect()
}
assert(e.getErrorClass == "DELTA_UNSUPPORTED_TIME_TRAVEL_VIEWS")
assert(e.getCondition == "DELTA_UNSUPPORTED_TIME_TRAVEL_VIEWS")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class DeltaCDCSQLSuite extends DeltaCDCSuiteBase with DeltaColumnMappingTestUtil
e = intercept[AnalysisException] {
sql(s"SELECT * FROM table_changes('invalidtable', 1, 1)")
}
assert(e.getErrorClass === "TABLE_OR_VIEW_NOT_FOUND")
assert(e.getCondition === "TABLE_OR_VIEW_NOT_FOUND")

withTable ("tbl") {
spark.range(1).write.format("delta").saveAsTable("tbl")
Expand Down Expand Up @@ -332,13 +332,13 @@ class DeltaCDCSQLSuite extends DeltaCDCSuiteBase with DeltaColumnMappingTestUtil
var e = intercept[AnalysisException] {
spark.sql(s"SELECT * FROM table_changes('tbl', 0, 1)")
}
assert(e.getErrorClass == "DELTA_TABLE_ONLY_OPERATION")
assert(e.getCondition == "DELTA_TABLE_ONLY_OPERATION")
assert(e.getMessage.contains("table_changes"))

e = intercept[AnalysisException] {
spark.sql(s"SELECT * FROM table_changes_by_path('${dir.getAbsolutePath}', 0, 1)")
}
assert(e.getErrorClass == "DELTA_MISSING_DELTA_TABLE")
assert(e.getCondition == "DELTA_MISSING_DELTA_TABLE")
assert(e.getMessage.contains("not a Delta table"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ abstract class DeltaCDCSuiteBase
StartingTimestamp(ts0),
EndingTimestamp(ts1))
.collect()
}.getErrorClass === "DELTA_INVALID_CDC_RANGE"
}.getCondition === "DELTA_INVALID_CDC_RANGE"
}
}

Expand All @@ -418,7 +418,7 @@ abstract class DeltaCDCSuiteBase
StartingTimestamp(ts0),
EndingTimestamp(ts1))
.collect()
}.getErrorClass === "DELTA_INVALID_CDC_RANGE"
}.getCondition === "DELTA_INVALID_CDC_RANGE"
}
}

Expand Down
Loading

0 comments on commit 469131b

Please sign in to comment.