You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "landlord-matt (via GitHub)" <gi...@apache.org> on 2023/11/17 15:54:49 UTC

[PR] [MINOR][Docs] Clarify sort behaviour for structs [spark]

landlord-matt opened a new pull request, #43871:
URL: https://github.com/apache/spark/pull/43871

   <!--
   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.
   -->
   It clarifies what the the natural order of a struct is. This is to my knowledge never stated anywhere, but according to this [Stack Overflow answer](https://stackoverflow.com/a/68848379) it is the first field. 
   
   ### 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.
   -->
   It was unclear how this would behave for structs.
   
   ### 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'.
   -->
   It improves the documentation
   
   ### 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.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   Not applicable
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   No


-- 
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


Re: [PR] [MINOR][DOCS] Clarify sort behaviour for structs [spark]

Posted by "landlord-matt (via GitHub)" <gi...@apache.org>.
landlord-matt commented on code in PR #43871:
URL: https://github.com/apache/spark/pull/43871#discussion_r1399028056


##########
python/pyspark/sql/functions.py:
##########
@@ -14102,7 +14102,7 @@ def sort_array(col: "ColumnOrName", asc: bool = True) -> Column:
     Collection function: sorts the input array in ascending or descending order according
     to the natural ordering of the array elements. Null elements will be placed at the beginning
     of the returned array in ascending order or at the end of the returned array in descending
-    order.
+    order. The natural order of a struct is the natural order of the first field in the struct schema.

Review Comment:
   Maybe you are right and StackOverflow is wrong. I'm not so good at Scala, but I think it is decided [here ](https://github.com/apache/spark/blob/398bff77b1c837aed55f4f10ff1157f7da813570/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateOrdering.scala#L58) or perhaps [here](https://github.com/apache/spark/blob/398bff77b1c837aed55f4f10ff1157f7da813570/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/PhysicalDataType.scala#L318)
   
   Maybe it is sorting first on the first field, then on second and so on. 
   
   A more correct description would in this case be 
   ```suggestion
       order. The natural order of a struct is the natural order of the underlying fields of the struct schema in positional order.
   ```
   
   I'm not 100 % sure this is true either. Are we sure that we get the field in positional order when it iterates through the 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.

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


Re: [PR] [MINOR][DOCS] Clarify sort behaviour for structs [spark]

Posted by "landlord-matt (via GitHub)" <gi...@apache.org>.
landlord-matt commented on PR #43871:
URL: https://github.com/apache/spark/pull/43871#issuecomment-1824563107

   @JoshRosen : Thanks for clarifying! While it is true that the code is available for anyone to read and it is well written, I still think it would nice to have a text version for us dummies. Instead of explaining it in the function, I also had this brilliant idea of explaining it in the data type document. What do you think of this proposal? https://github.com/apache/spark/pull/43981
   
   Also, I am still wondering about this section. It loops through all the fields in the schema and adds it to that magic ordering array. I assume that ordering array corresponds to "ORDER BY 1,2,3", but what is "1,2,3" in this case? How does it iterate through the schema?
   
   https://github.com/apache/spark/blob/fdcd20f4b51c3ddddaae12f7d3f429e7b77c9f5e/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/PhysicalDataType.scala#L318-L329
   
   If you want you can also check out my other proposal about collect_list that was ignored :( https://github.com/apache/spark/pull/43787


-- 
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


Re: [PR] [MINOR][DOCS] Clarify sort behaviour for structs [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #43871:
URL: https://github.com/apache/spark/pull/43871#discussion_r1398565942


##########
python/pyspark/sql/functions.py:
##########
@@ -14102,7 +14102,7 @@ def sort_array(col: "ColumnOrName", asc: bool = True) -> Column:
     Collection function: sorts the input array in ascending or descending order according
     to the natural ordering of the array elements. Null elements will be placed at the beginning
     of the returned array in ascending order or at the end of the returned array in descending
-    order.
+    order. The natural order of a struct is the natural order of the first field in the struct schema.

Review Comment:
   Oh, so it doesn't sort by the second field?



-- 
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


Re: [PR] [MINOR][DOCS] Clarify sort behaviour for structs [spark]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #43871: [MINOR][DOCS] Clarify sort behaviour for structs
URL: https://github.com/apache/spark/pull/43871


-- 
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


Re: [PR] [MINOR][DOCS] Clarify sort behaviour for structs [spark]

Posted by "landlord-matt (via GitHub)" <gi...@apache.org>.
landlord-matt commented on PR #43871:
URL: https://github.com/apache/spark/pull/43871#issuecomment-1820696947

   Another alternative would be instead of writing it for this function, we could add something on this documentation page. I don't it is open source though https://spark.apache.org/docs/latest/sql-ref-datatypes.html


-- 
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


Re: [PR] [MINOR][DOCS] Clarify sort behaviour for structs [spark]

Posted by "JoshRosen (via GitHub)" <gi...@apache.org>.
JoshRosen commented on PR #43871:
URL: https://github.com/apache/spark/pull/43871#issuecomment-1821456888

   > I don't think this documentation is open source though, so I can't submit a proposal.
   
   The Spark website's source code can be found at https://github.com/apache/spark-website


-- 
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


Re: [PR] [MINOR][DOCS] Clarify sort behaviour for structs [spark]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #43871:
URL: https://github.com/apache/spark/pull/43871#issuecomment-1974952321

   We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
   If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!


-- 
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