Skip to content

Commit 3cd1d33

Browse files
committed
[SQL] Clarify schema mismatch types in insertInto error
1 parent d88298a commit 3cd1d33

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,16 @@ object TableOutputResolver extends SQLConfHelper with Logging {
570570

571571
val canWriteExpr = canWrite(
572572
tableName, queryExpr.dataType, attrTypeWithoutCharVarchar,
573-
byName, conf, addError, colPath)
573+
byName, conf, errorMsg => {
574+
val colName = colPath.lastOption.getOrElse(tableAttr.name)
575+
addError(QueryCompilationErrors.insertIntoSchemaMismatchError(
576+
colName,
577+
queryExpr.dataType.simpleString,
578+
tableAttr.name,
579+
attrTypeWithoutCharVarchar.simpleString
580+
))
581+
}
582+
, colPath)
574583

575584
if (canWriteExpr) outputField else None
576585
}

sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,23 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase with Compilat
576576
origin = t.origin)
577577
}
578578

579+
def insertIntoSchemaMismatchError(
580+
columnName: String,
581+
sourceType: String,
582+
targetColumnName: String,
583+
targetType: String): AnalysisException = {
584+
new AnalysisException(
585+
errorClass = "INSERT_INTO_SCHEMA_MISMATCH",
586+
messageParameters = Map(
587+
"columnName" -> columnName,
588+
"sourceType" -> sourceType,
589+
"targetColumnName" -> targetColumnName,
590+
"targetType" -> targetType
591+
)
592+
)
593+
}
594+
595+
579596
def writeIntoViewNotAllowedError(identifier: TableIdentifier, t: TreeNode[_]): Throwable = {
580597
new AnalysisException(
581598
errorClass = "_LEGACY_ERROR_TEMP_1011",

0 commit comments

Comments
 (0)