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 2020/12/15 18:18:22 UTC

[GitHub] [spark] yliou opened a new pull request #30788: Fix and Test for SPARK-33726

yliou opened a new pull request #30788:
URL: https://github.com/apache/spark/pull/30788


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
   -->
   
   ### What changes were proposed in this pull request?
   The code will iterate over the fields themselves in `org.apache.spark.sql.catalyst.expressions.RowBasedKeyValueBatch#allocate` instead of field names. Added UT to manually check that there's no null values in the Dataframe for the sample query in the Jira description
   <!--
   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.
   -->
   
   
   ### Why are the changes needed?
   To fix bug issue mentioned in description of https://issues.apache.org/jira/browse/SPARK-33726 .
   <!--
   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.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   No
   <!--
   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'.
   -->
   
   
   ### How was this patch tested?
   Added UT, tested manually on spark shell.
   <!--
   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.
   -->
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-764926711


   I checked this again and I would like to suggest some more changes. 
   
   1) Change the PR description and explain the problem more detailed (see below).
   
   2) As in `FixedLengthRowBasedKeyValueBatch` the `vlen` and `klen` are already stored as member variables in the constructor we could use those values to validate the added records' lengths. So I would add  an `assert` (or at least WARN/ERROR log) to `FixedLengthRowBasedKeyValueBatch#appendRow` method to check the incoming `vlen` and `klen` by comparing them with the lengths stored as member variables.
   
   # What changes were proposed in this pull request?
   
   The `RowBasedKeyValueBatch` has two different implementations depending on whether the aggregation key and value uses only fixed length data types (`FixedLengthRowBasedKeyValueBatch`) or not (`VariableLengthRowBasedKeyValueBatch`). 
   
   Before this PR the decision about the used implementation was based on by accessing the schema fields by their name.
   But if two fields has the same name and one with variable length and the other with fixed length type (and all the other fields are with fixed length types) a bad decision could be made. 
   
   When `FixedLengthRowBasedKeyValueBatch` is chosen but there is a variable length field then an aggregation function could calculate with invalid values. This case is illustrated by the example used in the unit test:
   
   ```
   with T as (select id as a, -id as x from range(3)), 
           U as (select id as b, cast(id as string) as x from range(3)) 
   select T.x, U.x, min(a) as ma, min(b) as mb from T join U on a=b group by U.x, T.x
   ```
   
    where the 'x' column in the left side of the join is a Long but on the right side is a String.
   
   --- 
   
   cc @cloud-fan what do you think (especially about 2nd point)?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766516347


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


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758607700


   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.

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] yliou commented on a change in pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r555492451



##########
File path: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java
##########
@@ -79,13 +79,11 @@ public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType va
     boolean allFixedLength = true;
     // checking if there is any variable length fields
     // there is probably a more succinct impl of this
