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/08/12 15:16:45 UTC
[GitHub] [spark] cloud-fan opened a new pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
cloud-fan opened a new pull request #33728:
URL: https://github.com/apache/spark/pull/33728
<!--
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'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### 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.
-->
Today, when we write data to a v2 table with byName mode, we only reorder the top-level columns, not inner struct fields. This doesn't make sense as Spark should treat inner struct fields as the first-class citizen (e.g. nested column pruning, filter pushdown with nested columns).
This PR improves `TableOutputResolver` to reorder inner fields as well.
### 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.
-->
better user-experience
### 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'.
-->
yes, more queries are allowed to write to v2 tables.
### 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.
-->
new test
--
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 removed a comment on pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898091009
**[Test build #142405 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142405/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898196754
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/46917/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898091009
**[Test build #142405 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142405/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-897731882
cc @sunchao @yaooqinn
--
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] dilipbiswal commented on a change in pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
dilipbiswal commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r687873492
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,42 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ val matchedCol = matched.head match {
+ case a: Attribute => a.withName(expectedCol.name)
+ case a: Alias => a.withName(expectedCol.name)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (input: StructType, expected: StructType) =>
+ val fields = input.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(matchedCol, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(
+ fields, expected.toAttributes, conf, addError, newColPath)
+ Some(Alias(CreateStruct(reordered), expectedCol.name)())
+ case _ =>
Review comment:
@cloud-fan Thanks for the fix !! I am thinking, do we need cases for Array and Map types ? Like for cases.
Struct<a: Array<Struct>> . Don't we need to build up new expressions to create the arrays and maps from the remapped inner structs ?
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r687835742
##########
File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/V2WriteAnalysisSuite.scala
##########
@@ -220,29 +221,15 @@ abstract class DataSourceV2StrictAnalysisSuite extends DataSourceV2AnalysisBaseS
}
}
-abstract class DataSourceV2AnalysisBaseSuite extends AnalysisTest {
+abstract class V2WriteAnalysisSuiteBase extends AnalysisTest {
Review comment:
a small update to make the test suite names consistent: V2XXXSuite
--
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 removed a comment on pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898289170
**[Test build #142423 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142423/testReport)** for PR 33728 at commit [`3693ce6`](https://github.com/apache/spark/commit/3693ce6241701e6451224395c68e716f02b65424).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898440704
**[Test build #142423 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142423/testReport)** for PR 33728 at commit [`3693ce6`](https://github.com/apache/spark/commit/3693ce6241701e6451224395c68e716f02b65424).
* This patch **fails Spark unit tests**.
* This patch merges cleanly.
* This patch adds no public classes.
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898289170
**[Test build #142423 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142423/testReport)** for PR 33728 at commit [`3693ce6`](https://github.com/apache/spark/commit/3693ce6241701e6451224395c68e716f02b65424).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898620626
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898056434
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/142387/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-897765785
Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46892/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898275751
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/142411/
--
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 removed a comment on pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898156520
**[Test build #142411 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142411/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #33728:
URL: https://github.com/apache/spark/pull/33728
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898620626
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/46941/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r688216716
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,42 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ val matchedCol = matched.head match {
+ case a: Attribute => a.withName(expectedCol.name)
+ case a: Alias => a.withName(expectedCol.name)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (input: StructType, expected: StructType) =>
+ val fields = input.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(matchedCol, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(
+ fields, expected.toAttributes, conf, addError, newColPath)
+ Some(Alias(CreateStruct(reordered), expectedCol.name)())
+ case _ =>
Review comment:
Let me add tests and check it out.
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898156062
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898449879
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/142423/
--
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] viirya commented on a change in pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r689244868
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,160 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ val matchedCols = mutable.HashSet.empty[String]
+ val reordered = expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ matchedCols += matched.head.name
+ val expectedName = expectedCol.name
+ val matchedCol = matched.head match {
+ // Save an Alias if we can change the name directly.
+ case a: Attribute => a.withName(expectedName)
+ case a: Alias => a.withName(expectedName)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (matchedType: StructType, expectedType: StructType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveStructType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case (matchedType: ArrayType, expectedType: ArrayType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveArrayType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case (matchedType: MapType, expectedType: MapType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveMapType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case _ =>
+ checkField(expectedCol, matchedCol, byName = true, conf, addError)
+ }
+ }
+ }
+
+ if (reordered.length == expectedCols.length) {
+ if (matchedCols.size < inputCols.length) {
+ val extraCols = inputCols.filterNot(col => matchedCols.contains(col.name))
+ .map(col => s"'${col.name}'").mkString(", ")
+ addError(s"Cannot write extra fields to struct '${colPath.quoted}': $extraCols")
+ Nil
+ } else {
+ reordered
+ }
+ } else {
+ Nil
+ }
+ }
+
+ private def checkNullability(
+ input: Expression,
+ expected: Attribute,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Unit = {
+ if (input.nullable && !expected.nullable &&
+ conf.storeAssignmentPolicy != StoreAssignmentPolicy.LEGACY) {
+ addError(s"Cannot write nullable values to non-null column '${colPath.quoted}'")
+ }
+ }
+
+ private def resolveStructType(
+ input: NamedExpression,
+ inputType: StructType,
+ expectedType: StructType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ val fields = inputType.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(input, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(fields, expectedType.toAttributes, conf, addError, colPath)
+ if (reordered.length == expectedType.length) {
+ val struct = CreateStruct(reordered)
+ val res = if (input.nullable) {
+ If(IsNull(input), Literal(null, struct.dataType), struct)
+ } else {
+ struct
+ }
+ Some(Alias(res, expectedName)())
+ } else {
+ None
+ }
+ }
+
+ private def resolveArrayType(
+ input: NamedExpression,
+ inputType: ArrayType,
+ expectedType: ArrayType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ if (inputType.containsNull && !expectedType.containsNull) {
+ addError(s"Cannot write nullable elements to array of non-nulls: '${colPath.quoted}'")
+ None
+ } else {
+ val param = NamedLambdaVariable("x", inputType.elementType, inputType.containsNull)
+ val fakeAttr = AttributeReference("x", expectedType.elementType, expectedType.containsNull)()
+ val res = reorderColumnsByName(Seq(param), Seq(fakeAttr), conf, addError, colPath)
+ if (res.length == 1) {
+ val func = LambdaFunction(res.head, Seq(param))
+ Some(Alias(ArrayTransform(input, func), expectedName)())
+ } else {
+ None
+ }
+ }
+ }
+
+ private def resolveMapType(
+ input: NamedExpression,
+ inputType: MapType,
+ expectedType: MapType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ if (inputType.valueContainsNull && !expectedType.valueContainsNull) {
+ addError(s"Cannot write nullable values to map of non-nulls: '${colPath.quoted}'")
+ None
+ } else {
+ val keyParam = NamedLambdaVariable("k", inputType.keyType, nullable = false)
+ val fakeKeyAttr = AttributeReference("k", expectedType.keyType, nullable = false)()
+ val resKey = reorderColumnsByName(
+ Seq(keyParam), Seq(fakeKeyAttr), conf, addError, colPath :+ "key")
+
+ val valueParam = NamedLambdaVariable("v", inputType.valueType, inputType.valueContainsNull)
+ val fakeValueAttr =
+ AttributeReference("v", expectedType.valueType, expectedType.valueContainsNull)()
+ val resValue = reorderColumnsByName(
+ Seq(valueParam), Seq(fakeValueAttr), conf, addError, colPath :+ "value")
+
+ if (resKey.length == 1 && resValue.length == 1) {
+ val keyFunc = LambdaFunction(resKey.head, Seq(keyParam))
+ val valueFunc = LambdaFunction(resValue.head, Seq(valueParam))
+ val newKeys = ArrayTransform(MapKeys(input), keyFunc)
+ val newValues = ArrayTransform(MapValues(input), valueFunc)
+ Some(Alias(MapFromArrays(newKeys, newValues), expectedName)())
Review comment:
ok
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898156520
**[Test build #142411 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142411/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898156073
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-897815194
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/46892/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898725606
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/142434/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898196754
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/46917/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898137728
**[Test build #142405 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142405/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
* This patch **fails Spark unit tests**.
* This patch merges cleanly.
* This patch adds no public classes.
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898274585
**[Test build #142411 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142411/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
--
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 removed a comment on pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898578375
**[Test build #142434 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142434/testReport)** for PR 33728 at commit [`452b535`](https://github.com/apache/spark/commit/452b53571f26ad8b4994910b2cb99325f43a4215).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898357011
Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46929/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-897815194
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/46892/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898151459
Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46911/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r688346957
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,42 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ val matchedCol = matched.head match {
+ case a: Attribute => a.withName(expectedCol.name)
+ case a: Alias => a.withName(expectedCol.name)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (input: StructType, expected: StructType) =>
+ val fields = input.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(matchedCol, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(
+ fields, expected.toAttributes, conf, addError, newColPath)
+ Some(Alias(CreateStruct(reordered), expectedCol.name)())
+ case _ =>
Review comment:
Added
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898620596
Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46941/
--
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] sunchao commented on a change in pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r688580414
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,42 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ val matchedCol = matched.head match {
+ case a: Attribute => a.withName(expectedCol.name)
+ case a: Alias => a.withName(expectedCol.name)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (input: StructType, expected: StructType) =>
+ val fields = input.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(matchedCol, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(
+ fields, expected.toAttributes, conf, addError, newColPath)
+ Some(Alias(CreateStruct(reordered), expectedCol.name)())
+ case _ =>
Review comment:
oops I missed the cases when structs are inside array & map, good point @dilipbiswal !
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-897800681
Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46892/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898719297
**[Test build #142434 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142434/testReport)** for PR 33728 at commit [`452b535`](https://github.com/apache/spark/commit/452b53571f26ad8b4994910b2cb99325f43a4215).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
--
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] sunchao commented on a change in pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r687961061
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,42 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ val matchedCol = matched.head match {
+ case a: Attribute => a.withName(expectedCol.name)
+ case a: Alias => a.withName(expectedCol.name)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (input: StructType, expected: StructType) =>
+ val fields = input.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(matchedCol, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(
+ fields, expected.toAttributes, conf, addError, newColPath)
+ Some(Alias(CreateStruct(reordered), expectedCol.name)())
+ case _ =>
Review comment:
I think these case are already covered in the clause.
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r689241054
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,160 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ val matchedCols = mutable.HashSet.empty[String]
+ val reordered = expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ matchedCols += matched.head.name
+ val expectedName = expectedCol.name
+ val matchedCol = matched.head match {
+ // Save an Alias if we can change the name directly.
+ case a: Attribute => a.withName(expectedName)
+ case a: Alias => a.withName(expectedName)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (matchedType: StructType, expectedType: StructType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveStructType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case (matchedType: ArrayType, expectedType: ArrayType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveArrayType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case (matchedType: MapType, expectedType: MapType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveMapType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case _ =>
+ checkField(expectedCol, matchedCol, byName = true, conf, addError)
+ }
+ }
+ }
+
+ if (reordered.length == expectedCols.length) {
+ if (matchedCols.size < inputCols.length) {
+ val extraCols = inputCols.filterNot(col => matchedCols.contains(col.name))
+ .map(col => s"'${col.name}'").mkString(", ")
+ addError(s"Cannot write extra fields to struct '${colPath.quoted}': $extraCols")
+ Nil
+ } else {
+ reordered
+ }
+ } else {
+ Nil
+ }
+ }
+
+ private def checkNullability(
+ input: Expression,
+ expected: Attribute,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Unit = {
+ if (input.nullable && !expected.nullable &&
+ conf.storeAssignmentPolicy != StoreAssignmentPolicy.LEGACY) {
+ addError(s"Cannot write nullable values to non-null column '${colPath.quoted}'")
+ }
+ }
+
+ private def resolveStructType(
+ input: NamedExpression,
+ inputType: StructType,
+ expectedType: StructType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ val fields = inputType.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(input, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(fields, expectedType.toAttributes, conf, addError, colPath)
+ if (reordered.length == expectedType.length) {
+ val struct = CreateStruct(reordered)
+ val res = if (input.nullable) {
+ If(IsNull(input), Literal(null, struct.dataType), struct)
+ } else {
+ struct
+ }
+ Some(Alias(res, expectedName)())
+ } else {
+ None
+ }
+ }
+
+ private def resolveArrayType(
+ input: NamedExpression,
+ inputType: ArrayType,
+ expectedType: ArrayType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ if (inputType.containsNull && !expectedType.containsNull) {
+ addError(s"Cannot write nullable elements to array of non-nulls: '${colPath.quoted}'")
+ None
+ } else {
+ val param = NamedLambdaVariable("x", inputType.elementType, inputType.containsNull)
+ val fakeAttr = AttributeReference("x", expectedType.elementType, expectedType.containsNull)()
+ val res = reorderColumnsByName(Seq(param), Seq(fakeAttr), conf, addError, colPath)
+ if (res.length == 1) {
+ val func = LambdaFunction(res.head, Seq(param))
+ Some(Alias(ArrayTransform(input, func), expectedName)())
+ } else {
+ None
+ }
+ }
+ }
+
+ private def resolveMapType(
+ input: NamedExpression,
+ inputType: MapType,
+ expectedType: MapType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ if (inputType.valueContainsNull && !expectedType.valueContainsNull) {
+ addError(s"Cannot write nullable values to map of non-nulls: '${colPath.quoted}'")
+ None
+ } else {
+ val keyParam = NamedLambdaVariable("k", inputType.keyType, nullable = false)
+ val fakeKeyAttr = AttributeReference("k", expectedType.keyType, nullable = false)()
+ val resKey = reorderColumnsByName(
+ Seq(keyParam), Seq(fakeKeyAttr), conf, addError, colPath :+ "key")
+
+ val valueParam = NamedLambdaVariable("v", inputType.valueType, inputType.valueContainsNull)
+ val fakeValueAttr =
+ AttributeReference("v", expectedType.valueType, expectedType.valueContainsNull)()
+ val resValue = reorderColumnsByName(
+ Seq(valueParam), Seq(fakeValueAttr), conf, addError, colPath :+ "value")
+
+ if (resKey.length == 1 && resValue.length == 1) {
+ val keyFunc = LambdaFunction(resKey.head, Seq(keyParam))
+ val valueFunc = LambdaFunction(resValue.head, Seq(valueParam))
+ val newKeys = ArrayTransform(MapKeys(input), keyFunc)
+ val newValues = ArrayTransform(MapValues(input), valueFunc)
+ Some(Alias(MapFromArrays(newKeys, newValues), expectedName)())
Review comment:
This creates map twice, can be slower.
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898191977
Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46917/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898357043
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/46929/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898333274
Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46929/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898275751
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/142411/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898106438
Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46911/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-897730638
**[Test build #142387 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142387/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898044345
**[Test build #142387 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142387/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
* This patch **fails from timeout after a configured wait of `500m`**.
* This patch merges cleanly.
* This patch adds no public classes.
--
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] viirya commented on a change in pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r689016665
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,160 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ val matchedCols = mutable.HashSet.empty[String]
+ val reordered = expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ matchedCols += matched.head.name
+ val expectedName = expectedCol.name
+ val matchedCol = matched.head match {
+ // Save an Alias if we can change the name directly.
+ case a: Attribute => a.withName(expectedName)
+ case a: Alias => a.withName(expectedName)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (matchedType: StructType, expectedType: StructType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveStructType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case (matchedType: ArrayType, expectedType: ArrayType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveArrayType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case (matchedType: MapType, expectedType: MapType) =>
+ checkNullability(matchedCol, expectedCol, conf, addError, newColPath)
+ resolveMapType(
+ matchedCol, matchedType, expectedType, expectedName, conf, addError, newColPath)
+ case _ =>
+ checkField(expectedCol, matchedCol, byName = true, conf, addError)
+ }
+ }
+ }
+
+ if (reordered.length == expectedCols.length) {
+ if (matchedCols.size < inputCols.length) {
+ val extraCols = inputCols.filterNot(col => matchedCols.contains(col.name))
+ .map(col => s"'${col.name}'").mkString(", ")
+ addError(s"Cannot write extra fields to struct '${colPath.quoted}': $extraCols")
+ Nil
+ } else {
+ reordered
+ }
+ } else {
+ Nil
+ }
+ }
+
+ private def checkNullability(
+ input: Expression,
+ expected: Attribute,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Unit = {
+ if (input.nullable && !expected.nullable &&
+ conf.storeAssignmentPolicy != StoreAssignmentPolicy.LEGACY) {
+ addError(s"Cannot write nullable values to non-null column '${colPath.quoted}'")
+ }
+ }
+
+ private def resolveStructType(
+ input: NamedExpression,
+ inputType: StructType,
+ expectedType: StructType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ val fields = inputType.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(input, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(fields, expectedType.toAttributes, conf, addError, colPath)
+ if (reordered.length == expectedType.length) {
+ val struct = CreateStruct(reordered)
+ val res = if (input.nullable) {
+ If(IsNull(input), Literal(null, struct.dataType), struct)
+ } else {
+ struct
+ }
+ Some(Alias(res, expectedName)())
+ } else {
+ None
+ }
+ }
+
+ private def resolveArrayType(
+ input: NamedExpression,
+ inputType: ArrayType,
+ expectedType: ArrayType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ if (inputType.containsNull && !expectedType.containsNull) {
+ addError(s"Cannot write nullable elements to array of non-nulls: '${colPath.quoted}'")
+ None
+ } else {
+ val param = NamedLambdaVariable("x", inputType.elementType, inputType.containsNull)
+ val fakeAttr = AttributeReference("x", expectedType.elementType, expectedType.containsNull)()
+ val res = reorderColumnsByName(Seq(param), Seq(fakeAttr), conf, addError, colPath)
+ if (res.length == 1) {
+ val func = LambdaFunction(res.head, Seq(param))
+ Some(Alias(ArrayTransform(input, func), expectedName)())
+ } else {
+ None
+ }
+ }
+ }
+
+ private def resolveMapType(
+ input: NamedExpression,
+ inputType: MapType,
+ expectedType: MapType,
+ expectedName: String,
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String]): Option[NamedExpression] = {
+ if (inputType.valueContainsNull && !expectedType.valueContainsNull) {
+ addError(s"Cannot write nullable values to map of non-nulls: '${colPath.quoted}'")
+ None
+ } else {
+ val keyParam = NamedLambdaVariable("k", inputType.keyType, nullable = false)
+ val fakeKeyAttr = AttributeReference("k", expectedType.keyType, nullable = false)()
+ val resKey = reorderColumnsByName(
+ Seq(keyParam), Seq(fakeKeyAttr), conf, addError, colPath :+ "key")
+
+ val valueParam = NamedLambdaVariable("v", inputType.valueType, inputType.valueContainsNull)
+ val fakeValueAttr =
+ AttributeReference("v", expectedType.valueType, expectedType.valueContainsNull)()
+ val resValue = reorderColumnsByName(
+ Seq(valueParam), Seq(fakeValueAttr), conf, addError, colPath :+ "value")
+
+ if (resKey.length == 1 && resValue.length == 1) {
+ val keyFunc = LambdaFunction(resKey.head, Seq(keyParam))
+ val valueFunc = LambdaFunction(resValue.head, Seq(valueParam))
+ val newKeys = ArrayTransform(MapKeys(input), keyFunc)
+ val newValues = ArrayTransform(MapValues(input), valueFunc)
+ Some(Alias(MapFromArrays(newKeys, newValues), expectedName)())
Review comment:
`TransformValues(TransformKeys(input, keyFunc), valueFunc)`?
--
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] HyukjinKwon commented on pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898089055
retest this please
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898056434
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/142387/
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898175294
Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46917/
--
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] yaooqinn commented on pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
yaooqinn commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898138586
retest this please
--
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 removed a comment on pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-897730638
**[Test build #142387 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142387/testReport)** for PR 33728 at commit [`81101d0`](https://github.com/apache/spark/commit/81101d08c54ead4a2bb37aae576770005b2fc696).
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-899275097
jenkins passes and GA failure is unrelated. I'm merging this to master, thanks for the review!
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898357043
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898578375
**[Test build #142434 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/142434/testReport)** for PR 33728 at commit [`452b535`](https://github.com/apache/spark/commit/452b53571f26ad8b4994910b2cb99325f43a4215).
--
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] dilipbiswal commented on a change in pull request #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
dilipbiswal commented on a change in pull request #33728:
URL: https://github.com/apache/spark/pull/33728#discussion_r687873492
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala
##########
@@ -74,6 +66,42 @@ object TableOutputResolver {
}
}
+ private def reorderColumnsByName(
+ inputCols: Seq[NamedExpression],
+ expectedCols: Seq[Attribute],
+ conf: SQLConf,
+ addError: String => Unit,
+ colPath: Seq[String] = Nil): Seq[NamedExpression] = {
+ expectedCols.flatMap { expectedCol =>
+ val matched = inputCols.filter(col => conf.resolver(col.name, expectedCol.name))
+ val newColPath = colPath :+ expectedCol.name
+ if (matched.isEmpty) {
+ addError(s"Cannot find data for output column '${newColPath.quoted}'")
+ None
+ } else if (matched.length > 1) {
+ addError(s"Ambiguous column name in the input data: '${newColPath.quoted}'")
+ None
+ } else {
+ val matchedCol = matched.head match {
+ case a: Attribute => a.withName(expectedCol.name)
+ case a: Alias => a.withName(expectedCol.name)
+ case other => other
+ }
+ (matchedCol.dataType, expectedCol.dataType) match {
+ case (input: StructType, expected: StructType) =>
+ val fields = input.zipWithIndex.map { case (f, i) =>
+ Alias(GetStructField(matchedCol, i, Some(f.name)), f.name)()
+ }
+ val reordered = reorderColumnsByName(
+ fields, expected.toAttributes, conf, addError, newColPath)
+ Some(Alias(CreateStruct(reordered), expectedCol.name)())
+ case _ =>
Review comment:
@cloud-fan Thanks for the fix !! I am thinking, do we need cases for Array and Map types ? Like for cases.
Struct<a: Array<Struct>> . Don't we need to create the arrays and maps from the remapped inner structs ?
--
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 #33728: [SPARK-36498][SQL] Reorder inner fields of the input query in byName V2 write
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33728:
URL: https://github.com/apache/spark/pull/33728#issuecomment-898601190
Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/46941/
--
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