imback82 commented on a change in pull request #32854:
URL: https://github.com/apache/spark/pull/32854#discussion_r648877170
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -298,6 +298,7 @@ class Analyzer(override val catalogManager: CatalogManager)
Batch("Post-Hoc Resolution", Once,
Seq(ResolveCommandsWithIfExists) ++
postHocResolutionRules: _*),
+ Batch("Normalize Alter Table Commands", Once, ResolveAlterTableCommands),
Batch("Normalize Alter Table", Once, ResolveAlterTableChanges),
Review comment:
We can remove `ResolveAlterTableChanges` once all the alter table
commands are migrated to `ResolveAlterTableCommands`.
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -3540,6 +3541,32 @@ class Analyzer(override val catalogManager:
CatalogManager)
}
}
+ /**
+ * Rule to mostly resolve, normalize and rewrite column names based on case
sensitivity
+ * for alter table commands.
+ */
+ object ResolveAlterTableCommands extends Rule[LogicalPlan] {
+ def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp {
+ case a @ AlterTableDropColumns(r: ResolvedTable, colsToDrop) =>
+ val resolvedColsToDrop = colsToDrop.flatMap { col =>
+ resolveFieldNames(r.schema, col).orElse(Some(col))
+ }
+ a.copy(columnsToDrop = resolvedColsToDrop)
+ }
+
+ /**
+ * Returns the resolved field name if the field can be resolved, returns
None if the column is
+ * not found. An error will be thrown in CheckAnalysis for columns that
can't be resolved.
+ */
+ private def resolveFieldNames(
Review comment:
This is a copied/modified version of
https://github.com/apache/spark/blob/cadd3a0588eeed42c6742ae1b7a2eaa85bd8a3af/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala#L3687
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -694,6 +697,24 @@ trait CheckAnalysis extends PredicateHelper with
LookupCatalog {
plan.setAnalyzed()
}
+ /**
+ * Find the given field name in the resolved table's schema for alter table
commands.
+ */
+ private def findField(
Review comment:
This is a copied/modified version of
https://github.com/apache/spark/blob/cadd3a0588eeed42c6742ae1b7a2eaa85bd8a3af/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala#L445
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]