Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions modules/eventing/pages/eventing-Terminologies.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ It is not possible to get the value of a document that has been deleted or expir

==== `OnDeploy`

The `OnDeploy` handler runs once when an Eventing function is deployed or resumed.
The `OnDeploy` handler runs once when an Eventing function is deployed or resumed, before any mutations are processed.

The entry point `OnDeploy(action)` receives an `action` parameter, like `deploy` or `resume`, indicating the reason for invocation. It also includes a `delay` value (in milliseconds), showing the time since the function was paused. For deployment operations, this value is `0`
The entry point `OnDeploy(action)` receives an `action` parameter, like `deploy` or `resume`, indicating the reason for invocation. It also includes a `delay` value (in milliseconds), showing the time since the function was paused. For deployment operations, this value is `0`.

*Limitation*: Avoid long-running operations within the `OnDeploy` as they can delay function deployment.

Expand Down Expand Up @@ -336,6 +336,13 @@ Versions 6.0.0 and 6.5.0 filter all binary documents out of the DCP mutation str
The entry points into the handler processing for each mutation must run from start to finish before the specified timeout duration.
The default number of seconds is `60`.

|OnDeploy Timeout
|The number of seconds to elapse before the OnDeploy entry point times out and terminates.

The timeout is set to `60` seconds, by default.

The OnDeploy Timeout defines the maximum duration allowed for an Eventing Function to complete its initialization during deployment or resumption.

|Time Context Max Size
|The size limit of the context for any Timer created by the Eventing Function.

Expand Down
30 changes: 28 additions & 2 deletions modules/eventing/pages/eventing-language-constructs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -562,17 +562,18 @@ The Eventing Service calls the following JavaScript functions on events like mut

* <<onupdate_handler>>
* <<ondelete_handler>>
* <<ondeploy_handler>>
* <<timer_callback_handler>>

