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

fix: Add check to filter result for logical ops #2573

Conversation

fredcarle
Copy link
Collaborator

@fredcarle fredcarle commented May 1, 2024

Relevant issue(s)

Resolves #2571

Description

This PR adds a check post doc filtering in the fetcher to see if we need to rely on the external conditions instead to ensure a valid filtering operation. This is specially important when filtering with logical operators _and and _or.

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 bug Something isn't working label May 1, 2024
@fredcarle fredcarle added this to the DefraDB v0.11 milestone May 1, 2024
@fredcarle fredcarle requested a review from a team May 1, 2024 17:49
@fredcarle fredcarle self-assigned this May 1, 2024
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Fred!

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.

LGTM. One minor suggestion.

@@ -32,6 +32,7 @@ func isComplex(conditions any, seekRelation bool) bool {
for k, v := range typedCond {
if op, ok := k.(*mapper.Operator); ok {
if (op.Operation == request.FilterOpOr && len(v.([]any)) > 1) ||
Copy link
Member

@nasdf nasdf May 1, 2024

Choose a reason for hiding this comment

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

suggestion: I think this can be simplified a bit and avoid the potential panic from type casting.

switch op.Operation {
  case request.FilterOpOr, request.FilterOpAnd, request.FilterOpNot:
    if isComplex(v, true) {
      return true
    }
    continue
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

v can't be anything other than an []any if it's an _or or _and operator and we don't want to classify them as complex if there is only one element in the array.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this changes the logic though. It just adds another recursive step.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

made a change in line with what you suggested. Let me know what you think.

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

@fredcarle fredcarle merged commit 4248007 into sourcenetwork:develop May 1, 2024
27 of 28 checks passed
@fredcarle fredcarle deleted the fredcarle/fix/i2571-logical-op-with-foreign-object branch May 1, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Foreign object filter part of an _or set of filters doesn't seem to do anything
4 participants