Skip to content

Commit

Permalink
[SPARK-46576][SQL] Improve error messages for unsupported data source…
Browse files Browse the repository at this point in the history
… save mode

### What changes were proposed in this pull request?

This PR renames the error class `_LEGACY_ERROR_TEMP_1308` to `UNSUPPORTED_DATA_SOURCE_SAVE_MODE` and improves its error messages.

### Why are the changes needed?

To make the error more user-friendly.

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

New unit tests

### Was this patch authored or co-authored using generative AI tooling?

No

Closes apache#44576 from allisonwang-db/spark-46576-unsupported-save-mode.

Authored-by: allisonwang-db <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
  • Loading branch information
allisonwang-db authored and MaxGekk committed Jan 4, 2024
1 parent 59d147a commit 69c4687
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
11 changes: 6 additions & 5 deletions common/utils/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3588,6 +3588,12 @@
],
"sqlState" : "0A000"
},
"UNSUPPORTED_DATA_SOURCE_SAVE_MODE" : {
"message" : [
"The data source '<source>' cannot be written in the <createMode> mode. Please use either the \"Append\" or \"Overwrite\" mode instead."
],
"sqlState" : "0A000"
},
"UNSUPPORTED_DATA_TYPE_FOR_DATASOURCE" : {
"message" : [
"The <format> datasource doesn't support the column <columnName> of the type <columnType>."
Expand Down Expand Up @@ -5403,11 +5409,6 @@
"There is a 'path' option set and save() is called with a path parameter. Either remove the path option, or call save() without the parameter. To ignore this check, set '<config>' to 'true'."
]
},
"_LEGACY_ERROR_TEMP_1308" : {
"message" : [
"TableProvider implementation <source> cannot be written with <createMode> mode, please use Append or Overwrite modes instead."
]
},
"_LEGACY_ERROR_TEMP_1309" : {
"message" : [
"insertInto() can't be used together with partitionBy(). Partition columns have already been defined for the table. It is not necessary to use partitionBy()."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class KafkaSinkBatchSuiteV2 extends KafkaSinkBatchSuiteBase {

test("batch - unsupported save modes") {
testUnsupportedSaveModes((mode) =>
Seq(s"cannot be written with ${mode.name} mode", "does not support truncate"))
Seq(s"cannot be written in the \"${mode.name}\" mode", "does not support truncate"))
}

test("generic - write big data with small producer buffer") {
Expand Down
6 changes: 6 additions & 0 deletions docs/sql-error-conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,12 @@ Unsupported data source type for direct query on files: `<dataSourceType>`

Unsupported data type `<typeName>`.

### UNSUPPORTED_DATA_SOURCE_SAVE_MODE

[SQLSTATE: 0A000](sql-error-conditions-sqlstates.html#class-0A-feature-not-supported)

The data source '`<source>`' cannot be written in the `<createMode>` mode. Please use either the "Append" or "Overwrite" mode instead.

### UNSUPPORTED_DATA_TYPE_FOR_DATASOURCE

[SQLSTATE: 0A000](sql-error-conditions-sqlstates.html#class-0A-feature-not-supported)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3193,10 +3193,10 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase with Compilat

def writeWithSaveModeUnsupportedBySourceError(source: String, createMode: String): Throwable = {
new AnalysisException(
errorClass = "_LEGACY_ERROR_TEMP_1308",
errorClass = "UNSUPPORTED_DATA_SOURCE_SAVE_MODE",
messageParameters = Map(
"source" -> source,
"createMode" -> createMode))
"createMode" -> toDSOption(createMode)))
}

def partitionByDoesNotAllowedWhenUsingInsertIntoError(): Throwable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ class DataSourceV2Suite extends QueryTest with SharedSparkSession with AdaptiveS
.write.format(cls.getName)
.option("path", path).mode("ignore").save()
},
errorClass = "_LEGACY_ERROR_TEMP_1308",
errorClass = "UNSUPPORTED_DATA_SOURCE_SAVE_MODE",
parameters = Map(
"source" -> cls.getName,
"createMode" -> "Ignore"
"createMode" -> "\"Ignore\""
)
)

Expand All @@ -467,10 +467,10 @@ class DataSourceV2Suite extends QueryTest with SharedSparkSession with AdaptiveS
.write.format(cls.getName)
.option("path", path).mode("error").save()
},
errorClass = "_LEGACY_ERROR_TEMP_1308",
errorClass = "UNSUPPORTED_DATA_SOURCE_SAVE_MODE",
parameters = Map(
"source" -> cls.getName,
"createMode" -> "ErrorIfExists"
"createMode" -> "\"ErrorIfExists\""
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,21 @@ class PythonDataSourceSuite extends QueryTest with SharedSparkSession {
}

withClue("without mode") {
val error = intercept[AnalysisException] {
spark.range(1).write.format(dataSourceName).save()
}
// TODO: improve this error message.
assert(error.getMessage.contains("TableProvider implementation SimpleDataSource " +
"cannot be written with ErrorIfExists mode, please use Append or Overwrite modes instead."))
checkError(
exception = intercept[AnalysisException] {
spark.range(1).write.format(dataSourceName).save()
},
errorClass = "UNSUPPORTED_DATA_SOURCE_SAVE_MODE",
parameters = Map("source" -> "SimpleDataSource", "createMode" -> "\"ErrorIfExists\""))
}

withClue("with unsupported mode") {
checkError(
exception = intercept[AnalysisException] {
spark.range(1).write.format(dataSourceName).mode("ignore").save()
},
errorClass = "UNSUPPORTED_DATA_SOURCE_SAVE_MODE",
parameters = Map("source" -> "SimpleDataSource", "createMode" -> "\"Ignore\""))
}

withClue("invalid mode") {
Expand Down

0 comments on commit 69c4687

Please sign in to comment.