You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/06/28 03:54:33 UTC
[GitHub] [spark] imback82 opened a new pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
imback82 opened a new pull request #33113:
URL: https://github.com/apache/spark/pull/33113
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
This PR proposes to migrate the following `ALTER TABLE ... CHANGE COLUMN` command to use `UnresolvedTable` as a `child` to resolve the table identifier. This allows consistent resolution rules (temp view first, etc.) to be applied for both v1/v2 commands. More info about the consistent resolution rule proposal can be found in [JIRA](https://issues.apache.org/jira/browse/SPARK-29900) or [proposal doc](https://docs.google.com/document/d/1hvLjGA8y_W_hhilpngXVub1Ebv8RsMap986nENCFnrg/edit?usp=sharing).
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
This is a part of effort to make the relation lookup behavior consistent: [SPARK-29900](https://issues.apache.org/jira/browse/SPARK-29900).
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
After this PR, the above `ALTER TABLE ... CHANGE COLUMN` commands will have a consistent resolution behavior.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
Updated existing tests.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] imback82 commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
imback82 commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r660121284
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
##########
@@ -1142,3 +1142,42 @@ case class AlterTableRenameColumn(
override protected def withNewChildInternal(newChild: LogicalPlan): LogicalPlan =
copy(table = newChild)
}
+
+/**
+ * The logical plan of the ALTER TABLE ... CHANGE COLUMN command.
Review comment:
Updated
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r663721254
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -1088,8 +1058,51 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog {
}
alter match {
- case AlterTableRenameColumn(table: ResolvedTable, ResolvedFieldName(name), newName) =>
- checkColumnNotExists(name.init :+ newName, table.schema)
+ case AlterTableRenameColumn(table: ResolvedTable, col: ResolvedFieldName, newName) =>
+ checkColumnNotExists(col.path :+ newName, table.schema)
+ case a @ AlterTableAlterColumn(table: ResolvedTable, col: ResolvedFieldName, _, _, _, _) =>
+ val fieldName = col.name.quoted
+ if (a.dataType.isDefined) {
+ val field = CharVarcharUtils.getRawType(col.field.metadata)
+ .map(dt => col.field.copy(dataType = dt))
+ .getOrElse(col.field)
+ val newDataType = a.dataType.get
+ newDataType match {
Review comment:
Actually, this is OK. In the analzer, we will set the `newDataType` to None if it's the same with the existing data type in the table.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] dongjoon-hyun commented on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-870240863
This seems to break JDBC v2 suite. I made a follow-up. Could you review that, @imback82 and @cloud-fan ?
- https://github.com/apache/spark/pull/33124
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-870933105
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/44892/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r663724637
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -3527,13 +3527,35 @@ class Analyzer(override val catalogManager: CatalogManager)
* Rule to mostly resolve, normalize and rewrite column names based on case sensitivity
* for alter table commands.
*/
- object ResolveFieldNames extends Rule[LogicalPlan] {
+ object ResolveAlterTableCommands extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp {
case a: AlterTableCommand if a.table.resolved =>
- a.transformExpressions {
+ val table = a.table.asInstanceOf[ResolvedTable]
+ val transformed = a.transformExpressions {
case u: UnresolvedFieldName =>
- val table = a.table.asInstanceOf[ResolvedTable]
- resolveFieldNames(table.schema, u.name).map(ResolvedFieldName(_)).getOrElse(u)
+ resolveFieldNames(table.schema, u.name).getOrElse(u)
+ case u: UnresolvedFieldPosition => u.position match {
+ case after: After =>
+ resolveFieldNames(table.schema, u.fieldName.init :+ after.column())
Review comment:
https://github.com/apache/spark/pull/33213
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r659497730
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/v2ResolutionPlans.scala
##########
@@ -150,7 +165,12 @@ case class ResolvedPartitionSpec(
ident: InternalRow,
location: Option[String] = None) extends PartitionSpec
-case class ResolvedFieldName(name: Seq[String]) extends FieldName
+case class ResolvedFieldName(path: Seq[String], field: StructField) extends FieldName {
+ def name: Seq[String] = path :+ field.name
+}
+
+case class ResolvedFieldPosition(position: ColumnPosition) extends FieldPosition
Review comment:
don't we need the `fieldName` in the resolved version?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-870885494
Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44892/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-870916117
Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44892/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan closed pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #33113:
URL: https://github.com/apache/spark/pull/33113
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-870933105
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/44892/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] imback82 commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
imback82 commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r659462276
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -522,66 +552,6 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog {
positionArgumentExists(add.position(), parent, fieldsAdded)
TypeUtils.failWithIntervalType(add.dataType())
colsToAdd(parentName) = fieldsAdded :+ add.fieldNames().last
- case update: UpdateColumnType =>
- val field = {
- val f = findField("update", update.fieldNames)
- CharVarcharUtils.getRawType(f.metadata)
- .map(dt => f.copy(dataType = dt))
- .getOrElse(f)
- }
- val fieldName = update.fieldNames.quoted
- update.newDataType match {
- case _: StructType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a struct by updating its fields")
- case _: MapType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a map by updating $fieldName.key or $fieldName.value")
- case _: ArrayType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update the element by updating $fieldName.element")
- case u: UserDefinedType[_] =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a UserDefinedType[${u.sql}] by updating its fields")
- case _: CalendarIntervalType | _: YearMonthIntervalType |
- _: DayTimeIntervalType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName to " +
- s"interval type")
- case _ =>
- // update is okay
- }
-
- // We don't need to handle nested types here which shall fail before
Review comment:
These changes are moved below.
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -522,66 +552,6 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog {
positionArgumentExists(add.position(), parent, fieldsAdded)
TypeUtils.failWithIntervalType(add.dataType())
colsToAdd(parentName) = fieldsAdded :+ add.fieldNames().last
- case update: UpdateColumnType =>
- val field = {
- val f = findField("update", update.fieldNames)
- CharVarcharUtils.getRawType(f.metadata)
- .map(dt => f.copy(dataType = dt))
- .getOrElse(f)
- }
- val fieldName = update.fieldNames.quoted
- update.newDataType match {
- case _: StructType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a struct by updating its fields")
- case _: MapType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a map by updating $fieldName.key or $fieldName.value")
- case _: ArrayType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update the element by updating $fieldName.element")
- case u: UserDefinedType[_] =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a UserDefinedType[${u.sql}] by updating its fields")
- case _: CalendarIntervalType | _: YearMonthIntervalType |
- _: DayTimeIntervalType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName to " +
- s"interval type")
- case _ =>
- // update is okay
- }
-
- // We don't need to handle nested types here which shall fail before
- def canAlterColumnType(from: DataType, to: DataType): Boolean = (from, to) match {
- case (CharType(l1), CharType(l2)) => l1 == l2
- case (CharType(l1), VarcharType(l2)) => l1 <= l2
- case (VarcharType(l1), VarcharType(l2)) => l1 <= l2
- case _ => Cast.canUpCast(from, to)
- }
-
- if (!canAlterColumnType(field.dataType, update.newDataType)) {
- alter.failAnalysis(
- s"Cannot update ${table.name} field $fieldName: " +
- s"${field.dataType.simpleString} cannot be cast to " +
- s"${update.newDataType.simpleString}")
- }
- case update: UpdateColumnNullability =>
- val field = findField("update", update.fieldNames)
- val fieldName = update.fieldNames.quoted
- if (!update.nullable && field.nullable) {
- alter.failAnalysis(
- s"Cannot change nullable column to non-nullable: $fieldName")
- }
- case updatePos: UpdateColumnPosition =>
- findField("update", updatePos.fieldNames)
- val parent = findParentStruct("update", updatePos.fieldNames())
- val parentName = updatePos.fieldNames().init
- positionArgumentExists(
- updatePos.position(),
- parent,
- colsToAdd.getOrElse(parentName, Nil))
Review comment:
I don't think we should consider `colsToAdd` since the `CHANGE COLUMN` command doesn't add a new column. So, in this PR, I didn't consider new columns added. Please let me know if I understood this wrong.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] imback82 commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
imback82 commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r660121284
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
##########
@@ -1142,3 +1142,42 @@ case class AlterTableRenameColumn(
override protected def withNewChildInternal(newChild: LogicalPlan): LogicalPlan =
copy(table = newChild)
}
+
+/**
+ * The logical plan of the ALTER TABLE ... CHANGE COLUMN command.
Review comment:
Updated
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] imback82 commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
imback82 commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r659462276
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -522,66 +552,6 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog {
positionArgumentExists(add.position(), parent, fieldsAdded)
TypeUtils.failWithIntervalType(add.dataType())
colsToAdd(parentName) = fieldsAdded :+ add.fieldNames().last
- case update: UpdateColumnType =>
- val field = {
- val f = findField("update", update.fieldNames)
- CharVarcharUtils.getRawType(f.metadata)
- .map(dt => f.copy(dataType = dt))
- .getOrElse(f)
- }
- val fieldName = update.fieldNames.quoted
- update.newDataType match {
- case _: StructType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a struct by updating its fields")
- case _: MapType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a map by updating $fieldName.key or $fieldName.value")
- case _: ArrayType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update the element by updating $fieldName.element")
- case u: UserDefinedType[_] =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName type: " +
- s"update a UserDefinedType[${u.sql}] by updating its fields")
- case _: CalendarIntervalType | _: YearMonthIntervalType |
- _: DayTimeIntervalType =>
- alter.failAnalysis(s"Cannot update ${table.name} field $fieldName to " +
- s"interval type")
- case _ =>
- // update is okay
- }
-
- // We don't need to handle nested types here which shall fail before
Review comment:
These changes are moved below to `checkAlterTableCommand`.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r663643466
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -3527,13 +3527,35 @@ class Analyzer(override val catalogManager: CatalogManager)
* Rule to mostly resolve, normalize and rewrite column names based on case sensitivity
* for alter table commands.
*/
- object ResolveFieldNames extends Rule[LogicalPlan] {
+ object ResolveAlterTableCommands extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp {
case a: AlterTableCommand if a.table.resolved =>
- a.transformExpressions {
+ val table = a.table.asInstanceOf[ResolvedTable]
+ val transformed = a.transformExpressions {
case u: UnresolvedFieldName =>
- val table = a.table.asInstanceOf[ResolvedTable]
- resolveFieldNames(table.schema, u.name).map(ResolvedFieldName(_)).getOrElse(u)
+ resolveFieldNames(table.schema, u.name).getOrElse(u)
+ case u: UnresolvedFieldPosition => u.position match {
+ case after: After =>
+ resolveFieldNames(table.schema, u.fieldName.init :+ after.column())
Review comment:
Do we need to put `fieldName` in `UnresolvedFieldPosition`? We can easily get it via `AlterTableAlterColumn.column.name`
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] imback82 commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-870189467
thanks, merging to master!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r659498507
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
##########
@@ -1142,3 +1142,42 @@ case class AlterTableRenameColumn(
override protected def withNewChildInternal(newChild: LogicalPlan): LogicalPlan =
copy(table = newChild)
}
+
+/**
+ * The logical plan of the ALTER TABLE ... CHANGE COLUMN command.
Review comment:
nit: let's put the SQL standard syntax in the doc `ALTER TABLE ... ALTER COLUMN`
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-870189467
thanks, merging to master!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r663634209
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -1088,8 +1058,51 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog {
}
alter match {
- case AlterTableRenameColumn(table: ResolvedTable, ResolvedFieldName(name), newName) =>
- checkColumnNotExists(name.init :+ newName, table.schema)
+ case AlterTableRenameColumn(table: ResolvedTable, col: ResolvedFieldName, newName) =>
+ checkColumnNotExists(col.path :+ newName, table.schema)
+ case a @ AlterTableAlterColumn(table: ResolvedTable, col: ResolvedFieldName, _, _, _, _) =>
+ val fieldName = col.name.quoted
+ if (a.dataType.isDefined) {
+ val field = CharVarcharUtils.getRawType(col.field.metadata)
+ .map(dt => col.field.copy(dataType = dt))
+ .getOrElse(col.field)
+ val newDataType = a.dataType.get
+ newDataType match {
Review comment:
Not related to this PR: I think there is a small bug here, if the data type is not changed, we shouldn't fail even if the new data type is struct/array/map. @imback82 can you help to fix it?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan closed pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #33113:
URL: https://github.com/apache/spark/pull/33113
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33113:
URL: https://github.com/apache/spark/pull/33113#discussion_r663721254
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -1088,8 +1058,51 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog {
}
alter match {
- case AlterTableRenameColumn(table: ResolvedTable, ResolvedFieldName(name), newName) =>
- checkColumnNotExists(name.init :+ newName, table.schema)
+ case AlterTableRenameColumn(table: ResolvedTable, col: ResolvedFieldName, newName) =>
+ checkColumnNotExists(col.path :+ newName, table.schema)
+ case a @ AlterTableAlterColumn(table: ResolvedTable, col: ResolvedFieldName, _, _, _, _) =>
+ val fieldName = col.name.quoted
+ if (a.dataType.isDefined) {
+ val field = CharVarcharUtils.getRawType(col.field.metadata)
+ .map(dt => col.field.copy(dataType = dt))
+ .getOrElse(col.field)
+ val newDataType = a.dataType.get
+ newDataType match {
Review comment:
Actually, this is OK. In the analzer, we will set the `newDataType` to None if it's the same with the existing data type in the table.
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -3527,13 +3527,35 @@ class Analyzer(override val catalogManager: CatalogManager)
* Rule to mostly resolve, normalize and rewrite column names based on case sensitivity
* for alter table commands.
*/
- object ResolveFieldNames extends Rule[LogicalPlan] {
+ object ResolveAlterTableCommands extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp {
case a: AlterTableCommand if a.table.resolved =>
- a.transformExpressions {
+ val table = a.table.asInstanceOf[ResolvedTable]
+ val transformed = a.transformExpressions {
case u: UnresolvedFieldName =>
- val table = a.table.asInstanceOf[ResolvedTable]
- resolveFieldNames(table.schema, u.name).map(ResolvedFieldName(_)).getOrElse(u)
+ resolveFieldNames(table.schema, u.name).getOrElse(u)
+ case u: UnresolvedFieldPosition => u.position match {
+ case after: After =>
+ resolveFieldNames(table.schema, u.fieldName.init :+ after.column())
Review comment:
https://github.com/apache/spark/pull/33213
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] imback82 commented on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
imback82 commented on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-869360867
cc @cloud-fan
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] dongjoon-hyun commented on pull request #33113: [SPARK-34302][SQL] Migrate ALTER TABLE ... CHANGE COLUMN command to use UnresolvedTable to resolve the identifier
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #33113:
URL: https://github.com/apache/spark/pull/33113#issuecomment-870240863
This seems to break JDBC v2 suite. I made a follow-up. Could you review that, @imback82 and @cloud-fan ?
- https://github.com/apache/spark/pull/33124
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org