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

[CX] NPE in a complex group-by query

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • CBAS DP3
    • CBAS DP2
    • analytics
    • None
    • Triaged
    • Unknown
    • CX Sprint 45, CX Sprint 46, CX Sprint 47, CX Sprint 48, CX Sprint 49, CX Sprint 50, CX Sprint 51, CX Sprint 64, CX Sprint 65

    Description

      BUCKET: policies

      Using N1QL to insert data:

      {noformat}

      insert into policies (key, value)
      values ("c123",

      {"policyno": "C123",
      "state": "CA",
      "zipcode": "96008",
      "make": "Honda",
      "accidents": [
      { "year": "2015",
      "cost": 5000
      },
      {"year": "2016",
      "cost": 8000
      },
      {"year": "2016",
      "cost": 6000
      }
      ]
      }

      ), values ("c124",

      {"policyno": "C124",
      "state": "CA",
      "zipcode": "96853",
      "make": "Ford",
      "accidents": [
      { "year": "2015",
      "cost": 5000
      },
      {"year": "2015",
      "cost": 8000
      },
      {"year": "2016",
      "cost": 6000
      }
      ]
      }

      ), values ("a123",

      {"policyno": "A123",
      "state": "AZ",
      "zipcode": "86008",
      "make": "Honda",
      "accidents": [
      { "year": "2015",
      "cost": 5000
      },
      {"year": "2016",
      "cost": 8000
      },
      {"year": "2016",
      "cost": 6000
      }
      ]
      }

      ), values ("a124",

      {"policyno": "A124",
      "state": "AZ",
      "zipcode": "86853",
      "make": "Ford",
      "accidents": [
      { "year": "2015",
      "cost": 5000
      },
      {"year": "2016",
      "cost": 8000
      },
      {"year": "2016",
      "cost": 6000
      }
      ]
      }

      ), values ("u123",

      {"policyno": "U123",
      "state": "UT",
      "zipcode": "66008",
      "make": "Honda",
      "accidents": [
      { "year": "2015",
      "cost": 5000
      },
      {"year": "2016",
      "cost": 8000
      },
      {"year": "2016",
      "cost": 6000
      }
      ]
      }

      ), values ("u124",

      {"policyno": "U124",
      "state": "UT",
      "zipcode": "66853",
      "make": "Ford",
      "accidents": [ ]
      }

      ), values ("u125",

      {"policyno": "U125",
      "state": "UT",
      "zipcode": "66853",
      "make": "Ford"
      }

      );

      {noformat} 

      Define "risk" as the number of accidents divided by the number of policies.
      Find the five states that had the most risk in 2016.

      {noformat}

      from policies
      group by state group as g
      select state,
      ( from g
      select sum(
      (from g.accidents a
      where a.year = "2016"
      select count )[0]
      )[0] / count
      ) as risk
      order by risk desc
      limit 5;

      {noformat}

      This query runs into a NPE.

      Expected:

      "results": [
      { "state": "AZ",
      "risk": 2.0 },
      { "state": "CA",
      "risk": 1.5 },
      { "state": "UT",
      "risk": 0.6666666666666666

      }
      ]

       

       

      Attachments

        For Gerrit Dashboard: MB-22837
        # Subject Branch Project Status CR V

        Activity

          People

            yingyi Yingyi Bu (Inactive)
            yingyi Yingyi Bu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty