[JAVA-4583] Stop using null values in the Scala query building API for $setWindowFields Created: 20/Apr/22  Updated: 17/May/22  Resolved: 17/May/22

Status: Closed
Project: Java Driver
Component/s: Builders
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Improvement Priority: Unknown
Reporter: Valentin Kavalenka Assignee: Valentin Kavalenka
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
Gantt Dependency
Backwards Compatibility: Minor Change
Documentation Changes: Needed
Documentation Changes Summary:

We need to update examples in https://mongodb.github.io/mongo-java-driver/4.6/driver-scala/builders/aggregation/#setwindowfields such that they wrap references in `Some` where needed:

val pastMonth: Window = Windows.timeRange(-1, MongoTimeUnit.MONTH, Windows.Bound.CURRENT)
setWindowFields(Some("$localityId"), Some(Sorts.ascending("measurementDateTime")),
WindowedComputations.sum("monthlyRainfall", "$rainfall", Some(pastMonth)),
WindowedComputations.avg("monthlyAvgTemp", "$temperature", Some(pastMonth)))

P.S. Note also that the order of arguments passed to the `timeRange` differs from that in the currently published example. This is because the order in the currently published example is incorrect.


 Description   

While this API is still marked as @Beta, we have a chance to change the docs and maybe the wrappers such that the API can be used without passing null values, as using them is discouraged in Scala 2 (and here is something about null s in Scala 3).

The API was added in this commit, and uses null in the following program elements:

  • Aggregates.setWindowFields
  • WindowedComputations and many of its methods

Also, the test "render $setWindowFields with no partitionBy/sortBy" passes null s when uses the API.

We should start accepting scala.Option for null-able parameters.



 Comments   
Comment by Githook User [ 17/May/22 ]

Author:

{'name': 'Valentin Kovalenko', 'email': 'valentin.kovalenko@mongodb.com', 'username': 'stIncMale'}

Message: Stop using `null` values in the Scala query building API for `$setWindowFields` (#937)

JAVA-4583
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/4a6f2c0fb13cfc9c707e0bd3e82ad190d242edca

Generated at Thu Feb 08 09:02:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.