GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `-Stable` to `Sort-Object` and related tests by KirkMunro · Pull Request #7862 · PowerShell/PowerShell

Conversation

@KirkMunro

@KirkMunro Kirk Munro (KirkMunro) commented Sep 26, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR Summary

Fix #7846.

  • added -Stable switch parameter to Sort-Object
  • moved -Top parameter from Default parameter set to Top parameter set and made it mandatory for that parameter set
  • added new Pester tests for -Stable switch (ascending, descending, with/without unique)

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

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.
  • User-facing changes
    • Not Applicable
    • OR
    • User-facing Documentation needed
      • Issue filed - Issue link: Document -Stable parameter for Sort-Object MicrosoftDocs/PowerShell-Docs#3246
  • Testing - New and feature
    • Not Applicable or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
      • Add [feature] if the change is significant or affects feature tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@KirkMunro
added -Stable sort and tests (PowerShell#7846)
73ba2f0
@KirkMunro
Kirk Munro (KirkMunro) requested review from James Truher (JamesWTruher) and Paul Higinbotham (PaulHigin) as code owners September 26, 2018 01:19
@iSazonov Ilya (iSazonov) added Review - Committee The PR/Issue needs a review from the PowerShell Committee Breaking-Change breaking change that may affect users labels Sep 26, 2018
iSazonov
Ilya (iSazonov) reviewed Sep 26, 2018
View reviewed changes

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look CodeFactor issues.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Utility/Sort-Object.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Sep 26, 2018

Copy link
Copy Markdown
Contributor Author

Ilya (@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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
updated for StyleCop; code review changes
131aa16
@iSazonov

Ilya (iSazonov) commented Sep 26, 2018

Copy link
Copy Markdown
Collaborator

Kirk Munro (@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Sep 26, 2018

Copy link
Copy Markdown
Collaborator

Kirk Munro (@KirkMunro) Please update Markdig.Signed package version 0.15.2 -> 0.15.3 to pass CI tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
updated nuget packages
9941e1e
@KirkMunro
Kirk Munro (KirkMunro) requested review from Travis Plunk (TravisEz13), Aditya Patwardhan (adityapatwardhan), Andrew (anmenaga) and Dongbo Wang (daxian-dbw) as code owners September 26, 2018 15:17
@KirkMunro

Kirk Munro (KirkMunro) commented Sep 26, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Ilya (@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Sep 27, 2018

Copy link
Copy Markdown
Collaborator

Kirk Munro (@KirkMunro) Thanks for clarify. Please update the PR description about the "breaking" change.

Now we are waiting PowerShell Committee conclusion.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TravisEz13 Travis Plunk (TravisEz13) added the Documentation Needed in this repo Documentation is needed in this repo label Oct 1, 2018
@joeyaiello Joey Aiello (joeyaiello) mentioned this pull request Oct 15, 2018
Docs needed for 'added -Stable sort and tests (#7846)' MicrosoftDocs/PowerShell-Docs#3021
Closed
@joeyaiello Joey Aiello (joeyaiello) removed Documentation Needed in this repo Documentation is needed in this repo labels Oct 15, 2018
@anmenaga Andrew (anmenaga) assigned Aditya Patwardhan (adityapatwardhan) Oct 23, 2018
@anmenaga

Andrew (anmenaga) commented Oct 23, 2018

Copy link
Copy Markdown

Steve Lee (@SteveL-MSFT) we need to make sure this breaking change gets reviewed by PS Committee...
Review - Committee label was added almost a month ago.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Oct 27, 2018

Copy link
Copy Markdown
Member

Andrew (@anmenaga) yes, this is in the queue for review but we have so many items now it's taking a bit longer

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 1, 2018

Copy link
Copy Markdown
Collaborator

Kirk Munro (@KirkMunro) Please resolve merge conflicts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
Merge branch 'master' into sort-stable
2260eb0
PaulHigin
Paul Higinbotham (PaulHigin) suggested changes Nov 5, 2018
View reviewed changes
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro Kirk Munro (KirkMunro) mentioned this pull request Nov 5, 2018
Document -Stable parameter for Sort-Object MicrosoftDocs/PowerShell-Docs#3246
Closed
2 of 8 tasks
Kirk Munro (KirkMunro) added 2 commits November 5, 2018 13:55
@KirkMunro
code review changes
7536ae8
@KirkMunro
Merge branch 'sort-stable' of https://github.com/KirkMunro/PowerShell …
55da8b2
…into sort-stable
@TravisEz13 Travis Plunk (TravisEz13) changed the title added -Stable sort and tests (#7846) Add -Stable sort and tests (#7846) Nov 5, 2018
adityapatwardhan
Aditya Patwardhan (adityapatwardhan) approved these changes Nov 9, 2018
View reviewed changes
@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Nov 9, 2018

Copy link
Copy Markdown
Member

Change looks good, awaiting review from committee.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sdwheeler

Sean Wheeler (sdwheeler) commented Nov 27, 2018

Copy link
Copy Markdown
Contributor

Docs issue MicrosoftDocs/PowerShell-Docs#3021

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anmenaga

Andrew (anmenaga) commented Nov 28, 2018

Copy link
Copy Markdown

Bruce Payette (@BrucePay) friendly ping. This PR needs your review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BrucePay

Bruce Payette (BrucePay) commented Nov 29, 2018

Copy link
Copy Markdown
Collaborator

Kirk Munro (@KirkMunro) Andrew (@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 29, 2018

Copy link
Copy Markdown
Collaborator

There has been a significant performance increase in # 2518 + support Top/Bottom.
There is open issues in CoreFX for new API that can replace the code.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Nov 29, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Bruce Payette (@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 Ilya (@iSazonov) just mentioned (Ilya, can you provide a link to that please?).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BrucePay
Bruce Payette (BrucePay) approved these changes Nov 29, 2018
View reviewed changes

@BrucePay Bruce Payette (BrucePay) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/sort-object.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
Fixed typo that Bruce pointed out
63d66bb
@iSazonov

Ilya (iSazonov) commented Nov 30, 2018

Copy link
Copy Markdown
Collaborator

Waiting PowerShell Committee review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Dec 5, 2018

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee approves of the changes

IISResetMe reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Dec 5, 2018
@TravisEz13 Travis Plunk (TravisEz13) added the CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log label Dec 7, 2018
@stale

stale Bot commented Jan 7, 2019

Copy link
Copy Markdown

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.
Thank you for your contributions.
Community members are welcome to grab these works.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stale stale Bot added the Stale label Jan 7, 2019
@sdwheeler

Sean Wheeler (sdwheeler) commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

Steve Lee (@SteveL-MSFT) What's the status on this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stale stale Bot removed the Stale label Jan 7, 2019
@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Jan 8, 2019

Copy link
Copy Markdown
Member

Kirk Munro (@KirkMunro) Can you resolve the merge conflict?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Jan 8, 2019

Copy link
Copy Markdown
Member

Sean Wheeler (@sdwheeler) Kirk Munro (@KirkMunro) I believe the changes are approved by committee and individuals, so once the merge conflict is resolved this can be merged

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adityapatwardhan
Merge branch 'master' into sort-stable
1c1b1fb
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) changed the title Add -Stable sort and tests (#7846) Add -Stable sort and tests Jan 16, 2019
@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Jan 16, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Kirk Munro (@KirkMunro) Fixed the merge conflict.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) changed the title Add -Stable sort and tests Add -Stable to Sort-Object and related tests Jan 16, 2019
@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit 41d9667 into PowerShell:master Jan 16, 2019
@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Jan 16, 2019

Copy link
Copy Markdown
Member

Kirk Munro (@KirkMunro) Thank you for your contribution!

iSazonov reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
Kirk Munro (KirkMunro) deleted the sort-stable branch January 16, 2019 17:48
@KirkMunro

Kirk Munro (KirkMunro) commented Jan 16, 2019

Copy link
Copy Markdown
Contributor Author

Thanks Aditya Patwardhan (@adityapatwardhan), for fixing the merge conflict and merging the PR. I missed the earlier comments about the merge conflict.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@KirkMunro @adityapatwardhan
Add -Stable to Sort-Object and related tests (PowerShell#7862)
47699a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov left review comments
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) adityapatwardhan approved these changes
@JamesWTruher James Truher (JamesWTruher) Awaiting requested review from JamesWTruher
@anmenaga Andrew (anmenaga) Awaiting requested review from anmenaga
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw
@TravisEz13 Travis Plunk (TravisEz13) Awaiting requested review from TravisEz13
+2 more reviewers
@BrucePay Bruce Payette (BrucePay) BrucePay approved these changes
@PaulHigin Paul Higinbotham (PaulHigin) PaulHigin approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adityapatwardhan Aditya Patwardhan (adityapatwardhan)

Labels

Breaking-Change breaking change that may affect users CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Sort-Object inappropriately sacrifices stability for performance

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@KirkMunro @iSazonov @anmenaga @SteveL-MSFT @adityapatwardhan @sdwheeler @BrucePay @PaulHigin @joeyaiello @TravisEz13
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.