Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-31492

N1QL: SUM is incorrectly rounding my scotch eggs

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not a Bug
    • Major
    • feature-backlog
    • 5.5.2
    • query
    • None
    • Untriaged
    • Unknown

    Description

      I was running the Couchmart Demo on 5.5.2 I have a simple data set where every product has a price recorded to 2 decimal places, see sample doc below. I put the keys of 5 such documents in a shopping basket and run a query to sum the price of this basket. The price occasionally comes back with an incorrectly rounded total (see below). I have attached a backup of the complete (small) dataset.

      Sample Product Document:

      {
        "category": "british",
        "product": "scotch egg",
        "name": "scotch egg",
        "productList": {
          "owner": "david",
          "id": "david.all_the_products"
        },
        "price": 0.36,
        "description": "Perfect for picnics - a boiled egg, shrouded in meat and breadcrumbs",
        "complete": false,
        "type": "product",
        "image": "scotch_egg.png",
        "createdAt": 12022,
        "stock": 100
      }
      

      SUM query:

      SELECT b.name name, SUM(a.price) price, b.`order` basket FROM couchmart b 
      JOIN couchmart a ON KEYS b.`order`
      WHERE b.type="order"
      GROUP BY meta(b).id,b.name,b.`order`
      ORDER BY price DESC
      LIMIT 10
      

      Result with incorrect rounding:

            {
                  "basket": [
                      "product:milk",
                      "product:scotch egg",
                      "product:cheese",
                      "product:sausages",
                      "product:eggs"
                  ],
                  "name": "David",
                  "price": 9.600000000000001
              }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Donald.haggart Donald Haggart
              dhaikney David Haikney (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty