imback82 commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r659464527
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -444,12 +444,42 @@ trait CheckAnalysis extends PredicateHelper with
LookupCatalog {
write.query.schema.foreach(f =>
TypeUtils.failWithIntervalType(f.dataType))
case alter: AlterTableCommand if alter.table.resolved =>
+ val table = alter.table.asInstanceOf[ResolvedTable]
+ def findField(fieldName: Seq[String]): StructField = {
+ // Include collections because structs nested in maps and arrays
may be altered.
+ val field = table.schema.findNestedField(fieldName,
includeCollections = true)
+ if (field.isEmpty) {
+ alter.failAnalysis(s"Cannot ${alter.operation} missing field
${fieldName.quoted} " +
+ s"in ${table.name} schema: ${table.schema.treeString}")
+ }
+ field.get._2
+ }
+ def findParentStruct(fieldNames: Seq[String]): StructType = {
Review comment:
`findField` and `findParentStruct` are existing functions in
`CheckAnalysis` with a slight modification (e.g., not passing operation
argument). The existing functions will be removed once all alter table commands
are migrated.
--
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]