Skip to content

filters: add comparison operators#307

Open
Omkar-Ugal wants to merge 2 commits into
unikraft-cloud:prod-stagingfrom
Omkar-Ugal:feat/filter-comparison
Open

filters: add comparison operators#307
Omkar-Ugal wants to merge 2 commits into
unikraft-cloud:prod-stagingfrom
Omkar-Ugal:feat/filter-comparison

Conversation

@Omkar-Ugal

Copy link
Copy Markdown

Summary

  • Add support for >, <, >=, and <= operators
  • Implement numeric and size comparisons

Signed-off-by: Omkar Ugalmugle <omkarugalmugle285@gmail.com>
Comment thread filters/compare.go Outdated
return false, fmt.Errorf("cannot compare %q and %q", lhs, rhs)
}

func parseSize(s string) (float64, error) {

@jedevc jedevc Jun 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't love that this package needs to include these helpers - ideally, downstream, in the cli, we'd be able to define custom handlers for comparison.

Here's my idea for that - let me know if this seems reasonable:

  • Update the Adaptor, so that it includes a Compare(any) function (returns -1 for less-than, 0 for equal, and +1 for larger than, similar to cmp.Compare. It should also return a boolean, which should be false if the comparison was invalid, e.g. you can't do running>stopped).
    • While you're there, maybe actually change Value to return any. But keep a String method, since we should use that for regexp comparisons.
  • Then, in selector.Match, use the Adaptor.Compare to compare against the value for all normal comparisons. If the comparison is invalid, it doesn't match. If it turns out that the equal comparison is invalid - then just callback to comparing Adaptor.String. You should also fallback Compare < and > comparisons of int/float/etc by using cmp.Compare directly.
  • Finally, in the cli, is the place to actually put the custom comparators for sizes + dates + such. Probably into the custom internal/types package.

Because of this, it's a bit more complicated, but means that the actual comparisons are correctly implemented in the CLI. I want to avoid CLI-specific abstractions and helpers from leaking into this more generic package.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hey @jedevc, just wanted to make sure I'm on the right track.

From your review, my understanding is that selector.Match should call Adaptor.Compare, and this package shouldn't contain helpers like parseSize anymore.

The only thing I'm unsure about is Compare(any). Since the parser passes comparison values as strings (like "50"), should Adaptor.Compare handle parsing them before comparing, or were you thinking of a different approach?

Just wanted to check before I continue.

@Omkar-Ugal Omkar-Ugal requested a review from jedevc July 5, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants