You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: update array value docs to reflect RediSearch-compatible error behavior
Remove element-wise operations, array-specific functions, and broadcasting.
Arrays now return errors/nil/nan when passed to scalar functions or arithmetic,
matching RediSearch behavior.
Signed-off-by: Alexandru Filip <alexandru.filip@improving.com>
Arrays can be nested — an array may contain other arrays as elements, enabling multi-dimensional data structures within the expression evaluation context.
180
180
181
-
## Element-wise Scalar Functions
181
+
## Scalar Functions on Arrays
182
182
183
-
When a scalar function receives an array argument, it applies independently to each element, returning a new array of the same length.
183
+
Scalar functions do not apply element-wise to arrays. Passing an array to a scalar function produces a nil or nan result, consistent with RediSearch behavior.
184
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 |
185
+
Functions that return nil when applied to an array: `lower`, `upper`, `strlen`, `startswith`, `contains`.
195
186
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.
187
+
Functions that return nan when applied to an array: `floor`, `ceil`, `abs`, `log`, `log2`, `exp`, `sqrt`.
201
188
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
189
+
## Array Arithmetic
211
190
212
-
| Syntax | Description |
213
-
| :----- | :---------- |
214
-
|`arraylen(array)`| Returns the number of elements in the array |
215
-
|`arrayat(array, index)`| Returns the element at the zero-based index |
216
-
|`isarray(value)`| Returns 1 if the value is an array, otherwise 0 |
217
-
|`makearray(e1, e2, ...)`| Constructs an array from the provided arguments |
218
-
|`flatten(array, depth)`| Flattens nested arrays to the specified depth |
191
+
Any mathematical operation (`+`, `-`, `*`, `/`, `^`) involving an array operand returns the error `"Could not convert value to a number"`. This is consistent with RediSearch behavior.
219
192
220
193
## Error Handling
221
194
222
-
Array operations produce specific error messages when encountering invalid conditions.
195
+
Array operations produce specific error messages when encountering invalid conditions, consistent with RediSearch error behavior.
223
196
224
-
| Condition |Message Format|
225
-
| :-------- | :-------------|
226
-
| Arithmetic with incompatible type|`Type error: cannot add array to string`|
227
-
|Element-wise on mismatched lengths|`Length mismatch: arrays have lengths 3 and 5`|
228
-
|Per-element computation failure |`Element error at index 2: division by zero`|
229
-
|`arrayat` out-of-bounds |`Index out of bounds: index 5, array length 3`|
197
+
| Condition |Result|
198
+
| :-------- | :----- |
199
+
| Arithmetic with array operand|`"Could not convert value to a number"`|
200
+
|`substr` with array argument|`"Invalid type for substr. Expected string"`|
0 commit comments