Skip to content
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

feat: Add case insensitive like operator #2368

Conversation

fredcarle
Copy link
Collaborator

Relevant issue(s)

Resolves #2367

Description

This PR adds support for case insensitive like and not-like operators. This was requested by a partner.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

make test

Specify the platform(s) on which this was tested:

  • MacOS

@fredcarle fredcarle added the feature New feature or request label Mar 4, 2024
@fredcarle fredcarle added this to the DefraDB v0.10 milestone Mar 4, 2024
@fredcarle fredcarle requested a review from a team March 4, 2024 17:31
@fredcarle fredcarle self-assigned this Mar 4, 2024
@fredcarle fredcarle force-pushed the fredcarle/feat/i2367-case-insensitive-like branch from c46458d to e9986f3 Compare March 4, 2024 17:33
Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 70.45455% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 75.02%. Comparing base (eb872f5) to head (e9986f3).
Report is 2 commits behind head on develop.

❗ Current head e9986f3 differs from pull request most recent head a0d906a. Consider uploading reports for the commit a0d906a to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2368      +/-   ##
===========================================
- Coverage    75.03%   75.02%   -0.01%     
===========================================
  Files          266      268       +2     
  Lines        25855    25889      +34     
===========================================
+ Hits         19400    19423      +23     
- Misses        5150     5160      +10     
- Partials      1305     1306       +1     
Flag Coverage Δ
all-tests 75.02% <70.45%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
connor/connor.go 100.00% <100.00%> (ø)
db/fetcher/indexer_iterators.go 79.74% <100.00%> (+0.40%) ⬆️
connor/like.go 84.09% <33.33%> (ø)
connor/nilike.go 50.00% <50.00%> (ø)
connor/ilike.go 46.67% <46.67%> (ø)

... and 10 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3963bf4...a0d906a. Read the comment docs.

Copy link
Member

@nasdf nasdf left a comment

Choose a reason for hiding this comment

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

Looks good! This is a nice usability feature.

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

LGTM

thought(out-of-scope): _nilike seems odd reading it, what if we prepend all negated labels with _n_ so for example we would have _n_eq, _n_in, _n_ilike

@@ -40,6 +40,10 @@ func matchWith(op string, conditions, data any) (bool, error) {
return like(conditions, data)
case "_nlike":
return nlike(conditions, data)
case "_ilike":
return ilike(conditions, data)
case "_nilike":
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moving this here to keep under a thread:
From @shahzadlone

thought(out-of-scope): _nilike seems odd reading it, what if we prepend all negated labels with n so for example we would have _n_eq, _n_in, _n_ilike

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can see if others feel the same way but in my opinion, _n_... make every negated labels ugly 😅 while _nilike makes only this one ugly. But I'm open to the idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do prefer _nilike over _n_ilike at first glance.

Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to add a logical not operator to connor? Then we could remove the _n variants.

Copy link
Member

Choose a reason for hiding this comment

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

It's just that the first three chars read _nil... haha

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would it be possible to add a logical not operator to connor? Then we could remove the _n variants.

Maybe like this?

switch op {
	case "_and":
		return and(conditions, data)
	case "_eq":
		return eq(conditions, data)
	case "_ge":
		return ge(conditions, data)
	case "_gt":
		return gt(conditions, data)
	case "_in":
		return in(conditions, data)
	case "_le":
		return le(conditions, data)
	case "_lt":
		return lt(conditions, data)
	case "_ne": // -> "_!eq"
		return ne(conditions, data)
	case "_nin": // -> "_!in"
		return nin(conditions, data)
	case "_or":
		return or(conditions, data)
	case "_like":
		return like(conditions, data)
	case "_nlike": // -> "_!like"
		return nlike(conditions, data)
        case "_ilike":
		return ilike(conditions, data)
	case "_nilike": // -> "_!ilike"
		return nilike(conditions, data)
	case "_not":
		return not(conditions, data)
	default:
		return false, NewErrUnknownOperator(op)
	}

Copy link
Member

Choose a reason for hiding this comment

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

Instead of _nilike: "test" it could be _not: { _ilike: "test" }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instead of _nilike: "test" it could be _not: { _ilike: "test" }

This can already be done. _nilike is available for convenience.

@fredcarle fredcarle force-pushed the fredcarle/feat/i2367-case-insensitive-like branch from e9986f3 to a0d906a Compare March 5, 2024 21:28
@fredcarle fredcarle merged commit b45ad88 into sourcenetwork:develop Mar 5, 2024
27 of 28 checks passed
@fredcarle fredcarle deleted the fredcarle/feat/i2367-case-insensitive-like branch March 5, 2024 21:42
@islamaliev
Copy link
Contributor

bug bash result: ran different queries with _like, _nlike, _ilike and _nilike filters. Everything works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add case insensitive like operator
5 participants