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

NEST ON KEYS doesn't preserve original key order

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 4.6.0, 5.0.0
    • 4.0.0, 4.1.0, 4.5.0
    • query
    • Security Level: Public
    • Tried with 4.0 GA and 4.1.0-DP on Mac and Ubuntu.
    • Untriaged
    • Unknown

    Description

      For example, with the following data set:

      user::a

      { "name": "Amy", "friends": ["user::b", "user::c", "user::d"] }

      user::b

      { "name": "Bruno" }

      user::c

      { "name": "Cameron" }

      user::d

      { "name": "Declan" }

      N1QL query:
      SELECT u, f[*].name AS friendNames
      FROM user_profiles u
      USE KEYS "user::a"
        NEST user_profiles AS f
          ON KEYS u.friends;
      

      Executing above query returns the following result.
      However, the friendNames is not ordered as these keys are ordered in the original u.friends array.
      It seems that the result ordering is at random, every time returns different result.

      N1QL query result:

      [  {
          "friendNames": [
            "Declan",
            "Bruno",
            "Cameron"
          ],
          "u": {
            "friends": [
              "b", "c", "d"
            ],
            "name": "Amy"
          }
        } ]
      

      I've tested this with 4.0 GA and 4.1 DP, and got the same result.
      For some use cases, preserving the original order is critical.

      The nested object should be returned in the order of the keys array.

      An array is an ordered sequence of zero or more values.
      http://www.rfc-editor.org/rfc/rfc7159.txt

      Attachments

        Issue Links

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

          Activity

            People

              Prerna.Manaktala Prerna Manaktala (Inactive)
              koji@couchbase.com Koji Kawamura (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