cloud-fan commented on code in PR #52016:
URL: https://github.com/apache/spark/pull/52016#discussion_r2277219207
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala:
##########
@@ -341,58 +310,39 @@ object TableOutputResolver extends SQLConfHelper with
Logging {
inputCols: Seq[NamedExpression],
expectedCols: Seq[Attribute],
conf: SQLConf,
- addError: String => Unit,
colPath: Seq[String] = Nil): Seq[NamedExpression] = {
- val actualExpectedCols = expectedCols.map { attr =>
- attr.withDataType {
CharVarcharUtils.getRawType(attr.metadata).getOrElse(attr.dataType) }
- }
- if (inputCols.size > actualExpectedCols.size) {
- val extraColsStr = inputCols.takeRight(inputCols.size -
actualExpectedCols.size)
- .map(col => toSQLId(col.name))
- .mkString(", ")
+ if (inputCols.size > expectedCols.size) {
+ val extraColsStr = columnsToString(inputCols.drop(expectedCols.size))
if (colPath.isEmpty) {
throw
QueryCompilationErrors.cannotWriteTooManyColumnsToTableError(tableName,
- actualExpectedCols.map(_.name), inputCols.map(_.toAttribute))
+ expectedCols.map(_.name), inputCols.map(_.toAttribute))
} else {
throw
QueryCompilationErrors.incompatibleDataToTableExtraStructFieldsError(
tableName, colPath.quoted, extraColsStr
)
}
- } else if (inputCols.size < actualExpectedCols.size) {
- val missingColsStr =
actualExpectedCols.takeRight(actualExpectedCols.size - inputCols.size)
- .map(col => toSQLId(col.name))
- .mkString(", ")
+ } else if (inputCols.size < expectedCols.size) {
+ val missingColsStr = columnsToString(expectedCols.drop(inputCols.size))
if (colPath.isEmpty) {
throw
QueryCompilationErrors.cannotWriteNotEnoughColumnsToTableError(tableName,
- actualExpectedCols.map(_.name), inputCols.map(_.toAttribute))
+ expectedCols.map(_.name), inputCols.map(_.toAttribute))
} else {
throw
QueryCompilationErrors.incompatibleDataToTableStructMissingFieldsError(
tableName, colPath.quoted, missingColsStr
)
}
}
- inputCols.zip(actualExpectedCols).flatMap { case (inputCol, expectedCol) =>
+ inputCols.zip(expectedCols).map { case (inputCol, expectedCol) =>
val newColPath = colPath :+ expectedCol.name
- (inputCol.dataType, expectedCol.dataType) match {
- case (inputType: StructType, expectedType: StructType) =>
- resolveStructType(
- tableName, inputCol, inputType, expectedCol, expectedType,
- byName = false, conf, addError, newColPath)
- case (inputType: ArrayType, expectedType: ArrayType) =>
- resolveArrayType(
- tableName, inputCol, inputType, expectedCol, expectedType,
- byName = false, conf, addError, newColPath)
- case (inputType: MapType, expectedType: MapType) =>
- resolveMapType(
- tableName, inputCol, inputType, expectedCol, expectedType,
- byName = false, conf, addError, newColPath)
- case _ =>
- checkField(tableName, expectedCol, inputCol, byName = false, conf,
addError, newColPath)
- }
+ resolveField(tableName, inputCol, expectedCol, byName = false, conf,
newColPath)
}
}
+ private def columnsToString(cols: Seq[NamedExpression]): String =
+ cols.map(col => toSQLId(col.name)).mkString(", ")
+
+
private[sql] def checkNullability(
Review Comment:
shall we rename it? `checkNullability` sounds like it returns nothing but
just performs some checks. How about `withNullabilityChecked`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]