Add -Stable to Sort-Object and related tests#7862
Add -Stable to Sort-Object and related tests#7862adityapatwardhan merged 8 commits intoPowerShell:masterfrom
-Stable to Sort-Object and related tests#7862Conversation
iSazonov
left a comment
There was a problem hiding this comment.
Please look CodeFactor issues.
src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1
Show resolved
Hide resolved
|
@iSazonov Why did you add the Breaking-Change label? Because the Top parameter was moved to a separate parameter set (which would invalidate code someone had written specifically against the Default parameter set if they expected Top to be in there)? Or is there a functional breaking change you see here that I don't? |
|
@KirkMunro Formally it is a breaking change because (1) a parameter set is changed, (2) sort order is changed and some scripts can fail. I believe we should inform users in change log about this. Also we need PowerShell Committee approvement. |
|
@KirkMunro Please update Markdig.Signed package version 0.15.2 -> 0.15.3 to pass CI tests. |
|
@iSazonov I updated the 3 packages that had updates available. On the breaking change comments, where you say "sort order is changed and some scripts may fail", the sort order has not changed with this PR. A new option has been added to allow users to choose a stable sort, where the order of duplicate items is preserved through the sort. That addition should not have any impact whatsoever over the sort order of existing sorts, because you only get that functionality by adding the new -Stable switch. For yourself and other readers, the reason this was done is because Top/Bottom sorts are implicitly stable, so there is no need to have a -Stable switch on those parameter sets. The behavior of the default parameter set has not changed either. The only "breaking" change is if you use -Top, you're invoking a different parameter set, that's all. The only people who might run into that as a breaking change are teams building tooling around PowerShell where they explicitly look for a Top parameter in the Default parameter set, if any such teams exist. Anyhow, I agree with the committee review to decide if change log details are necessary for this. |
|
@KirkMunro Thanks for clarify. Please update the PR description about the "breaking" change. Now we are waiting PowerShell Committee conclusion. |
|
@SteveL-MSFT we need to make sure this breaking change gets reviewed by PS Committee... |
|
@anmenaga yes, this is in the queue for review but we have so many items now it's taking a bit longer |
|
@KirkMunro Please resolve merge conflicts. |
src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs
Outdated
Show resolved
Hide resolved
|
@BrucePay I believe you had an action item to review this PR on behalf of the @PowerShell/powershell-committee |
-Stable sort and tests (#7846)
|
Change looks good, awaiting review from committee. |
|
Docs issue MicrosoftDocs/PowerShell-Docs#3021 |
|
@BrucePay friendly ping. This PR needs your review. |
|
@KirkMunro @anmenaga My main question is this: do we really need a custom implementation of a heap sort? LINQ OrderBy and OrderByDescrnding are stable sorts. Why not just use them? It would be a lot less code to maintain. |
|
There has been a significant performance increase in # 2518 + support Top/Bottom. |
|
@BrucePay That question has nothing to do with this PR. This PR is to correct issue #7846, while also allowing full stable sorts using the same algorithm. The sorting algorithm isn't new here. It was added for PowerShell 6.0 in PR #2518 to greatly improve Sort-Object performance issues while adding -Top and -Bottom to Sort-Object. To get the answer to your question, I think it would be better to open another issue requesting a comparison between LINQ's OrderBy and OrderByDescending and the existing indexed min-/max-heap sort algorithm, which should include an in depth analysis of results to ensure sorting does not change as well as a thorough performance analysis. Either that or compare with the CoreFX issue that @iSazonov just mentioned (Ilya, can you provide a link to that please?). |
BrucePay
left a comment
There was a problem hiding this comment.
Hmm - sorry - I clicked the link from the issue and started looking at the wrong PR. Given that the code I'm concerned about has already been committed I agree that a separate issue is the right way to approach it. Other than that, you might consider checking PSBoundParameters to see if the top/bottom/stable parameters have been specified instead of depending on signal values but I'll leave that up to you. (Sooner or later someone is probably going to suggest using sort -Top -10 to get all but the top ten :-) ) . Anyway I approve these changes.
src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs
Outdated
Show resolved
Hide resolved
|
Waiting PowerShell Committee review. |
|
@PowerShell/powershell-committee approves of the changes |
|
This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. |
|
@SteveL-MSFT What's the status on this PR? |
|
@KirkMunro Can you resolve the merge conflict? |
|
@sdwheeler @KirkMunro I believe the changes are approved by committee and individuals, so once the merge conflict is resolved this can be merged |
-Stable sort and tests (#7846)-Stable sort and tests
|
@KirkMunro Fixed the merge conflict. |
-Stable sort and tests-Stable to Sort-Object and related tests
|
@KirkMunro Thank you for your contribution! |
|
Thanks @adityapatwardhan, for fixing the merge conflict and merging the PR. I missed the earlier comments about the merge conflict. |
PR Summary
Fix #7846.
Regarding the breaking change, this is clearly in Bucket 3 (technically it is breaking, but it is highly unlikely that anyone will be impacted by this change). For details on how it is breaking, see here.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests