-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implement map expressions #1054
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
694c969
to
7b42be1
Compare
3db92db
to
57c5c88
Compare
driver-core/src/main/com/mongodb/client/model/expressions/ArrayExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/MapExpression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/MapExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/EntryExpression.java
Show resolved
Hide resolved
|
||
import static com.mongodb.client.model.expressions.Expressions.of; | ||
|
||
public interface MapExpression<T extends Expression> extends Expression { |
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 don't see a way to generate something like{ $objectToArray: "$instock" }
which is the most common usage of maps that I can think of. Seems like we need either a new method in Expressions
or a way to convert a DocumentExpression
to a MapExpression
.
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.
Right you are - getMap
is missing, and needs to be added. This would be doc.getMap("instock").entrySet()
. Passing test:
DocumentExpression doc = of(Document.parse("{ instock: { warehouse1: 2500, warehouse2: 500 } }"));
assertExpression(
Arrays.asList(
Document.parse("{'k': 'warehouse1', 'v': 2500}"),
Document.parse("{'k': 'warehouse2', 'v': 500}")),
doc.getMap("instock").entrySet(),
"{'$objectToArray': {'$getField': {'input': {'$literal': "
+ "{'instock': {'warehouse1': 2500, 'warehouse2': 500}}}, 'field': 'instock'}}}");
Let's get #1050 and #1052 resolved, and I will be able to merge those and #1053 in, and then rebase to fix this?
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.
Added getMap and isMapOr in aae819e.
Incidentally, the fact that maps are equal to documents introduces an unavoidable way of converting between them (using isMapOr/isDocumentOr).
8e3f9f2
to
b14aea2
Compare
08486b5
to
aae819e
Compare
aae819e
to
d0099cd
Compare
driver-core/src/main/com/mongodb/client/model/expressions/MapExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
...e/src/test/functional/com/mongodb/client/model/expressions/MapExpressionsFunctionalTest.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/ArrayExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/MapExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/MqlExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
.../src/test/functional/com/mongodb/client/model/expressions/TypeExpressionsFunctionalTest.java
Show resolved
Hide resolved
...e/src/test/functional/com/mongodb/client/model/expressions/MapExpressionsFunctionalTest.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/MqlExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/MqlExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/MqlExpression.java
Outdated
Show resolved
Hide resolved
ea32894
to
5cd16db
Compare
Rebased, no conflicts. |
* 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-4817
objectToArray / arrayToObject (which correspond to Java's map.entrySet, and reduce-entries-to-map) require a Map type (as well as an Entry type)