-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implement arithmetic expressions #1037
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
Conversation
driver-core/src/main/com/mongodb/client/model/expressions/NumberExpression.java
Show resolved
Hide resolved
assertExpression(0.5, of(1).divide(2.0)); | ||
// TODO these convenience methods are all for doubles, so while they | ||
// TODO allow longs and ints, they do not carry that through to the server: | ||
assertExpression(0.5, of(1).divide(2L)); |
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 have created convenience methods only for doubles. If it is critical that the underlying structure, a long, is correctly propagated into the server, the user would need to use of
.
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
5093ef5
to
1a776bf
Compare
2544993
to
146a6be
Compare
1a776bf
to
d3a93e0
Compare
|
||
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/ | ||
// sum's alternative behaviour exists for purposes of reduction, but is | ||
// inconsistent with multiply, and potentially confusing. Unimplemented. |
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.
Note above comment
146a6be
to
7058fe5
Compare
driver-core/src/main/com/mongodb/client/model/expressions/IntegerExpression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/MqlExpression.java
Outdated
Show resolved
Hide resolved
...est/functional/com/mongodb/client/model/expressions/ArithmeticExpressionsFunctionalTest.java
Show resolved
Hide resolved
...est/functional/com/mongodb/client/model/expressions/ArithmeticExpressionsFunctionalTest.java
Show resolved
Hide resolved
...est/functional/com/mongodb/client/model/expressions/ArithmeticExpressionsFunctionalTest.java
Outdated
Show resolved
Hide resolved
@@ -21,4 +21,37 @@ | |||
*/ | |||
public interface NumberExpression extends Expression { | |||
|
|||
NumberExpression multiply(NumberExpression n); | |||
|
|||
default NumberExpression multiply(final double multiply) { |
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.
@jyemin raised an issue with double
causing unexpected promotion of underlying BSON type causing a ClassCast during:
long d1 = (long) result.get("d");
long d2 = result.getLong("d");
long d3 = result.get("d", Long.class);
Fixed in:
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 pulled this in to this PR
driver-core/src/main/com/mongodb/client/model/expressions/NumberExpression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Show resolved
Hide resolved
Implement arithmetic expressions (from top 50, and others) JAVA-4803
Implement arithmetic expressions (from top 50, and others) JAVA-4803
* Implement boolean expressions (#1025) JAVA-4779 * Implement filter, map, reduce (#1031) JAVA-4781 * Implement eq, ne, gt, gte, lt, lte (#1033) JAVA-4784 * Implement string expressions (#1036) JAVA-4801 * Implement arithmetic expressions (#1037) Implement arithmetic expressions (from top 50, and others) JAVA-4803 * Implement array expressions (#1043) JAVA-4805 * Implement date expressions (#1045) JAVA-4804 * Implement conversion/type expressions (#1050) JAVA-4802 * Implement document expressions (#1052) JAVA-4782 * Replace reduce with individual reductions (#1053) JAVA-4814 * Implement map expressions (#1054) JAVA-4817 * Implement switch expression (#1055) JAVA-4813 * Test expressions in context (#1057) JAVA-4820 * Add javadoc for boolean, date, number, integer, and expression (#1059) JAVA-4799 * Update and add documentation (#1059) * Fix, tests JAVA-4799 * Add `@MqlUnchecked` and a few usage examples (#1059) JAVA-4799 * Add has to document, add tests (#1070) JAVA-4799 * Add javadocs for remaining classes (#1070) JAVA-4799 * 5.2 annotations (#1070) JAVA-4799 * 5.0 annotations (#1070) JAVA-4799 * 4.4 annotations (#1070) JAVA-4799 * 4.2 annotations (#1070) JAVA-4799 * 4.0 annotations (#1070) JAVA-4799 * Update and add documentation, add tests, fix minor issues (#1070) Rename extractBsonValue Fix access modifiers Remove excess comments Update docs Fix: behaviour of get Add notNull to API, add notNullApi test Fix docs/annotations, tests Fix docs, annotations, since Fix docs Revert external Add missing MqlUnchecked Fix missing null checks Checkstyle JAVA-4799 * Rename to Mql (automated) (#1073) JAVA-3879 * Rename methods (automated) (#1073) JAVA-3879 * Update naming, terms, and missing checks and annotations (#1073) JAVA-3879 --------- Co-authored-by: Valentin Kovalenko <[email protected]>
JAVA-4803
Implements arithmetic expressions from the top 50, and a few others.