From d65ffd7840b0f4214cc66772e3885d35b686752e Mon Sep 17 00:00:00 2001 From: Simon Dew Date: Tue, 19 Nov 2024 11:16:01 +0000 Subject: [PATCH 1/5] Update Analytics function name and example --- .../pages/eventing-language-constructs.adoc | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/modules/eventing/pages/eventing-language-constructs.adoc b/modules/eventing/pages/eventing-language-constructs.adoc index b20d16b30..d253c51ae 100644 --- a/modules/eventing/pages/eventing-language-constructs.adoc +++ b/modules/eventing/pages/eventing-language-constructs.adoc @@ -376,14 +376,14 @@ The `close()` method on the iterable handle can throw an exception if the underl |=== [#analytics_call] -=== `ANALYTICS()` +=== `couchbase.analyticsQuery()` ifeval::['{page-component-version}' == '7.6'] [.status]#Introduced in Couchbase Server 7.6# endif::[] -The `ANALYTICS()` function provides integration with {sqlpp} Analytics directly from the Eventing Service. +The `couchbase.analyticsQuery()` function provides integration with {sqlpp} Analytics directly from the Eventing Service. Integrating Eventing with Analytics: @@ -394,31 +394,17 @@ Integrating Eventing with Analytics: [source,javascript] ---- function OnUpdate(doc, meta) { - // Ignore information we don't care about - if (doc.type !== 'airline') return; - - // Get the total routes per IATA - var route_cnt = 0; - // Uses a true variable as a SQL++ parameter - var airline = doc.iata; - - var results = ANALYTICS( - "SELECT COUNT(*) AS cnt - FROM `travel-sample`.`inventory`.`route` - WHERE type = \"route\" - AND airline = $1", [doc.iata] - ); - - // Stream results using the 'for' iterator - for (var item of results) { - route_cnt = item.cnt; - } + var count = 0; + const limit = 4; - // End the query and free the resources held - results.close(); + let query = couchbase.analyticsQuery('SELECT * FROM default LIMIT $limit;', {"limit": limit}); + for (let row of query) { + ++count; + } - // Log the KEY, AIRLINE and ROUTE_CNT - log("key: " + meta.id + ", airline: " + doc.iata + ", route_cnt: " + route_cnt); + if (count === limit) { + dst_bucket[meta.id] = 'yes'; + } } ---- From 7b082c62b4a1e2f20a76f76decbe72507d4ed5f1 Mon Sep 17 00:00:00 2001 From: Simon Dew Date: Tue, 19 Nov 2024 11:34:01 +0000 Subject: [PATCH 2/5] Let AsciiDoc generate link text where possible --- .../pages/eventing-language-constructs.adoc | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/modules/eventing/pages/eventing-language-constructs.adoc b/modules/eventing/pages/eventing-language-constructs.adoc index d253c51ae..240970b4c 100644 --- a/modules/eventing/pages/eventing-language-constructs.adoc +++ b/modules/eventing/pages/eventing-language-constructs.adoc @@ -15,10 +15,10 @@ Certain capabilities have been removed and are not supported in order to handle Eventing Functions support the following features: -* <> -* <> -* <> -* <> +* <> +* <> +* <> +* <> [#basic_bucket_accessors] === Basic Keyspace Accessors @@ -77,7 +77,7 @@ function OnUpdate(doc, meta) { Advanced Keyspace Accessors expose a larger set of options and operators than <>. They have non-trivial argument sets and return values. -See xref:eventing-advanced-keyspace-accessors.adoc[Advanced Keyspace Accessors] for more details. +See xref:eventing-advanced-keyspace-accessors.adoc[] for more details. [#logging] === Logging @@ -196,10 +196,10 @@ To include comments in multiline statements, use `/* this format */` instead. The following features are not supported by Eventing Functions: -* <> -* <> -* <> -* <> +* <> +* <> +* <> +* <> [#global-state] === Global State @@ -264,13 +264,13 @@ The Eventing Service does not support importing libraries into Eventing Function Eventing Functions support the following built-in functions: -* <> -* <> -* <> -* <> -* <> -* <> -* <> +* <> +* <> +* <> +* <> +* <> +* <> +* <> [#n1ql_call] === `N1QL()` @@ -379,7 +379,6 @@ The `close()` method on the iterable handle can throw an exception if the underl === `couchbase.analyticsQuery()` ifeval::['{page-component-version}' == '7.6'] - [.status]#Introduced in Couchbase Server 7.6# endif::[] @@ -408,7 +407,7 @@ function OnUpdate(doc, meta) { } ---- -For more information about {sqlpp} Analytics, see xref:server:analytics:1_intro.adoc[What’s SQL++ for Analytics?]. +For more information about {sqlpp} Analytics, see xref:server:analytics:1_intro.adoc[]. [#crc64_call] === `crc64()` @@ -542,14 +541,14 @@ To cancel a Timer, you can do one of the following: * Call the `createTimer()` function again using a reference from the existing Timer you want to cancel. * Call the `cancelTimer()` function using `cancelTimer(callback, reference)`. -For more information about Timers, see xref:eventing-timers.adoc[Timers]. +For more information about Timers, see xref:eventing-timers.adoc[]. [#curl_call] === `curl()` The `curl()` function lets you interact with external entities through a REST endpoint from Eventing Functions, using either HTTP or HTTPS. -For more information about the `curl()` function, see xref:eventing-curl-spec.adoc[cURL]. +For more information about the `curl()` function, see xref:eventing-curl-spec.adoc[]. [#handler-signatures] @@ -557,9 +556,9 @@ For more information about the `curl()` function, see xref:eventing-curl-spec.ad The Eventing Service calls the following JavaScript functions on events like mutations and fired Timers: -* <> -* <> -* <> +* <> +* <> +* <> [#onupdate_handler] === OnUpdate Handler @@ -648,7 +647,7 @@ function OnUpdate(doc, meta) { } ---- -For more information about Timers, see xref:eventing-timers.adoc[Timers]. +For more information about Timers, see xref:eventing-timers.adoc[]. == Reserved Words From 4cd30bbd3708cfcbe3fdd2e56e05edd71e79f415 Mon Sep 17 00:00:00 2001 From: Simon Dew Date: Tue, 19 Nov 2024 11:44:12 +0000 Subject: [PATCH 3/5] Prevent awkward line break in the page ToC --- modules/eventing/pages/eventing-language-constructs.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/eventing/pages/eventing-language-constructs.adoc b/modules/eventing/pages/eventing-language-constructs.adoc index 240970b4c..939820e8e 100644 --- a/modules/eventing/pages/eventing-language-constructs.adoc +++ b/modules/eventing/pages/eventing-language-constructs.adoc @@ -376,7 +376,7 @@ The `close()` method on the iterable handle can throw an exception if the underl |=== [#analytics_call] -=== `couchbase.analyticsQuery()` +=== `couchbase.{zwsp}analyticsQuery({wj})` ifeval::['{page-component-version}' == '7.6'] [.status]#Introduced in Couchbase Server 7.6# From 5fb6afcc25c615cd843ac0148c581df79c6e8dc9 Mon Sep 17 00:00:00 2001 From: Simon Dew Date: Thu, 21 Nov 2024 15:43:50 +0000 Subject: [PATCH 4/5] Updates after review --- .../pages/eventing-language-constructs.adoc | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/eventing/pages/eventing-language-constructs.adoc b/modules/eventing/pages/eventing-language-constructs.adoc index 939820e8e..21bae45bf 100644 --- a/modules/eventing/pages/eventing-language-constructs.adoc +++ b/modules/eventing/pages/eventing-language-constructs.adoc @@ -390,20 +390,22 @@ Integrating Eventing with Analytics: * Simplifies Eventing code logic and improves code readability * Eliminates security and network latency issues with the `curl()` function +The following example assumes that the Analytics collection (dataset) called `default` already exists. + [source,javascript] ---- function OnUpdate(doc, meta) { - var count = 0; - const limit = 4; + var count = 0; + const limit = 4; - let query = couchbase.analyticsQuery('SELECT * FROM default LIMIT $limit;', {"limit": limit}); - for (let row of query) { - ++count; - } + let query = couchbase.analyticsQuery('SELECT * FROM default LIMIT $limit;', {"limit": limit}); + for (let row of query) { + ++count; + } - if (count === limit) { - dst_bucket[meta.id] = 'yes'; - } + if (count === limit) { + dst_bucket[meta.id] = 'yes'; + } } ---- From 47bed8cffffbf2484d13a25b7d8f993be5b6e406 Mon Sep 17 00:00:00 2001 From: Simon Dew Date: Fri, 22 Nov 2024 16:49:42 +0000 Subject: [PATCH 5/5] Beautify JavaScript example --- modules/eventing/pages/eventing-language-constructs.adoc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/eventing/pages/eventing-language-constructs.adoc b/modules/eventing/pages/eventing-language-constructs.adoc index 21bae45bf..432d45ce3 100644 --- a/modules/eventing/pages/eventing-language-constructs.adoc +++ b/modules/eventing/pages/eventing-language-constructs.adoc @@ -398,13 +398,15 @@ function OnUpdate(doc, meta) { var count = 0; const limit = 4; - let query = couchbase.analyticsQuery('SELECT * FROM default LIMIT $limit;', {"limit": limit}); + let query = couchbase.analyticsQuery('SELECT * FROM default LIMIT $limit;', { + "limit": limit + }); for (let row of query) { - ++count; + ++count; } if (count === limit) { - dst_bucket[meta.id] = 'yes'; + dst_bucket[meta.id] = 'yes'; } } ----