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
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.
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
Loading