-
Notifications
You must be signed in to change notification settings - Fork 16
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
$not
operator
#760
$not
operator
#760
Conversation
...n/java/io/stargate/sgv2/jsonapi/api/model/command/clause/filter/ArrayComparisonOperator.java
Show resolved
Hide resolved
return new JsonLiteral<Boolean>(!((Boolean) operand.value()), operand.type()); | ||
} else if (operator == ArrayComparisonOperator.SIZE) { | ||
return new JsonLiteral<BigDecimal>( | ||
((BigDecimal) operand.value()).multiply(new BigDecimal(-1)), operand.type()); |
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.
If this is done to flip between 1 and -1, more efficient way would be to use BigDecimal.negate()
(https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#negate-- )
But I guess I am not sure what the logic here really is? Negative values can't match anything, I guess that is the idea?
EDIT: this ^^^ makes sense when at later point negative value is converted to "$size NOT equals X"
src/main/java/io/stargate/sgv2/jsonapi/api/model/command/clause/filter/LogicalExpression.java
Show resolved
Hide resolved
...in/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterableResolver.java
Show resolved
Hide resolved
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.
LGTM: added some questions, but nothing blocking merge.
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.
LGTM
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'm curious about why $not
is an array. In MongoDB, $not is an object like the following:
find({
num: {
$not: {
$lt: 42
}
}
}); // Equivalent to `find({ num: { $gte: 42 } })`
Is there a reason for making $not an array?
I made it in line with |
Hmmmh. Good point, thank you for pointing it out. It is interesting Mongo has this discrepancy: Earlier we wanted to be highly Mongo-compatible, and I would have suggested we follow its lead. I think we need to discuss this on our daily meeting @maheshrajamani see what Aaron thinks. |
Based on discussion with @amorton, I think the preferred option is to use JSON Object, same as how Mongo behaves. |
Another reason why we should make 'use strict';
const mongoose = require('mongoose');
mongoose.set('debug', true);
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_test');
const schema = new mongoose.Schema({ age: Number });
const Test = mongoose.model('Test', schema);
await Test.find({ age: { $not: [{ $gt: 42 }] } });
console.log('Done');
} However, |
@vkarpov15 @tatu-at-datastax Have made the |
} | ||
|
||
@Test | ||
public void multipleNotCancelling() { |
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.
Nice, I'm glad you tested this. I checked whether multiple $not
works in MongoDB and Mongoose: MongoDB supports it, but Mongoose doesn't. Something for Mongoose to fix.
What this PR does:
Which issue(s) this PR fixes:
Fixes #
Checklist