Skip to content

[WIP][SQL] Clarify schema mismatch types in insertInto error #51446

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

Open
wants to merge 5 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@ in the online documentation for an overview on how to configure Spark.

Please review the [Contribution to Spark guide](https://spark.apache.org/contributing.html)
for information on how to get started contributing to the project.
# trigger build
10 changes: 10 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,16 @@
},
"sqlState" : "21S01"
},
"INSERT_INTO_SCHEMA_MISMATCH": {
"message": "InsertInto schema mismatch at column '%columnName%':\n- DataFrame column has type %sourceType%\n- Target table column '%targetColumnName%' has type %targetType%\n- Columns matched by position",
"sqlState": "42K09",
"parameters": [
"columnName",
"sourceType",
"targetColumnName",
"targetType"
]
},
"INSERT_PARTITION_COLUMN_ARITY_MISMATCH" : {
"message" : [
"Cannot write to '<tableName>', <reason>:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,16 @@ object TableOutputResolver extends SQLConfHelper with Logging {

val canWriteExpr = canWrite(
tableName, queryExpr.dataType, attrTypeWithoutCharVarchar,
byName, conf, addError, colPath)
byName, conf, errorMsg => {
val colName = colPath.lastOption.getOrElse(tableAttr.name)
addError(QueryCompilationErrors.insertIntoSchemaMismatchError(
colName,
queryExpr.dataType.simpleString,
tableAttr.name,
attrTypeWithoutCharVarchar.simpleString
))
}
, colPath)

if (canWriteExpr) outputField else None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,23 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase with Compilat
origin = t.origin)
}

def insertIntoSchemaMismatchError(
columnName: String,
sourceType: String,
targetColumnName: String,
targetType: String): AnalysisException = {
new AnalysisException(
errorClass = "INSERT_INTO_SCHEMA_MISMATCH",
messageParameters = Map(
"columnName" -> columnName,
"sourceType" -> sourceType,
"targetColumnName" -> targetColumnName,
"targetType" -> targetType
)
)
}


def writeIntoViewNotAllowedError(identifier: TableIdentifier, t: TreeNode[_]): Throwable = {
new AnalysisException(
errorClass = "_LEGACY_ERROR_TEMP_1011",
Expand Down
2 changes: 2 additions & 0 deletions trigger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# trigger re-run
# trigger re-run