Skip to content

Commit ec3c2dd

Browse files
committed
Merge remote-tracking branch 'apache/main' into alamb/field_metadata2
2 parents 403e206 + 39c100a commit ec3c2dd

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

datafusion/functions-nested/src/position.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ make_udf_expr_and_func!(
5252

5353
#[user_doc(
5454
doc_section(label = "Array Functions"),
55-
description = "Returns the position of the first occurrence of the specified element in the array.",
55+
description = "Returns the position of the first occurrence of the specified element in the array, or NULL if not found.",
5656
syntax_example = "array_position(array, element)\narray_position(array, element, index)",
5757
sql_example = r#"```sql
5858
> select array_position([1, 2, 2, 3, 1, 4], 2);
@@ -76,7 +76,10 @@ make_udf_expr_and_func!(
7676
name = "element",
7777
description = "Element to search for position in the array."
7878
),
79-
argument(name = "index", description = "Index at which to start searching.")
79+
argument(
80+
name = "index",
81+
description = "Index at which to start searching (1-indexed)."
82+
)
8083
)]
8184
#[derive(Debug)]
8285
pub struct ArrayPosition {
@@ -170,7 +173,7 @@ fn general_position_dispatch<O: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<Ar
170173
// if `start_from` index is out of bounds, return error
171174
for (arr, &from) in list_array.iter().zip(arr_from.iter()) {
172175
if let Some(arr) = arr {
173-
if from < 0 || from as usize >= arr.len() {
176+
if from < 0 || from as usize > arr.len() {
174177
return internal_err!("start_from index out of bounds");
175178
}
176179
} else {

datafusion/sqllogictest/test_files/array.slt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,10 +3367,16 @@ select array_concat(make_array(column3), column1, column2) from arrays_values_v2
33673367
## array_position (aliases: `list_position`, `array_indexof`, `list_indexof`)
33683368

33693369
## array_position with NULL (follow PostgreSQL)
3370-
#query I
3371-
#select array_position([1, 2, 3, 4, 5], null), array_position(NULL, 1);
3372-
#----
3373-
#NULL NULL
3370+
query II
3371+
select array_position([1, 2, 3, 4, 5], arrow_cast(NULL, 'Int64')), array_position(arrow_cast(NULL, 'List(Int64)'), 1);
3372+
----
3373+
NULL NULL
3374+
3375+
# array_position with no match (incl. empty array) returns NULL
3376+
query II
3377+
select array_position([], 1), array_position([2], 1);
3378+
----
3379+
NULL NULL
33743380

33753381
# array_position scalar function #1
33763382
query III

docs/source/library-user-guide/upgrading.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,60 @@ See [#16317] for details.
5050

5151
## DataFusion `48.0.0`
5252

53+
### `Expr::WindowFunction` is now `Box`ed
54+
55+
`Expr::WindowFunction` is now a `Box<WindowFunction>` instead of a `WindowFunction` directly.
56+
This change was made to reduce the size of `Expr` and improve performance when
57+
planning queries (see [details on #16207]).
58+
59+
This is a breaking change, so you will need to update your code if you match
60+
on `Expr::WindowFunction` directly. For example, if you have code like this:
61+
62+
```rust
63+
# /* comment to avoid running
64+
match expr {
65+
Expr::WindowFunction(WindowFunction {
66+
params:
67+
WindowFunctionParams {
68+
partition_by,
69+
order_by,
70+
..
71+
}
72+
}) => {
73+
// Use partition_by and order_by as needed
74+
}
75+
_ => {
76+
// other expr
77+
}
78+
}
79+
# */
80+
```
81+
82+
You will need to change it to:
83+
84+
```rust
85+
# /* comment to avoid running
86+
match expr {
87+
Expr::WindowFunction(window_fun) => {
88+
let WindowFunction {
89+
fun,
90+
params: WindowFunctionParams {
91+
args,
92+
partition_by,
93+
..
94+
},
95+
} = window_fun.as_ref();
96+
// Use partition_by and order_by as needed
97+
}
98+
_ => {
99+
// other expr
100+
}
101+
}
102+
# */
103+
```
104+
105+
[details on #16207]: https://github.com/apache/datafusion/pull/16207#issuecomment-2922659103
106+
53107
### The `VARCHAR` SQL type is now represented as `Utf8View` in Arrow.
54108

55109
The mapping of the SQL `VARCHAR` type has been changed from `Utf8` to `Utf8View`

docs/source/user-guide/sql/scalar_functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,7 +3142,7 @@ array_pop_front(array)
31423142

31433143
### `array_position`
31443144

3145-
Returns the position of the first occurrence of the specified element in the array.
3145+
Returns the position of the first occurrence of the specified element in the array, or NULL if not found.
31463146

31473147
```sql
31483148
array_position(array, element)
@@ -3153,7 +3153,7 @@ array_position(array, element, index)
31533153

31543154
- **array**: Array expression. Can be a constant, column, or function, and any combination of array operators.
31553155
- **element**: Element to search for position in the array.
3156-
- **index**: Index at which to start searching.
3156+
- **index**: Index at which to start searching (1-indexed).
31573157

31583158
#### Example
31593159

0 commit comments

Comments
 (0)