Skip to content

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

Merged
merged 7 commits into from
Nov 29, 2022
Merged

Conversation

katcharov
Copy link
Collaborator

JAVA-4803

Implements arithmetic expressions from the top 50, and a few others.

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));
Copy link
Collaborator Author

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.

@katcharov katcharov force-pushed the expressions-arithmetic branch from 2544993 to 146a6be Compare November 9, 2022 22:08
@rozza rozza removed their request for review November 15, 2022 14:31
Base automatically changed from expressions-string to expressions November 15, 2022 16:44

// 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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note above comment

@katcharov katcharov force-pushed the expressions-arithmetic branch from 146a6be to 7058fe5 Compare November 17, 2022 20:44
@katcharov katcharov requested a review from stIncMale November 18, 2022 19:33
@@ -21,4 +21,37 @@
*/
public interface NumberExpression extends Expression {

NumberExpression multiply(NumberExpression n);

default NumberExpression multiply(final double multiply) {
Copy link
Collaborator Author

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:

https://github.com/mongodb/mongo-java-driver/pull/1052/files#diff-276193793ed4e0294e212d9927de707b2d000804cbf649f2a0d3888e2ec9adf6L26

Copy link
Collaborator Author

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

@katcharov katcharov merged commit 091ce50 into expressions Nov 29, 2022
@katcharov katcharov deleted the expressions-arithmetic branch November 29, 2022 15:31
katcharov added a commit that referenced this pull request Jan 30, 2023
Implement arithmetic expressions (from top 50, and others)

JAVA-4803
katcharov added a commit that referenced this pull request Jan 31, 2023
Implement arithmetic expressions (from top 50, and others)

JAVA-4803
katcharov added a commit that referenced this pull request Jan 31, 2023
* 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]>
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.

3 participants