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

Pivot an array into dynamic set of key:value properties in Analytics

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Duplicate
    • Major
    • None
    • None
    • analytics
    • 1

    Description

      Pivot an array into dynamic set of key:value properties in Analytics. This is a super powerful N1QL feature. Can that be done in Analytics, in a cleaner, better way?

      N1QL syntax allows me to:

      SELECT RAW OBJECT o.id:o.label for o IN 
      [
        {"id":"test","label":"val"}
        ,
        {"id":"test2","label":"val2"}
      ]
      END
      

      Result:

      { "test": "val", "test2": "val2" }
      

      Workaround is to use encode/decode_json() functions:

      select raw decode_json("{" || string_join( 
      (
      select value encode_json(i.id) || ":" || encode_json(i.label)
      from [
       
      {"id":"test","label":"val"}
       
      ,
       
      {"id":"test2","label":"val2"}
       
      ] i
      ), ","
      ) || "}")
      

      Attachments

        Issue Links

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

          Activity

            People

              till Till Westmann
              david.elliott David Elliott
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty