Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-37577][SQL] Fix ClassCastException: ArrayType cannot be cast to StructType for Generate Pruning #34845

Closed
wants to merge 3 commits into from

Conversation

viirya
Copy link
Member

@viirya viirya commented Dec 9, 2021

What changes were proposed in this pull request?

This patch fixes a bug in nested column pruning for Generate. The bug happens after we replace extractor's reference attribute with generator's input, then when we try to replace a top extractor (e.g. GetStructField), if the replaced child expression is array type, extractFieldName will fail by throwing ClassCastException.

Why are the changes needed?

In particular, when we transform the extractor and replace with generator's input, we cannot simply do a transform up because because if we replace the attribute, extractFieldName could cause ClassCastException error. We need to get the field name before replacing down the attribute/other extractor.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added test.

@github-actions github-actions bot added the SQL label Dec 9, 2021
@SparkQA
Copy link

SparkQA commented Dec 9, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 9, 2021

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

@SparkQA

This comment has been minimized.

@viirya
Copy link
Member Author

viirya commented Dec 9, 2021

cc @cloud-fan @maropu @dongjoon-hyun

@dongjoon-hyun
Copy link
Member

Thank you for pinging me, @viirya .

StructField("o", ArrayType(StructType(
Seq(StructField("s", StringType, false),
StructField("b", ArrayType(StructType(
Seq(StructField("e", StringType, false))), true), false)
Copy link
Member

Choose a reason for hiding this comment

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

Can we use more intrusive field names? o, s, b, e looks a little confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, i will update it.

@SparkQA
Copy link

SparkQA commented Dec 9, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 9, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 10, 2021

Test build #146051 has finished for PR 34845 at commit d034ea0.

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

@SparkQA
Copy link

SparkQA commented Dec 10, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 10, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 10, 2021

Test build #146053 has finished for PR 34845 at commit 2f47271.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

// `extractFieldName` could cause `ClassCastException` error. We need to get the
// field name before replacing down the attribute/other extractor.
val fieldName = g.extractFieldName
val newChild = replaceGenerator(generator, g.child)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do a manual top-down traversal via mapChildren? It's weird to see a recursive call inside transformDown.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, let me rewrite it using mapChildren.

@SparkQA
Copy link

SparkQA commented Dec 10, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 10, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 11, 2021

Test build #146080 has finished for PR 34845 at commit a9862c3.

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

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM from my side, @viirya . Thank you.

@dongjoon-hyun
Copy link
Member

Retest this please

@SparkQA
Copy link

SparkQA commented Dec 13, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 13, 2021

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

@SparkQA
Copy link

SparkQA commented Dec 13, 2021

Test build #146114 has finished for PR 34845 at commit a9862c3.

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

@dongjoon-hyun
Copy link
Member

Thank you, @viirya , @HyukjinKwon , @cloud-fan . Merged to master.

Could you make a backport to branch-3.2, @viirya ?

@viirya
Copy link
Member Author

viirya commented Dec 13, 2021

Thanks. I will make a backport to branch-3.2.

dongjoon-hyun pushed a commit that referenced this pull request Dec 14, 2021
…ast to StructType for Generate Pruning

### What changes were proposed in this pull request?

This patch fixes a bug in nested column pruning for Generate. The bug happens after we replace extractor's reference attribute with generator's input, then when we try to replace a top extractor (e.g. `GetStructField`), if the replaced child expression is array type, `extractFieldName` will fail by throwing `ClassCastException`.

This is the backport from #34845 to branch-3.2.

### Why are the changes needed?

 In particular, when we transform the extractor and replace with generator's input, we cannot simply do a transform up because because if we replace the attribute, `extractFieldName` could cause `ClassCastException` error. We need to get the field name before replacing down the attribute/other extractor.

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

No

### How was this patch tested?

Added test.

Closes #34885 from viirya/SPARK-37577-3.2.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
catalinii pushed a commit to lyft/spark that referenced this pull request Feb 22, 2022
…ast to StructType for Generate Pruning

### What changes were proposed in this pull request?

This patch fixes a bug in nested column pruning for Generate. The bug happens after we replace extractor's reference attribute with generator's input, then when we try to replace a top extractor (e.g. `GetStructField`), if the replaced child expression is array type, `extractFieldName` will fail by throwing `ClassCastException`.

This is the backport from apache#34845 to branch-3.2.

### Why are the changes needed?

 In particular, when we transform the extractor and replace with generator's input, we cannot simply do a transform up because because if we replace the attribute, `extractFieldName` could cause `ClassCastException` error. We need to get the field name before replacing down the attribute/other extractor.

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

No

### How was this patch tested?

Added test.

Closes apache#34885 from viirya/SPARK-37577-3.2.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
catalinii pushed a commit to lyft/spark that referenced this pull request Mar 4, 2022
…ast to StructType for Generate Pruning

### What changes were proposed in this pull request?

This patch fixes a bug in nested column pruning for Generate. The bug happens after we replace extractor's reference attribute with generator's input, then when we try to replace a top extractor (e.g. `GetStructField`), if the replaced child expression is array type, `extractFieldName` will fail by throwing `ClassCastException`.

This is the backport from apache#34845 to branch-3.2.

### Why are the changes needed?

 In particular, when we transform the extractor and replace with generator's input, we cannot simply do a transform up because because if we replace the attribute, `extractFieldName` could cause `ClassCastException` error. We need to get the field name before replacing down the attribute/other extractor.

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

No

### How was this patch tested?

Added test.

Closes apache#34885 from viirya/SPARK-37577-3.2.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
kazuyukitanimura pushed a commit to kazuyukitanimura/spark that referenced this pull request Aug 10, 2022
…ast to StructType for Generate Pruning

### What changes were proposed in this pull request?

This patch fixes a bug in nested column pruning for Generate. The bug happens after we replace extractor's reference attribute with generator's input, then when we try to replace a top extractor (e.g. `GetStructField`), if the replaced child expression is array type, `extractFieldName` will fail by throwing `ClassCastException`.

This is the backport from apache#34845 to branch-3.2.

### Why are the changes needed?

 In particular, when we transform the extractor and replace with generator's input, we cannot simply do a transform up because because if we replace the attribute, `extractFieldName` could cause `ClassCastException` error. We need to get the field name before replacing down the attribute/other extractor.

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

No

### How was this patch tested?

Added test.

Closes apache#34885 from viirya/SPARK-37577-3.2.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@viirya viirya deleted the SPARK-37577 branch December 27, 2023 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants