From 81faaaf52e0d832d9ae7e9ac32b3d87d9545f582 Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Tue, 25 Mar 2025 09:58:54 +0530 Subject: [PATCH 1/4] add object_contact2 function --- .../n1ql-language-reference/objectfun.adoc | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc b/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc index 6d4ab3239..4c414860e 100644 --- a/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc @@ -109,6 +109,62 @@ SELECT OBJECT_CONCAT({"abc": 1}, {"def": 2}, {"ghi": 3}, {"ghi": 4}, {"ghi": [5, ---- ==== +[[fn-obj-concat2,OBJECT_CONCAT2()]] +== OBJECT_CONCAT2(`expr`, `expr` ...) + +=== Description + +This function concatenates multiple input objects into a single new object, and requires at least two input objects to work. +Unlike <>, this function supports both plain objects and arrays of objects as arguments. + + +=== Arguments + +expr:: An expression representing an object or an array of objects. +The first argument must be a plain object and cannot be an array. + +=== Return Value + +An object constructed by concatenating all the input objects. +If any of the input objects contain the same attribute name, the attribute from the last relevant object in the input list is copied to the output; similarly-named attributes from earlier objects in the input list are ignored. + +=== Examples + +[[obj-concat2-ex,OBJECT_CONCAT2() Example]] +==== +.Query +[source,sqlpp] +---- +SELECT OBJECT_CONCAT2({"abc": 1}, {"def": 2}, {"ghi": 3}, {"ghi": 4}, {"ghi": [5, 6, 7]},{"jkl": [{"mno": 8}, {"pqr": 9}]} ); +---- + +.Results +[source,json] +---- +[ + { + "$1": { + "abc": 1, + "def": 2, + "ghi": [ + 5, + 6, + 7 + ], + "jkl": [ + { + "mno": 8 + }, + { + "pqr": 9 + } + ] + } + } +] +---- +==== + [[fn-obj-field,OBJECT_FIELD()]] == OBJECT_FIELD(`object`, `field`) From ada4b5ca1cdca5ac47769187b4b6bbfc0ebc4df8 Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Tue, 25 Mar 2025 10:19:14 +0530 Subject: [PATCH 2/4] Format example --- modules/n1ql/pages/n1ql-language-reference/objectfun.adoc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc b/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc index 4c414860e..af746190b 100644 --- a/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc @@ -135,7 +135,10 @@ If any of the input objects contain the same attribute name, the attribute from .Query [source,sqlpp] ---- -SELECT OBJECT_CONCAT2({"abc": 1}, {"def": 2}, {"ghi": 3}, {"ghi": 4}, {"ghi": [5, 6, 7]},{"jkl": [{"mno": 8}, {"pqr": 9}]} ); +SELECT OBJECT_CONCAT2({"abc": 1}, {"def": 2}, {"ghi": 3}, {"ghi": 4}, + {"ghi": [5, 6, 7]}, + {"jkl": [{"mno": 8}, {"pqr": 9}]} +); ---- .Results From d8b1763a128026a84aacdc79c50c28bbdf811e10 Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Tue, 22 Apr 2025 10:46:03 +0530 Subject: [PATCH 3/4] update example --- .../n1ql-language-reference/objectfun.adoc | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc b/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc index af746190b..407ba04be 100644 --- a/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc @@ -135,9 +135,12 @@ If any of the input objects contain the same attribute name, the attribute from .Query [source,sqlpp] ---- -SELECT OBJECT_CONCAT2({"abc": 1}, {"def": 2}, {"ghi": 3}, {"ghi": 4}, - {"ghi": [5, 6, 7]}, - {"jkl": [{"mno": 8}, {"pqr": 9}]} +SELECT OBJECT_CONCAT2({"employee_id":1}, + [ {"name": "John Doe"}, + {"department": "Engineering"}, + {"location": "New York"}, + {"location":"California"} + ] ); ---- @@ -147,21 +150,10 @@ SELECT OBJECT_CONCAT2({"abc": 1}, {"def": 2}, {"ghi": 3}, {"ghi": 4}, [ { "$1": { - "abc": 1, - "def": 2, - "ghi": [ - 5, - 6, - 7 - ], - "jkl": [ - { - "mno": 8 - }, - { - "pqr": 9 - } - ] + "department": "Engineering", + "employee_id": 1, + "location": "California", + "name": "John Doe" } } ] From 5c2e0ac6b2a639fd4f2ee0bb6d9b1d81e03c1f21 Mon Sep 17 00:00:00 2001 From: Rakhi Prathap Date: Wed, 23 Apr 2025 15:25:27 +0530 Subject: [PATCH 4/4] updated examples --- .../n1ql-language-reference/objectfun.adoc | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc b/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc index 407ba04be..172a43e1a 100644 --- a/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/objectfun.adoc @@ -87,7 +87,12 @@ If any of the input objects contain the same attribute name, the attribute from .Query [source,sqlpp] ---- -SELECT OBJECT_CONCAT({"abc": 1}, {"def": 2}, {"ghi": 3}, {"ghi": 4}, {"ghi": [5, 6, 7]}); +SELECT OBJECT_CONCAT({"flight": "AF198"}, + {"utc": "4:44:44"}, + {"code": "green"}, + {"code": "yellow"}, + {"passengers": ["Corrine Hill", "Vallie Ryan"]} +); ---- .Results @@ -96,12 +101,12 @@ SELECT OBJECT_CONCAT({"abc": 1}, {"def": 2}, {"ghi": 3}, {"ghi": 4}, {"ghi": [5, [ { "$1": { - "abc": 1, - "def": 2, - "ghi": [ - 5, - 6, - 7 + "flight": "AF198", + "utc": "4:44:44", + "code": "yellow", + "passengers": [ + "Corrine Hill", + "Vallie Ryan" ] } } @@ -135,12 +140,13 @@ If any of the input objects contain the same attribute name, the attribute from .Query [source,sqlpp] ---- -SELECT OBJECT_CONCAT2({"employee_id":1}, - [ {"name": "John Doe"}, - {"department": "Engineering"}, - {"location": "New York"}, - {"location":"California"} - ] +SELECT OBJECT_CONCAT2( + {"flight": "AF198"}, + [ {"utc": "4:44:44"}, + {"code": "green"}, + {"airline": "Air France"}, + {"airline": "Delta"} + ] ); ---- @@ -150,10 +156,10 @@ SELECT OBJECT_CONCAT2({"employee_id":1}, [ { "$1": { - "department": "Engineering", - "employee_id": 1, - "location": "California", - "name": "John Doe" + "flight": "AF198", + "utc": "4:44:44", + "code": "green", + "airline": "Delta" } } ]