Skip to content

Conversation

@cloud-fan
Copy link
Contributor

What changes were proposed in this pull request?

This is a followup of #33113, to do some code cleanup:

  1. UnresolvedFieldPosition doesn't need to include the field name. We can get it through "context" (AlterTableAlterColumn.column.name).
  2. Run ResolveAlterTableCommands in the main resolution batch, so that the column/field resolution is also unified between v1 and v2 commands (same error message).
  3. Fail immediately in ResolveAlterTableCommands if we can't resolve the field, instead of waiting until CheckAnalysis. We don't expect other rules to resolve fields in ALTER TABLE commands, so failing immediately is simpler and we can remove duplicated code in CheckAnalysis.

Why are the changes needed?

code simplification.

Does this PR introduce any user-facing change?

no

How was this patch tested?

existing tests

@cloud-fan
Copy link
Contributor Author

cc @imback82

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Test build #140642 has finished for PR 33213 at commit 34bd690.

  • This patch fails to build.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class UnresolvedFieldPosition(position: ColumnPosition) extends FieldPosition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45154/

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45154/

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45157/

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45157/

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Test build #140645 has finished for PR 33213 at commit 5246630.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class UnresolvedFieldPosition(position: ColumnPosition) extends FieldPosition

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45171/

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Test build #140660 has finished for PR 33213 at commit c31f8ba.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class UnresolvedFieldPosition(position: ColumnPosition) extends FieldPosition

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45171/

Copy link
Contributor

@imback82 imback82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (if tests pass), thanks @cloud-fan!

case o => alter.failAnalysis(s"Cannot ${alter.operation} ${fieldName.quoted}, " +
s"because its parent is not a StructType. Found $o")
}
alter.failAnalysis(s"Couldn't resolve positional argument $position amongst " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnresolvedFieldPosition was carrying fieldName to reconstruct this message (no need to match by commands). If this is not needed anymore, we can drop fieldName. Thanks for cleaning this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message can refer to a position in the SQL string, which should provide sufficient context. The missing top-level column also uses a simple error message.

sql(s"ALTER TABLE $tableName ALTER COLUMN bad_column COMMENT 'test'")
}.getMessage
assert(msg.contains("Cannot update missing field bad_column in h2.test.alt_table"))
assert(msg.contains("Missing field bad_column in table h2.test.alt_table"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are simplifying the message, we may not need to have AlterTableComand.operation. I can remove it in #33200.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, thanks!

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45179/

@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45179/

@cloud-fan
Copy link
Contributor Author

thanks for the review, merging to master/3.2 (since it's a followup).

@cloud-fan cloud-fan closed this in 8b46e26 Jul 5, 2021
cloud-fan added a commit that referenced this pull request Jul 5, 2021
### What changes were proposed in this pull request?

This is a followup of #33113, to do some code cleanup:
1. `UnresolvedFieldPosition` doesn't need to include the field name. We can get it through "context" (`AlterTableAlterColumn.column.name`).
2. Run `ResolveAlterTableCommands` in the main resolution batch, so that the column/field resolution is also unified between v1 and v2 commands (same error message).
3. Fail immediately in `ResolveAlterTableCommands` if we can't resolve the field, instead of waiting until `CheckAnalysis`. We don't expect other rules to resolve fields in ALTER  TABLE commands, so failing immediately is simpler and we can remove duplicated code in `CheckAnalysis`.

### Why are the changes needed?

code simplification.

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

existing tests

Closes #33213 from cloud-fan/follow.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 8b46e26)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@SparkQA
Copy link

SparkQA commented Jul 5, 2021

Test build #140668 has finished for PR 33213 at commit 52383ba.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants