Support for NOT / NOT IN operator #139
Support for NOT / NOT IN operator #139
Conversation
- added filter attribute for negation - added new negation operator - added test of it
Your PR suggests to solve the problem in two ways, and that seems to me to be one too many. One way is with the |
Correct me, please @kaspersorensen, but NegationOperator is much more general than different from and additing another way to propositional logic of filters. Operator Different from is used just for childs of filters and it's represented with <>. For example SQL NOT keyword has a wider usage. You can negate also composed filters on all levels or different from, too. This functionality I didn't found there and thought that it could be fine. |
Yes but having two ways of doing it means that we can now also have "NOT NOT_IN" (same as IN) and "NOT DIFFERENT_FROM" (same as EQUALS_TO) which to me seems like we've done our design wrong. I agree that ideally we would then just have the negation option, but that train has already left the station since we have negations built in to DIFFERENT_FROM. I also wonder why you would want to introduce NOT_IN if you really think we should be using the negation option instead? |
Alternatively we should deprecate DIFFERENT_FROM and not introduce NOT_IN. That would technically speaking be fine. But my last argument is that from an evolution perspective, it would be worse, because it forces a lot of existing implementations to evaluate a new attribute which was not there before. It would implicitly introduce a ton of bugs because data contexts out there would no longer execute queries correctly. |
I was thinking about it and for a complete option to be able to express all, what propositional logic allows, it should be enough so that we will add NOT IN and NOT LIKE operators. All operators should have a positive and negative form then every conditions can be transfomed to allowed constructions. Do you agree with this solution? |
Yes that sounds correct to me. I think this is much more manageable for existing implementations which typically do something like this:
(the above snippet would still be valid even though other operators are added. If we added the negation option, it would not). |
Prepared by the accepted way. |
return OperatorType.LESS_THAN_OR_EQUAL; | ||
case "LIKE": | ||
return OperatorType.LIKE; | ||
case "NOT_LIKE": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should definately add "NOT LIKE" here also (with space instead of underscore).
@@ -64,6 +64,21 @@ public B in(String... strings) { | |||
} | |||
|
|||
@Override | |||
public B not_in(Collection<?> values) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep using regular java method names here (and below), so notIn
@@ -460,6 +475,15 @@ public B like(String string) { | |||
} | |||
|
|||
@Override | |||
public B not_like(String string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and notLike
here
return OperatorType.LESS_THAN_OR_EQUAL; | ||
case "LIKE": | ||
return OperatorType.LIKE; | ||
case "NOT LIKE": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant to add this, not replace the old, so ...
case "NOT_LIKE":
case "NOT LIKE":
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sorry for all mistakes
Can you see any other weird things or issues, @kaspersorensen ? Thank you. |
LGTM! |
Applied the patch to master. Thank you very much @rposkocil and sorry for the long wait (another time you can bump it if you want to reinvigorate our attention ;-)) |
fixes #METAMODEL-1134
https://issues.apache.org/jira/browse/METAMODEL-1134