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 is empty, is not empty, starts with, ends with filters operators #801

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ChibiBlasphem
Copy link
Contributor

@ChibiBlasphem ChibiBlasphem commented Jan 16, 2025

@ChibiBlasphem ChibiBlasphem requested a review from a team January 16, 2025 12:06
Copy link
Contributor

@Pascal-Delange Pascal-Delange left a comment

Choose a reason for hiding this comment

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

👍 give me a small moment to review the impact on index creation logic of aggregates, tomorrow morning (otherwise LGTM)

@@ -25,6 +25,10 @@ var validTypeForFilterOperators = map[ast.FilterOperator][]models.DataType{
ast.FILTER_LESSER_OR_EQUAL: {models.Int, models.Float, models.String, models.Timestamp},
ast.FILTER_IS_IN_LIST: {models.String},
ast.FILTER_IS_NOT_IN_LIST: {models.String},
ast.FILTER_IS_EMPTY: {models.Int, models.Float, models.String, models.Timestamp},
Copy link
Contributor

Choose a reason for hiding this comment

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

just for the sake of completeness: could also work with bool type

@@ -12,6 +12,12 @@ import (
"github.com/checkmarble/marble-backend/models/ast"
)

// Define where to put that
type FilterWithType struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to put it into models (most generally) or optionally in the usecase where you are using it (if it's really a local type that you'll use just there)

Copy link
Contributor

Choose a reason for hiding this comment

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

=> in this case, into models since you use it in the usecase and the repo

}
return query.Where(orCondition), nil
case ast.FILTER_IS_NOT_EMPTY:
andCondition := squirrel.And{
Copy link
Contributor

Choose a reason for hiding this comment

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

you can reduce code a little bit by avoiding the squirrel.And and just adding to the squirrel.NotEq conditionally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That may be a stupid question, but I don't know how I can add the second NotEq conditionally on the first one.

Copy link
Contributor

Choose a reason for hiding this comment

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

squirrel.And is just an alias wrapper over a go map[string]any, so just by setting the value in the map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I read the code squirrel.And is an alias for []Sqlizer, so I don't know how to add both NotEq without it. Can you suggest me some code for me to see what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry, I didn't write what I meant to write. I meant to say that squirrel.(Not)Eq is a wrapper over a map.
So you could do

notEq := squirrel.NotEq{fmt.Sprintf("%s.%s", tableName, fieldName): nil}
if fieldType == models.String {
    notEq[fmt.Sprintf("%s.%s", tableName, fieldName)] = ""
}
return query.Where(notEq), nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh but won't the second one replace the first? The key being the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok you are right 🤦 sorry for misleading you

@Pascal-Delange
Copy link
Contributor

Btw, I understand "unary" from the context of the "main" ast, still feels like "unary" is not the exact word here but I don't have a better one TBH

@Pascal-Delange
Copy link
Contributor

@ChibiBlasphem I think the thing that remains to do, would be to add the filter operators you created in file usecases/indexes/aggregate_query.go, line 141 (along ast.FILTER_IS_IN_LIST, ast.FILTER_IS_NOT_IN_LIST, ast.FILTER_NOT_EQUAL)
Just this should do the job

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