-    for (String name : keySchema.fieldNames()) {
-      allFixedLength = allFixedLength
-              && UnsafeRow.isFixedLength(keySchema.apply(name).dataType());
+    for (StructField field: keySchema.fields()) {
+      allFixedLength = allFixedLength && UnsafeRow.isFixedLength(field.dataType());
     }
-    for (String name : valueSchema.fieldNames()) {
-      allFixedLength = allFixedLength
-              && UnsafeRow.isFixedLength(valueSchema.apply(name).dataType());
+    for (StructField field: valueSchema.fields()) {

Review comment:
       Fixed. Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] yliou commented on a change in pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r555494038



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,18 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726 Duplicate field name aggregation should not have null values in dataframe") {

Review comment:
       Got it. This title works for me.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758608502


   Jenkins, add to whitelist


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros edited a comment on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros edited a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766974909


   Oh, now I see


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765808041


   **[Test build #134393 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134393/testReport)** for PR 30788 at commit [`c6e036e`](https://github.com/apache/spark/commit/c6e036e581ed4506529941650f9d4aef3ea7f0c2).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766498102






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r562467173



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,16 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726: Aggregation on a table where a column name is reused") {
+    val query =
+      """|with T as (select id as a, -id as x from range(3)), U as (select id as b,

Review comment:
       let's properly format the SQL
   ```
   with T as (
     ...),
   U as (
     ...
   )
   SELECT ...
   FROM ... JOIN ...
   GROUP BY ...
   ```

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,16 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726: Aggregation on a table where a column name is reused") {
+    val query =
+      """|with T as (select id as a, -id as x from range(3)), U as (select id as b,

Review comment:
       let's properly format the SQL
   ```
   with T as (
     ...),
   U as (
     ...)
   SELECT ...
   FROM ... JOIN ...
   GROUP BY ...
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765845969


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/38979/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: Fix and Test for SPARK-33726

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-745473938


   Can one of the admins verify this patch?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #30788:
URL: https://github.com/apache/spark/pull/30788


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766516366






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765869821


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/134393/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765808041


   **[Test build #134393 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134393/testReport)** for PR 30788 at commit [`c6e036e`](https://github.com/apache/spark/commit/c6e036e581ed4506529941650f9d4aef3ea7f0c2).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766591390


   thanks, merging to master/3.1/3.0!  @yliou can you open a backport PR for 2.4 as it has code conflicts? thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros edited a comment on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros edited a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766717866


   > Sure, I'll add a assert to FixedLengthRowBasedKeyValueBatch#appendRow in the follow-up PR
   
   Sorry I do not got why a follow-up PR is needed for that assert...
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #30788:
URL: https://github.com/apache/spark/pull/30788


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766498102


   **[Test build #134418 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134418/testReport)** for PR 30788 at commit [`c6e036e`](https://github.com/apache/spark/commit/c6e036e581ed4506529941650f9d4aef3ea7f0c2).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758815966


   **[Test build #133971 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/133971/testReport)** for PR 30788 at commit [`ba2d3c7`](https://github.com/apache/spark/commit/ba2d3c70d1f4b0a747694aaf78cb74f426812e51).
    * 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.

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 edited a comment on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
cloud-fan edited a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765236781


   +1 to the second point. Adding an asset won't hurt but can catch this kind of bug earlier. We can add the assert in the follow-up PR, as this is a long-standing bug that we need to backport the fix, and we should avoid unnecessary changes.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758648698


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


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on a change in pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r559453797



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,18 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726 Duplicate field name aggregation should not have null values in dataframe") {
+    val query =
+      """|with T as (select id as a, -id as x from range(3)), U as (select id as b,
+         |cast(id as string) as x from range(3)) select T.x, U.x, min(a) as ma, min(b) as mb
+         |from T join U on a=b group by U.x, T.x
+      """.stripMargin
+    val df = spark.sql(query)
+    val nullCount = df.filter($"ma".isNull ).count + df.filter($"mb".isNull ).count
+    + df.filter($"U.x".isNull ).count + df.filter($"T.x".isNull).count
+    assert(nullCount == 0)

Review comment:
       Please update the PR description (by removing the "check that there's no null values in the Dataframe for the sample query" ). And please remove the link to the jira and explain here the problem fixed by this PR (the description will be the commit message when the fix is merged and browsing just the git commit messages on its own is easier than following links).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros edited a comment on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros edited a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766717866






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758629023


   **[Test build #133971 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/133971/testReport)** for PR 30788 at commit [`ba2d3c7`](https://github.com/apache/spark/commit/ba2d3c70d1f4b0a747694aaf78cb74f426812e51).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] yliou commented on a change in pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r555493275



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,18 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726 Duplicate field name aggregation should not have null values in dataframe") {
+    val query =
+      """|with T as (select id as a, -id as x from range(3)), U as (select id as b,
+         |cast(id as string) as x from range(3)) select T.x, U.x, min(a) as ma, min(b) as mb
+         |from T join U on a=b group by U.x, T.x
+      """.stripMargin
+    val df = spark.sql(query)
+    val nullCount = df.filter($"ma".isNull ).count + df.filter($"mb".isNull ).count
+    + df.filter($"U.x".isNull ).count + df.filter($"T.x".isNull).count
+    assert(nullCount == 0)

Review comment:
       Done, thanks for the suggestion.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] yliou commented on a change in pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r555492600



##########
File path: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java
##########
@@ -79,13 +79,11 @@ public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType va
     boolean allFixedLength = true;
     // checking if there is any variable length fields
     // there is probably a more succinct impl of this
-    for (String name : keySchema.fieldNames()) {
-      allFixedLength = allFixedLength
-              && UnsafeRow.isFixedLength(keySchema.apply(name).dataType());
+    for (StructField field: keySchema.fields()) {

Review comment:
       Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758629023


   **[Test build #133971 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/133971/testReport)** for PR 30788 at commit [`ba2d3c7`](https://github.com/apache/spark/commit/ba2d3c70d1f4b0a747694aaf78cb74f426812e51).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766591390


   thanks, merging to master/3.1/3.0!  @yliou can you open a backport PR for 2.4 as it has code conflicts? thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766605416


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/134418/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766516366


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/39004/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] yliou commented on a change in pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r560657787



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,18 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726 Duplicate field name aggregation should not have null values in dataframe") {
+    val query =
+      """|with T as (select id as a, -id as x from range(3)), U as (select id as b,
+         |cast(id as string) as x from range(3)) select T.x, U.x, min(a) as ma, min(b) as mb
+         |from T join U on a=b group by U.x, T.x
+      """.stripMargin
+    val df = spark.sql(query)
+    val nullCount = df.filter($"ma".isNull ).count + df.filter($"mb".isNull ).count
+    + df.filter($"U.x".isNull ).count + df.filter($"T.x".isNull).count
+    assert(nullCount == 0)

Review comment:
       Updated the PR description. Let me know if you have additional suggestions to my description change.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766498102


   **[Test build #134418 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134418/testReport)** for PR 30788 at commit [`c6e036e`](https://github.com/apache/spark/commit/c6e036e581ed4506529941650f9d4aef3ea7f0c2).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-764926711


   I checked this again and I would like to suggest some more changes. 
   
   1) Change the PR description and explain the problem more detailed (see below).
   
   2) As in `FixedLengthRowBasedKeyValueBatch` the `vlen` and `klen` are already stored as member variables in the constructor we could use those values to validate the added records' lengths. So I would add  an `assert` (or at least WARN/ERROR log) to `FixedLengthRowBasedKeyValueBatch#appendRow` method to check the incoming `vlen` and `klen` by comparing them with the lengths stored as member variables.
   
   # What changes were proposed in this pull request?
   
   The `RowBasedKeyValueBatch` has two different implementations depending on whether the aggregation key and value uses only fixed length data types (`FixedLengthRowBasedKeyValueBatch`) or not (`VariableLengthRowBasedKeyValueBatch`). 
   
   Before this PR the decision about the used implementation was based on by accessing the schema fields by their name.
   But if two fields has the same name and one with variable length and the other with fixed length type (and all the other fields are with fixed length types) a bad decision could be made. 
   
   When `FixedLengthRowBasedKeyValueBatch` is chosen but there is a variable length field then an aggregation function could calculate with invalid values. This case is illustrated by the example used in the unit test:
   
   ```
   with T as (select id as a, -id as x from range(3)), 
           U as (select id as b, cast(id as string) as x from range(3)) 
   select T.x, U.x, min(a) as ma, min(b) as mb from T join U on a=b group by U.x, T.x
   ```
   
    where the 'x' column in the left side of the join is a Long but on the right side is a String.
   
   --- 
   
   cc @cloud-fan what do you think (especially about 2nd point)?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766498102


   **[Test build #134418 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134418/testReport)** for PR 30788 at commit [`c6e036e`](https://github.com/apache/spark/commit/c6e036e581ed4506529941650f9d4aef3ea7f0c2).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] yliou commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765800322


   Sure, I'll add a `assert` to `FixedLengthRowBasedKeyValueBatch#appendRow` in the follow-up PR.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766508450


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


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765236781


   +1 to the second point. Adding an asset won't hurt but can catch this kind of bug earlier.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros removed a comment on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758607700


   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.

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] yliou edited a comment on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou edited a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765800322


   Sure, I'll add a `assert` to `FixedLengthRowBasedKeyValueBatch#appendRow` in the follow-up PR. I also used your PR description suggestion at the top @attilapiros .


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on a change in pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r555257755



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,18 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726 Duplicate field name aggregation should not have null values in dataframe") {

Review comment:
       Use ":" to separate the Spark jira ticket name and the description. 
   The description should explain the test and not the assert.
   
   So what about this?
   
   ```suggestion
     test("SPARK-33726: Aggregation on a table where a column name is reused") {
   ```

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,18 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726 Duplicate field name aggregation should not have null values in dataframe") {
+    val query =
+      """|with T as (select id as a, -id as x from range(3)), U as (select id as b,
+         |cast(id as string) as x from range(3)) select T.x, U.x, min(a) as ma, min(b) as mb
+         |from T join U on a=b group by U.x, T.x
+      """.stripMargin
+    val df = spark.sql(query)
+    val nullCount = df.filter($"ma".isNull ).count + df.filter($"mb".isNull ).count
+    + df.filter($"U.x".isNull ).count + df.filter($"T.x".isNull).count
+    assert(nullCount == 0)

Review comment:
       I would suggest to use the `checkAnswer` method for validating the result as it is a consistent set of Rows. You do not need to worry about ordering as the expected and actual data is checked with a set contains.
   
   And a nit: the space before ")" is not needed.
   
   So I suggest this:
   
   ```suggestion
       checkAnswer(df, Row(0, "0", 0, 0) :: Row(-1, "1", 1, 1) :: Row(-2, "2", 2, 2) :: Nil)
   ```

##########
File path: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java
##########
@@ -79,13 +79,11 @@ public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType va
     boolean allFixedLength = true;
     // checking if there is any variable length fields
     // there is probably a more succinct impl of this
-    for (String name : keySchema.fieldNames()) {
-      allFixedLength = allFixedLength
-              && UnsafeRow.isFixedLength(keySchema.apply(name).dataType());
+    for (StructField field: keySchema.fields()) {

Review comment:
       Keep the space on both sides of the ":" in the for each loop. 
   ```suggestion
       for (StructField field : keySchema.fields()) {
   ```

##########
File path: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/RowBasedKeyValueBatch.java
##########
@@ -79,13 +79,11 @@ public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType va
     boolean allFixedLength = true;
     // checking if there is any variable length fields
     // there is probably a more succinct impl of this
-    for (String name : keySchema.fieldNames()) {
-      allFixedLength = allFixedLength
-              && UnsafeRow.isFixedLength(keySchema.apply(name).dataType());
+    for (StructField field: keySchema.fields()) {
+      allFixedLength = allFixedLength && UnsafeRow.isFixedLength(field.dataType());
     }
-    for (String name : valueSchema.fieldNames()) {
-      allFixedLength = allFixedLength
-              && UnsafeRow.isFixedLength(valueSchema.apply(name).dataType());
+    for (StructField field: valueSchema.fields()) {

Review comment:
       Here too:
   ```suggestion
       for (StructField field : valueSchema.fields()) {
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766717866


   > Sure, I'll add a assert to FixedLengthRowBasedKeyValueBatch#appendRow in the follow-up PR
   
   Sorry I do not got why follow-up PR is needed for that assert...
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758694297


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/38558/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766717866






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766605416


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/134418/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758818173


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/133971/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766496353


   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.

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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766580429


   **[Test build #134418 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134418/testReport)** for PR 30788 at commit [`c6e036e`](https://github.com/apache/spark/commit/c6e036e581ed4506529941650f9d4aef3ea7f0c2).
    * 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.

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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758663900


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


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766516366


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/39004/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765869630


   **[Test build #134393 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134393/testReport)** for PR 30788 at commit [`c6e036e`](https://github.com/apache/spark/commit/c6e036e581ed4506529941650f9d4aef3ea7f0c2).
    * This patch **fails SparkR 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.

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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r562467173



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,16 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726: Aggregation on a table where a column name is reused") {
+    val query =
+      """|with T as (select id as a, -id as x from range(3)), U as (select id as b,

Review comment:
       let's properly format the SQL
   ```
   with t(
     ...)
   SELECT ...
   FROM ... JOIN ...
   GROUP BY ...
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] yliou commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766966946


   That's how I interpreted cloud-fan's comment regarding the assert statement. I could be mistaken though...


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] yliou commented on a change in pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #30788:
URL: https://github.com/apache/spark/pull/30788#discussion_r562989650



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -1079,6 +1079,16 @@ class DataFrameAggregateSuite extends QueryTest
     assert(aggs.head.output.map(_.dataType.simpleString).head ===
       aggs.last.output.map(_.dataType.simpleString).head)
   }
+
+  test("SPARK-33726: Aggregation on a table where a column name is reused") {
+    val query =
+      """|with T as (select id as a, -id as x from range(3)), U as (select id as b,

Review comment:
       Formatted the SQL.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766500714


   Will leave it to @cloud-fan though.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766496353






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-745473938


   Can one of the admins verify this patch?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758818173


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/133971/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-758694297


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/38558/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] yliou commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
yliou commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766966946


   That's how I interpreted cloud-fan's comment regarding the assert statement. I could be mistaken though...


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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] attilapiros commented on pull request #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
attilapiros commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766974909


   Oh, no I see


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765845969


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/38979/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-766516366






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
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 #30788: [SPARK-33726][SQL] Fix for Duplicate field names during Aggregation

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30788:
URL: https://github.com/apache/spark/pull/30788#issuecomment-765869821


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/134393/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org