ic4y opened a new pull request, #6783: URL: https://github.com/apache/kyuubi/pull/6783
# :mag: Description ## Issue References ๐ <!-- Append the issue number after #. If there is no issue for you to link create one or --> <!-- If there are no issues to link, please provide details here. --> First, I'd like to thank @wForget for the help with this issue. When using the "save to HDFS" feature, queries ending with an `ORDER BY` sometimes lose their sort order in the results. Upon investigating the code, I discovered that when using `WITH` statements and saving SQL results with `toDF.write.save`, a `WithCTE` node is generated after the Sort node. This causes the `canInsertRepartitionByExpression` check to fail, leading to an incorrect `Repartition` node insertion after the Sort node, which ultimately disrupts the sort order. However, this issue does not occur when using `INSERT INTO TABLE` with `WithCTE` nodes. The provided unit test can reproduce this issue, but after using `toDF.write.save`, I am unable to access the complete execution plan to assert whether a `Repartition` node is present. Therefore, the current test is ineffective. Hope someone can help figure out how to write this unit test. ## Describe Your Solution ๐ง Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. ## Types of changes :bookmark: <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan ๐งช #### Behavior Without This Pull Request :coffin: #### Behavior With This Pull Request :tada: #### Related Unit Tests --- # Checklist ๐ <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** -- 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: notifications-unsubscr...@kyuubi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@kyuubi.apache.org For additional commands, e-mail: notifications-h...@kyuubi.apache.org