Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4583

Stop using null values in the Scala query building API for $setWindowFields

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • 4.7.0
    • Affects Version/s: None
    • Component/s: Builders
    • None
    • Minor Change
    • Needed
    • Hide

      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.

      Show
      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.

      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.

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: