Skip to content

Commit 5fd8d7a

Browse files
docs: add array value documentation for search expressions
Signed-off-by: Alexandru Filip <alexandru.filip@improving.com>
1 parent dae77b6 commit 5fd8d7a

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

commands/ft.aggregate.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ The following reducer functions are available. The reducer functions that take a
9292
| MAX 1 <expression> | The largest numerical values of the expression. |
9393
| AVG 1 <expression> | The numerical average of the values of the expression. |
9494
| STDDEV 1 <expression> | The standard deviation the values of the expression. |
95+
| TOLIST 1 <expression> | Collects expression values into an array. |

topics/search-expressions.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,71 @@ The exists function returns 0 if the input argument is Nil else 1. This can be u
163163
| Syntax | Operation |
164164
| :-----------: | :----------------------------- |
165165
| exists(value) | 0 if the value is Nil, else 1. |
166+
167+
# Array Values
168+
169+
## Producing Arrays
170+
171+
An array is an ordered sequence of scalar elements produced by the `TOLIST` reducer during a `GROUPBY` stage. The resulting array value is available to expressions in subsequent pipeline stages.
172+
173+
Syntax:
174+
175+
```
176+
REDUCE TOLIST 1 <expression>
177+
```
178+
179+
Arrays can be nested — an array may contain other arrays as elements, enabling multi-dimensional data structures within the expression evaluation context.
180+
181+
## Element-wise Scalar Functions
182+
183+
When a scalar function receives an array argument, it applies independently to each element, returning a new array of the same length.
184+
185+
| Function | Description |
186+
| :------- | :---------- |
187+
| `lower(array)` | Applies lower-case conversion to each element |
188+
| `upper(array)` | Applies upper-case conversion to each element |
189+
| `strlen(array)` | Returns string length of each element |
190+
| `floor(array)` | Applies floor to each element |
191+
| `ceil(array)` | Applies ceiling to each element |
192+
| `abs(array)` | Applies absolute value to each element |
193+
| `log(array)` | Applies natural log to each element |
194+
| `sqrt(array)` | Applies square root to each element |
195+
196+
## Array Arithmetic
197+
198+
When both operands are arrays of equal length, arithmetic operators apply element-wise, producing a new array where each element is the result of applying the operator to the corresponding elements of the input arrays.
199+
200+
When one operand is a scalar and the other is an array, the scalar is broadcast — promoted to an array of the same length — so the operation applies to each element.
201+
202+
| Operator | Operation |
203+
| :------: | :-------- |
204+
| `+` | Element-wise addition |
205+
| `-` | Element-wise subtraction |
206+
| `*` | Element-wise multiplication |
207+
| `/` | Element-wise division |
208+
| `^` | Element-wise exponentiation |
209+
210+
## Array-Specific Functions
211+
212+
| Syntax | Description |
213+
| :----- | :---------- |
214+
| `vectorlen(array)` | Returns the number of elements in the array |
215+
| `vectorat(array, index)` | Returns the element at the zero-based index |
216+
| `isvector(value)` | Returns 1 if the value is an array, otherwise 0 |
217+
| `makevector(e1, e2, ...)` | Constructs an array from the provided arguments |
218+
| `flatten(array, depth)` | Flattens nested arrays to the specified depth |
219+
220+
## Error Handling
221+
222+
Array operations produce specific error messages when encountering invalid conditions.
223+
224+
| Condition | Message Format |
225+
| :-------- | :------------- |
226+
| Arithmetic with incompatible type | `Type error: cannot add vector to string` |
227+
| Element-wise on mismatched lengths | `Length mismatch: vectors have lengths 3 and 5` |
228+
| Per-element computation failure | `Element error at index 2: division by zero` |
229+
| `vectorat` out-of-bounds | `Index out of bounds: index 5, vector length 3` |
230+
231+
## RESP Serialization
232+
233+
Array values are serialized as RESP arrays in the `FT.AGGREGATE` response. Each element of the array is serialized according to its scalar type: numeric values become bulk strings containing digits, string values become bulk strings, and nil values become RESP nil.

0 commit comments

Comments
 (0)