[#onupdate_handler]
=== OnUpdate Handler

The `OnUpdate` handler is called when you create or modify a document using an operation like insert or update.
The `OnUpdate` handler is called when you create or modify a document.
The entry point `OnUpdate(doc, meta)` listens to mutations in the associated source bucket.

The `OnUpdate` handler has the following limitations:

* If a document is modified several times in a short period of time, the handler calls might be combined into a single event due to deduplication.
* If a document is modified several times in a short period of time, the handler calls can merge into a single event due to deduplication.
* You cannot distinguish between a Create and an Update operation.

[source,javascript]
Expand Down Expand Up @@ -622,6 +623,31 @@ function OnDelete(meta) {
}
----

[#ondeploy_handler]
=== OnDeploy Handler

The `OnDeploy` handler is invoked once when an Eventing function is deployed or resumed, before any mutations are processed.
The entry point `OnDeploy(action)` is used for one-time setup tasks like resource initialization, creation of timers, and so on.

The `OnDeploy` handler has a limitation. Avoid any long-running operations within the `OnDeploy` as they can delay function deployment.

The timeout for OnDeploy execution is configurable separately in the xref:eventing:eventing-Terminologies.adoc#function-settings[Eventing Function Settings].

----
function OnDeploy(action) {
log("OnDeploy triggered. Reason:", action.reason, "Delay (ms):", action.delay);

if (action.reason === "deploy") {
// Perform operations for fresh deployment (like timer creation, resource initialisation)
log("Deploy: perform first time setup for function");
}
else if (action.reason === "resume") {
// Function was paused and resumed: refresh any cached information
log("Resume: perform operations before function resumption");
}
}
----

[#timer_callback_handler]
=== Timer Callback Handler

Expand Down
12 changes: 9 additions & 3 deletions modules/eventing/pages/eventing-lifecycle.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@ The minimum value is 1 (the default) and the recommended maximum is 64.
If the semantics of a language construct change in any given release the “Language compatibility” setting will ensure an older Eventing Function will continue to see the runtime behavior that existed at the time it was authored, until such behavior is deprecated and removed. Note 6.0.0, 6.5.0, and 6.6.2 (the default) are the only currently defined versions.

* *Script Timeout*: Script Timeout provides a timeout option to terminate a non-responsive Function.
The entry points into the Eventing Function, like OnUpdate and OnDelete, processing for each mutation must complete from start to finish prior to this specified timeout duration. The default is 60 seconds. In addition an Timer callback must also complete within this period.
The entry points into the Eventing Function, like OnUpdate and OnDelete, processing for each mutation must complete from start to finish prior to this specified timeout duration.
The default is 60 seconds.
In addition an Timer callback must also complete within this period.

* *OnDeploy Timeout*: OnDeploy Timeout defines the maximum duration allowed for an Eventing Function to complete its initialization during deployment or resumption.
The OnDeploy entry point must complete execution, from start to end, within the specified timeout period. If the runtime exceeds the specified duration, the function is reverted to its previous state. By default, the timeout is set to 60 seconds.
The OnDeploy entry point must complete execution, from start to end, within the specified timeout period.
If the runtime exceeds the specified duration, the function is reverted to its previous state.
By default, the timeout is set to 60 seconds.

* *Timer Context Max Size*: Timer Context Max Size limits the size of the context for any Timer created by the Function.
Eventing Timers can store and access a context which can be any JSON document, the context is used to store state when the timer is created and retrieve state when the timer fires. By default the size is 1024 bytes, but this can be adjusted on a per Function basis.
Expand All @@ -147,7 +151,9 @@ Currently Eventing Functions support the following binding types:

* *Constant Bindings*: to pass global settings/constants into the function.

An Eventing Function can have no bindings, just one binding, or several bindings. For more information on Bindings, refer to xref:eventing-Terminologies.adoc#section_mzd_l1p_m2b[Terminologies - Bindings].
An Eventing Function can have no bindings, just one binding, or several bindings.
For more information on Bindings, refer to xref:eventing-Terminologies.adoc#section_mzd_l1p_m2b[Terminologies - Bindings].

|===

. In the *ADD FUNCTION* dialog, configure the following information:
Expand Down
12 changes: 6 additions & 6 deletions modules/guides/pages/defer-index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ The following examples create a set of primary and secondary indexes in the spec

[source,java]
----
include::java-sdk:hello-world:example$IndexHelloWorld.java[tag=defer-create-primary,indent=0]
include::java-sdk:devguide:example$java/IndexHelloWorld.java[tag=defer-create-primary,indent=0]
----

[source,java]
----
include::java-sdk:hello-world:example$IndexHelloWorld.java[tag=defer-create-secondary,indent=0]
include::java-sdk:devguide:example$java/IndexHelloWorld.java[tag=defer-create-secondary,indent=0]
----

{github}
Expand Down Expand Up @@ -165,12 +165,12 @@ The following examples create a set of primary and secondary indexes in the spec

[source,python]
----
include::python-sdk:devguide:example$python/index_hello_world.py[tag=defer-create-primary,indent=0]
include::python-sdk:hello-world:example$index_hello_world.py[tag=defer-create-primary,indent=0]
----

[source,python]
----
include::python-sdk:devguide:example$python/index_hello_world.py[tag=defer-create-secondary,indent=0]
include::python-sdk:hello-world:example$index_hello_world.py[tag=defer-create-secondary,indent=0]
----

{github}
Expand Down Expand Up @@ -251,7 +251,7 @@ The following example builds all deferred indexes in the specified keyspace.

[source,java]
----
include::java-sdk:hello-world:example$IndexHelloWorld.java[tag=defer-build,indent=0]
include::java-sdk:devguide:example$java/IndexHelloWorld.java[tag=defer-build,indent=0]
----

{github}
Expand Down Expand Up @@ -289,7 +289,7 @@ The following example builds all deferred indexes in the specified keyspace.

[source,python]
----
include::python-sdk:devguide:example$python/index_hello_world.py[tag=defer-build,indent=0]
include::python-sdk:hello-world:example$index_hello_world.py[tag=defer-build,indent=0]
----

{github}
Expand Down
6 changes: 3 additions & 3 deletions modules/guides/pages/select.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The result includes each row found.

[source,csharp]
----
include::dotnet-sdk:hello-world:example$StartUsing.cs[tag=n1ql-query,indent=0]
include::dotnet-sdk:hello-world:example$StartUsing.csx[tag=n1ql-query,indent=0]
----

{github}
Expand All @@ -70,7 +70,7 @@ The result object includes each row found.

[source,java]
----
include::java-sdk:hello-world:example$StartUsing.java[tag=n1ql-query,indent=0]
include::java-sdk:devguide:example$java/StartUsing.java[tag=n1ql-query,indent=0]
----

{github}
Expand Down Expand Up @@ -305,7 +305,7 @@ Querying with SDKs:
* xref:c-sdk:howtos:n1ql-queries-with-sdk.adoc[C]
| xref:dotnet-sdk:howtos:n1ql-queries-with-sdk.adoc[.NET]
| xref:go-sdk:howtos:n1ql-queries-with-sdk.adoc[Go]
| xref:java-sdk:howtos:n1ql-queries-with-sdk.adoc[Java]
| xref:java-sdk:howtos:sqlpp-queries-with-sdk.adoc[Java]
| xref:nodejs-sdk:howtos:n1ql-queries-with-sdk.adoc[Node.js]
| xref:php-sdk:howtos:n1ql-queries-with-sdk.adoc[PHP]
| xref:python-sdk:howtos:n1ql-queries-with-sdk.adoc[Python]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/n1ql/assets/images/n1ql-language-reference/slice-expr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions modules/n1ql/pages/n1ql-intro/sysinfo.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ xref:n1ql:n1ql-manage/monitoring-n1ql-query.adoc#sys-active-req[system:active_re
xref:n1ql:n1ql-manage/monitoring-n1ql-query.adoc#sys-prepared[system:prepareds]
xref:n1ql:n1ql-manage/monitoring-n1ql-query.adoc#sys-completed-req[system:completed_requests]
xref:n1ql:n1ql-manage/monitoring-n1ql-query.adoc#sys-history[system:completed_requests_history]
xref:n1ql:n1ql-manage/query-awr.adoc[system:awr]

a| [%hardbreaks]
<<sys_my-user-info,system:my_user_info>>
Expand Down
113 changes: 113 additions & 0 deletions modules/n1ql/pages/n1ql-language-reference/arrayfun.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,119 @@ SELECT array_star(children).age FROM contacts WHERE fname = "Dave"
----
====

=== Empty Array Subscripts

You can use an empty array subscript (`[ ]`) to return an array that includes only defined elements.

The rules governing its use are as follows:

[cols="1a,2a"]
|====
| Expression | Description

| `field[]`
|* If `field` is not an array, it returns `NULL`.
* If `field` is an array, it returns the array as is.


| `field[][]`
|* If `field` is not an array, it returns `NULL`.
* If `field` contains only unnamed arrays, it returns `field` as is.
Otherwise, it returns `NULL`.

| `field[].field2`
|* If `field` is not an array, it returns `MISSING`.
* If `field` is an array, it extracts `field2` from each element in `field` and returns a new array with those values.
* If `field` contains unnamed arrays, they are flattened by one level.
Then from the resulting array, it extracts `field2` from each object where it is present.

| `field[][].field2`
|* If `field` is not an array, it returns `MISSING`.
* If every element in `field` is not an unnamed array, it returns `MISSING`.
* If `field` contains unnamed arrays, they are flattened by one level.
Then from the resulting array, it extracts `field2` from each object where it is present.


| `field[].field2[].field3`
|* Returns an array of `field3` values by traversing two levels of arrays.
First it extracts `field2` from each element of `field`, then extracts `field3` from each element of the resulting `field2` array.
* If `field` and `field2` contain unnamed arrays, they are flattened by one level.
Then from the resulting `field2` array, it extracts `field3` from each object where it is present.

|====

NOTE: If you use more that two empty array subscripts (for example, `field[][][]`), the function considers only the first two subscripts and ignores the rest.

==== Example

====
Given the following sample document:

[source,json]
----
{
"a": {
"airline": "AF",
"airlineid": "airline_003",
"destinationairport": "SFO",
"distance": 2481.617376098415,
"equipment": "320",
"id": 3,
"schedule": [
{
"day": 0,
"flight": "AF198",
"utc": "10:13:00"
},
{
"flight": "AF250",
"utc": "12:59:00"
},
{
"day": 2,
"flight": "AF223",
"special_flights": [
{
"a": "SA"
},
{
"b": [
[
{
"c": "SC1"
},
{
"c": "SC2"
}
],
[
{
"c": "SC3"
}
]
]
}
],
"utc": "19:41:00"
}
],
"sourceairport": "DFW"
}
}
----

Here's how different array subscripts evaluate:

* `a.airline[]`: Returns `NULL` (not an array).
* `a.schedule[]`: Equivalent to `a.schedule`, returns the array.
* `a.schedule[].day`: Returns `[0, 2]`. This is in contrast to `a.schedule[*].day`, which returns `[0, null, 2]`.
* `a.schedule[].special_flights[].a`: Returns `["SA"]`.
* `a.schedule[][].utc`: Returns `MISSING`.
* `a.schedule[].special_flights[].b[][].c`: Returns `["SC1", "SC2", "SC3"]`.
* `a.schedule[].special_flights[].b[].c`: Also returns `["SC1", "SC2", "SC3"]`, as the unnamed arrays are flattened.

====

[[fn-array-sum,ARRAY_SUM()]]
== ARRAY_SUM([.var]`expr`)

Expand Down
21 changes: 2 additions & 19 deletions modules/n1ql/pages/n1ql-language-reference/createindex.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -440,25 +440,8 @@ In Couchbase Server 7.6.2 and later, you can change the default setting for the

If you change the default setting for `defer_build` to `true`, index creation operates in deferred build mode by default.

To change the default setting for deferred builds, use the REST API to set the `indexer.settings.defer_build` property.
For example,

[source,sh]
----
curl http://$BASEURL:9102/settings -u $USER:$PASSWORD \
-d '{"indexer.settings.defer_build": true}'
----

Use the following command to retrieve the indexer settings:

[source,sh]
----
curl -X GET http://$BASEURL:9102/settings -u $USER:$PASSWORD
----

* `$BASEURL` is the base URL for the API call, for example: `localhost`.
* `$USER` is the username, for example: `Administrator`.
* `$PASSWORD` is the password.
To change the default setting for deferred builds, use the Index Settings REST API to set the `indexer.settings.defer_build` property.
For an example, see xref:index-rest-settings:index.adoc#ex-defer-build[Defer Index Builds by Default].

== Examples

Expand Down
Loading