-
Notifications
You must be signed in to change notification settings - Fork 456
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
new implementation of $elemMatch support #985
Conversation
add support for $not with $elemMatch
@@ -142,7 +142,13 @@ public T doesNotHaveThisElement(final Object val) { | |||
@Override | |||
public T hasThisElement(final Object val) { | |||
Assert.parametersNotNull("val", val); | |||
return addCriteria(FilterOperator.ELEMENT_MATCH, val, false); | |||
return addCriteria(FilterOperator.ELEMENT_MATCH, val, not); |
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.
Why did the 3rd param just from false to 'not'? Is this fixing a bug?
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.
It is. It's currently not possible to negate this operation because of that hard coded 'false'
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.
Is that bug reported? If not, it should be so we can track that it's getting fixed. Also, ensure that the bug fix should be done in a separate commit from the new feature work for elemMatch (I didn't check).
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.
Ping on this last comment. Really should avoid drive-by bug fixes like this. Open a separate issue and fix it separately.
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.
I rolled back that fix but hadn't filed the issue. I'll do that now.
@@ -369,37 +391,67 @@ public void testElemMatchQueryCanBeNegated() { | |||
|
|||
Mapper mapper = getMorphia().getMapper(); | |||
|
|||
List<Key<PhotoWithKeywords>> keys = getDs().find(PhotoWithKeywords.class) | |||
validate(pwk1, pwk2, pwk3, pwk4, mapper, getDs().find(PhotoWithKeywords.class) |
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.
validate and validate2 are not testing what the test method says it is: that elemMatch queries can be negated. Only validate3 is doing that. So put the validate/validate2 assertions in a separate test.
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.
those are literally just refactorings of existing tests in to methods so i can use both elemMatch queries with the same asserts. I didn't change what they were testing
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.
Yes, I see that the validate methods are a refactoring. But a bunch more assertions have been added to this test method and I'm suggesting that it would be better to restructure into multiple test methods whose named better describe what it is that is being tested. And once you've done that, the test names you've chosen will suggest what the validate* methods should be renamed to to reflect their purpose.
Let me know if this doesn't make sense and we can talk about it more.
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.
I was trying to avoid cutting too deeply but I bit the bullet and cleaned that up a bit. less code now and easier to reason about what's being asserted.
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.
I like the new validate method... but there are still assertions that have nothing to do with negation in a test method called testElemMatchQueryCanBeNegated. That's just confusing, don't you think?
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.
a bit, yeah. there's only the one negation at the end, really. i'll brainstorm some new names. to be honest, i think this test duplicates a number of others and can probably be combined...
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.
Looks good now.
with the method renamed, all else is good @jyemin ? |
I'd still like to see the bug on the existing method reported and the fix pulled out into a separate commit. |
LGTM |
* use a query for complex hasThisElement clauses? * introduce elemMatch() with better semantics * expand tests to ensure old and new methods are tested. add support for $not with $elemMatch * deprecate `doesNotHaveThisElement` * clean up validations * rename method
Hi @evanchooly
My log had
Is this still a bug |
Probably related #1288 |
This is a replacement implementation of $elemMatch. The old "hasThisElement" and "doesNotHaveThisElement" are being deprecated as they are rather limited in what they support. This resolves #970.