vegarsti commented on code in PR #17732:
URL: https://github.com/apache/datafusion/pull/17732#discussion_r2399621116
##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -3305,17 +3306,29 @@ impl ScalarValue {
/// assert_eq!(scalar_vec, expected);
/// ```
pub fn convert_array_to_scalar_vec(array: &dyn Array) ->
Result<Vec<Vec<Self>>> {
- let mut scalars = Vec::with_capacity(array.len());
-
- for index in 0..array.len() {
- let nested_array = array.as_list::<i32>().value(index);
- let scalar_values = (0..nested_array.len())
- .map(|i| ScalarValue::try_from_array(&nested_array, i))
- .collect::<Result<Vec<_>>>()?;
- scalars.push(scalar_values);
+ fn generic_collect<OffsetSize: OffsetSizeTrait>(
+ array: &dyn Array,
+ ) -> Result<Vec<Vec<ScalarValue>>> {
+ array
+ .as_list::<OffsetSize>()
+ .iter()
+ .map(|nested_array| match nested_array {
+ Some(nested_array) => (0..nested_array.len())
+ .map(|i| ScalarValue::try_from_array(&nested_array, i))
+ .collect::<Result<Vec<_>>>(),
+ // TODO: what can we put for null?
+ None => Ok(vec![]),
+ })
+ .collect()
Review Comment:
@alamb By null semantics what do you mean exactly? Do you mean what this
returns? `select array_contains([NULL], 1)`
If so, DuckDB returns `false`:
```
D select list_contains([NULL], 1);
┌─────────────────────────────────────────┐
│ list_contains(main.list_value(NULL), 1) │
│ boolean │
├─────────────────────────────────────────┤
│ false │
└─────────────────────────────────────────┘
```
Spark returns `null`:
<img width="560" height="168" alt="CleanShot-2025-10-02-19-55-07@2x"
src="https://github.com/user-attachments/assets/6c51401c-17ab-4f27-bd4b-40d97f6422c7"
/>
Postgres returns `null`:
```
SELECT null = ANY(ARRAY[1,2,3]); -- true
?column?
----------
¤
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]