Skip to content

[SFS-1439] Implement custom sort for Unstructured #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 18, 2024

Conversation

biancasilvavtex
Copy link
Contributor

@biancasilvavtex biancasilvavtex commented Sep 9, 2024

Description

Within this PR, we're extending the CEL functions to include a way to sort lists. The new sort_by function can be used in the following way:

[3,1,2].sort_by(i, i) // returns [1,2,3]

[{Name: "c", Age: 10}, {Name: "a", Age: 30}, {Name: "b", Age: 1}].sort_by(obj, obj.age) // returns [{Name: "b", Age: 1}, {Name: "c", Age: 10}, {Name: "a", Age: 30}]

It supports all CEL types that implement the Comparer interface.

Additionally, we also include the Lists() capabilities from K8s extensions. So now we can use something like this:

[1,2,3,4].indexOf(2) // returns 1

What was done

  • Create a package named custom_cel specific for the code related to CEL
  • Implement the the logic responsible for sorting lists
  • Implement tests for the new code
  • Add Go docs for the new code
  • Make k8s.io/apiserver a required dependency instead of indirect

Documentation

@biancasilvavtex biancasilvavtex self-assigned this Sep 9, 2024
@biancasilvavtex biancasilvavtex force-pushed the SFS-1439/sort-unstructured branch from c442160 to 073ac4d Compare September 10, 2024 12:40
@biancasilvavtex biancasilvavtex marked this pull request as ready for review September 10, 2024 12:48
@biancasilvavtex biancasilvavtex added documentation Improvements or additions to documentation enhancement New feature or request labels Sep 10, 2024
@biancasilvavtex biancasilvavtex force-pushed the SFS-1439/sort-unstructured branch 2 times, most recently from b63bf06 to ffe9017 Compare September 13, 2024 00:41
@biancasilvavtex biancasilvavtex force-pushed the SFS-1439/sort-unstructured branch from ffe9017 to cd4cc7f Compare September 13, 2024 00:43
Copy link
Contributor

@cezar-guimaraes cezar-guimaraes left a comment

Choose a reason for hiding this comment

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

Great work @biancasilvavtex !
I'm approving the PR but there is one last change I requested to use slices.Reverse instead of implementing the reverse algorithm.

Co-authored-by: cezar-guimaraes <85624018+cezar-guimaraes@users.noreply.github.com>
@biancasilvavtex biancasilvavtex force-pushed the SFS-1439/sort-unstructured branch from 82ef782 to 6c07acd Compare September 13, 2024 12:48
Copy link

@cezar-guimaraes cezar-guimaraes merged commit 3ce4645 into main Sep 18, 2024
2 checks passed
@cezar-guimaraes cezar-guimaraes deleted the SFS-1439/sort-unstructured branch September 18, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants