Skip to content

Commit

Permalink
proper error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
c27kwan committed Apr 15, 2024
1 parent 731c833 commit 8ab57a0
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
18 changes: 18 additions & 0 deletions spark/src/main/resources/error/delta-error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,24 @@
},
"sqlState" : "KD00E"
},
"DELTA_IDENTITY_COLUMNS_UNSUPPORTED_DATA_TYPE" : {
"message" : [
"DataType <dataType> is not supported for IDENTITY columns."
],
"sqlState" : "KD009"
},
"DELTA_IDENTITY_COLUMNS_ILLEGAL_STEP" : {
"message" : [
"IDENTITY column step cannot be 0."
],
"sqlState" : "42611"
},
"DELTA_IDENTITY_COLUMNS_WITH_GENERATED_EXPRESSION" : {
"message" : [
"IDENTITY column cannot be specified with a generated column expression."
],
"sqlState" : "42613"
},
"DELTA_ILLEGAL_FILE_FOUND" : {
"message" : [
"Illegal files found in a dataChange = false transaction. Files: <file>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class DeltaColumnBuilder private[tables](
}

if (dataType != null && dataType != LongType) {
throw DeltaErrors.identityColumnDataTypeNotSupported()
throw DeltaErrors.identityColumnDataTypeNotSupported(dataType)
}

metadataBuilder.putBoolean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2410,15 +2410,19 @@ trait DeltaErrorsBase
}

def identityColumnWithGenerationExpression(): Throwable = {
new AnalysisException("Identity column cannot be specified with a generated column expression.")
new DeltaAnalysisException(
errorClass = "DELTA_IDENTITY_COLUMNS_WITH_GENERATED_EXPRESSION", Array.empty)
}

def identityColumnIllegalStep(): Throwable = {
new AnalysisException("Identity column step cannot be 0.")
new DeltaAnalysisException(errorClass = "DELTA_IDENTITY_COLUMNS_ILLEGAL_STEP", Array.empty)
}

def identityColumnDataTypeNotSupported(): Throwable = {
new AnalysisException("Identity column does not support this data type.")
def identityColumnDataTypeNotSupported(unsupportedType: DataType): Throwable = {
new DeltaUnsupportedOperationException(
errorClass = "DELTA_IDENTITY_COLUMNS_UNSUPPORTED_DATA_TYPE",
messageParameters = Array(unsupportedType.typeName)
)
}

def identityColumnInconsistentMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,8 @@ trait DeltaSQLConfBase {
.doc(
"""
| The umbrella config to turn on/off the IDENTITY column support.
| If true, enable Delta IDENTITY column support.
| If true, enable Delta IDENTITY column write support. If a table has an IDENTITY column,
| it is not writable but still readable if this config is set to false.
|""".stripMargin)
.booleanConf
.createWithDefault(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3183,6 +3183,43 @@ trait DeltaErrorsSuiteBase
Some(s"Could not resolve expression: ${exprs.mkString(",")}")
)
}
{
val unsupportedDataType = IntegerType
val e = intercept[DeltaUnsupportedOperationException] {
throw DeltaErrors.identityColumnDataTypeNotSupported(unsupportedDataType)
}
checkErrorMessage(
e,
Some("DELTA_IDENTITY_COLUMNS_UNSUPPORTED_DATA_TYPE"),
Some("KD009"),
Some(s"DataType ${unsupportedDataType.typeName} is not supported for IDENTITY columns."),
startWith = true
)
}
{
val e = intercept[DeltaAnalysisException] {
throw DeltaErrors.identityColumnIllegalStep()
}
checkErrorMessage(
e,
Some("DELTA_IDENTITY_COLUMNS_ILLEGAL_STEP"),
Some("42611"),
Some("IDENTITY column step cannot be 0."),
startWith = true
)
}
{
val e = intercept[DeltaAnalysisException] {
throw DeltaErrors.identityColumnWithGenerationExpression()
}
checkErrorMessage(
e,
Some("DELTA_IDENTITY_COLUMNS_WITH_GENERATED_EXPRESSION"),
Some("42613"),
Some("IDENTITY column cannot be specified with a generated column expression."),
startWith = true
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class IdentityColumnScalaSuite
val tblName = "identity_test"
for (unsupportedType <- unsupportedDataTypes) {
withTable(tblName) {
val ex = intercept[AnalysisException] {
val ex = intercept[DeltaUnsupportedOperationException] {
createTable(
tblName,
Seq(
Expand All @@ -143,7 +143,8 @@ class IdentityColumnScalaSuite
)
)
}
assert(ex.getMessage.contains("Identity column does not support this data type."))
assert(ex.getErrorClass === "DELTA_IDENTITY_COLUMNS_UNSUPPORTED_DATA_TYPE")
assert(ex.getMessage.contains("is not supported for IDENTITY columns"))
}
}
}
Expand All @@ -155,21 +156,23 @@ class IdentityColumnScalaSuite
startsWith <- Seq(Some(1L), None)
} {
withTable(tblName) {
val ex = intercept[AnalysisException] {
val ex = intercept[DeltaAnalysisException] {
createTableWithIdColAndIntValueCol(
tblName, generatedAsIdentityType, startsWith, incrementBy = Some(0))
}
assert(ex.getErrorClass === "DELTA_IDENTITY_COLUMNS_ILLEGAL_STEP")
assert(ex.getMessage.contains("step cannot be 0."))
}
}
}

test("cannot specify generatedAlwaysAs with identity columns") {
def expectColumnBuilderError(f: => StructField): Unit = {
val ex1 = intercept[AnalysisException] {
val ex = intercept[DeltaAnalysisException] {
f
}
ex1.getMessage.contains(
assert(ex.getErrorClass === "DELTA_IDENTITY_COLUMNS_WITH_GENERATED_EXPRESSION")
ex.getMessage.contains(
"Identity column cannot be specified with a generated column expression.")
}
val generatedColumn = io.delta.tables.DeltaTable.columnBuilder(spark, "id")
Expand Down

0 comments on commit 8ab57a0

Please sign in to comment.