You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "joroKr21 (via GitHub)" <gi...@apache.org> on 2025/03/11 08:51:49 UTC
[PR] Saner handling of nulls inside arrays [datafusion]
joroKr21 opened a new pull request, #15149:
URL: https://github.com/apache/datafusion/pull/15149
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- Part of #7142
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2739679149
> I recommend following whatever DuckDB (or postgres do) -- there is not muchv alue in DataFusion having different semantics from other systems
* DuckDB doesn't have union for arrays: https://duckdb.org/docs/stable/sql/functions/list.html
* `list_intersect` is not commutative in DuckDB (I would consider this a bug)
* `select list_intersect(NULL, [1,2,3]);` returns null
* `select list_intersect(NULL, [1,2,3]);` returns empty list
* Postgres has neither union, not intersect for arrays
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996130649
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -4408,12 +4422,10 @@ select array_union(arrow_cast([], 'LargeList(Int64)'), arrow_cast([], 'LargeList
query ?
select array_union([[null]], []);
----
-[[NULL]]
+[[]]
-query ?
+query error DataFusion error: Error during planning: Failed to unify argument types of array_union:
Review Comment:
Is this a regression? It looks like the query used to run but now doesn't.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2764507295
@thinkharderdev shall we merge this PR?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996516558
##########
datafusion/functions-nested/src/dimension.rs:
##########
@@ -204,59 +194,57 @@ pub fn array_dims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array] = take_function_args("array_dims", args)?;
let data = match array.data_type() {
- List(_) => {
- let array = as_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- LargeList(_) => {
- let array = as_large_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- array_type => {
- return exec_err!("array_dims does not support type '{array_type:?}'");
+ List(_) => as_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ LargeList(_) => as_large_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ arg_type => {
+ return exec_err!(
+ "array_dims does not support an argument of type {arg_type}"
+ );
}
};
let result = ListArray::from_iter_primitive::<UInt64Type, _, _>(data);
-
- Ok(Arc::new(result) as ArrayRef)
+ Ok(Arc::new(result))
}
/// Array_ndims SQL function
pub fn array_ndims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
- let [array_dim] = take_function_args("array_ndims", args)?;
+ let [array] = take_function_args("array_ndims", args)?;
fn general_list_ndims<O: OffsetSizeTrait>(
array: &GenericListArray<O>,
) -> Result<ArrayRef> {
- let mut data = Vec::new();
- let ndims = datafusion_common::utils::list_ndims(array.data_type());
-
+ let mut builder = UInt64Builder::with_capacity(array.len());
+ let ndims = list_ndims(array.data_type());
for arr in array.iter() {
if arr.is_some() {
- data.push(Some(ndims))
+ builder.append_value(ndims)
Review Comment:
I remember that builder is slower than ::from(vec![])
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "sgrebnov (via GitHub)" <gi...@apache.org>.
sgrebnov commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r2296274979
##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -364,98 +366,67 @@ fn get_valid_types(
return Ok(vec![vec![]]);
}
- let array_idx = arguments.iter().enumerate().find_map(|(idx, arg)| {
- if *arg == ArrayFunctionArgument::Array {
- Some(idx)
- } else {
- None
- }
- });
- let Some(array_idx) = array_idx else {
- return Err(internal_datafusion_err!("Function '{function_name}' expected at least one argument array argument"));
- };
- let Some(array_type) = array(¤t_types[array_idx]) else {
- return Ok(vec![vec![]]);
- };
-
- // We need to find the coerced base type, mainly for cases like:
- // `array_append(List(null), i64)` -> `List(i64)`
- let mut new_base_type = datafusion_common::utils::base_type(&array_type);
- for (current_type, argument_type) in current_types.iter().zip(arguments.iter()) {
- match argument_type {
- ArrayFunctionArgument::Element | ArrayFunctionArgument::Array => {
- new_base_type =
- coerce_array_types(function_name, current_type, &new_base_type)?;
+ let mut large_list = false;
+ let mut fixed_size = array_coercion != Some(&ListCoercion::FixedSizedListToList);
+ let mut list_sizes = Vec::with_capacity(arguments.len());
+ let mut element_types = Vec::with_capacity(arguments.len());
+ for (argument, current_type) in arguments.iter().zip(current_types.iter()) {
+ match argument {
+ ArrayFunctionArgument::Index | ArrayFunctionArgument::String => (),
+ ArrayFunctionArgument::Element => {
+ element_types.push(current_type.clone())
}
- ArrayFunctionArgument::Index | ArrayFunctionArgument::String => {}
+ ArrayFunctionArgument::Array => match current_type {
+ DataType::Null => element_types.push(DataType::Null),
+ DataType::List(field) => {
+ element_types.push(field.data_type().clone());
+ fixed_size = false;
+ }
+ DataType::LargeList(field) => {
+ element_types.push(field.data_type().clone());
+ large_list = true;
+ fixed_size = false;
+ }
+ DataType::FixedSizeList(field, size) => {
+ element_types.push(field.data_type().clone());
+ list_sizes.push(*size)
+ }
+ arg_type => {
+ plan_err!("{function_name} does not support type {arg_type}")?
+ }
+ },
}
}
- let new_array_type = datafusion_common::utils::coerced_type_with_base_type_only(
- &array_type,
- &new_base_type,
- array_coercion,
- );
- let new_elem_type = match new_array_type {
- DataType::List(ref field)
- | DataType::LargeList(ref field)
- | DataType::FixedSizeList(ref field, _) => field.data_type(),
- _ => return Ok(vec![vec![]]),
+ let Some(element_type) = type_union_resolution(&element_types) else {
+ return Ok(vec![vec![]]);
};
- let mut valid_types = Vec::with_capacity(arguments.len());
- for (current_type, argument_type) in current_types.iter().zip(arguments.iter()) {
- let valid_type = match argument_type {
- ArrayFunctionArgument::Element => new_elem_type.clone(),
+ if !fixed_size {
+ list_sizes.clear()
+ }
+
+ let mut list_sizes = list_sizes.into_iter();
+ let valid_types = arguments.iter().zip(current_types.iter()).map(
+ |(argument_type, current_type)| match argument_type {
ArrayFunctionArgument::Index => DataType::Int64,
ArrayFunctionArgument::String => DataType::Utf8,
+ ArrayFunctionArgument::Element => element_type.clone(),
ArrayFunctionArgument::Array => {
- let Some(current_type) = array(current_type) else {
- return Ok(vec![vec![]]);
- };
- let new_type =
- datafusion_common::utils::coerced_type_with_base_type_only(
- ¤t_type,
- &new_base_type,
- array_coercion,
- );
- // All array arguments must be coercible to the same type
- if new_type != new_array_type {
- return Ok(vec![vec![]]);
+ if current_type.is_null() {
+ DataType::Null
+ } else if large_list {
+ DataType::new_large_list(element_type.clone(), true)
+ } else if let Some(size) = list_sizes.next() {
+ DataType::new_fixed_size_list(element_type.clone(), size, true)
+ } else {
+ DataType::new_list(element_type.clone(), true)
Review Comment:
It seems we are loosing information on original type elements nullability and just always return nullable:true here
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996516558
##########
datafusion/functions-nested/src/dimension.rs:
##########
@@ -204,59 +194,57 @@ pub fn array_dims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array] = take_function_args("array_dims", args)?;
let data = match array.data_type() {
- List(_) => {
- let array = as_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- LargeList(_) => {
- let array = as_large_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- array_type => {
- return exec_err!("array_dims does not support type '{array_type:?}'");
+ List(_) => as_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ LargeList(_) => as_large_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ arg_type => {
+ return exec_err!(
+ "array_dims does not support an argument of type {arg_type}"
+ );
}
};
let result = ListArray::from_iter_primitive::<UInt64Type, _, _>(data);
-
- Ok(Arc::new(result) as ArrayRef)
+ Ok(Arc::new(result))
}
/// Array_ndims SQL function
pub fn array_ndims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
- let [array_dim] = take_function_args("array_ndims", args)?;
+ let [array] = take_function_args("array_ndims", args)?;
fn general_list_ndims<O: OffsetSizeTrait>(
array: &GenericListArray<O>,
) -> Result<ArrayRef> {
- let mut data = Vec::new();
- let ndims = datafusion_common::utils::list_ndims(array.data_type());
-
+ let mut builder = UInt64Builder::with_capacity(array.len());
+ let ndims = list_ndims(array.data_type());
for arr in array.iter() {
if arr.is_some() {
- data.push(Some(ndims))
+ builder.append_value(ndims)
Review Comment:
build is slower
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "thinkharderdev (via GitHub)" <gi...@apache.org>.
thinkharderdev merged PR #15149:
URL: https://github.com/apache/datafusion/pull/15149
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996626461
##########
datafusion/expr-common/src/signature.rs:
##########
@@ -865,6 +867,39 @@ impl Signature {
volatility,
}
}
+
+ /// Specialized Signature for ArrayPrepend and similar functions
+ pub fn element_and_array(volatility: Volatility) -> Self {
+ Signature {
+ type_signature: TypeSignature::ArraySignature(
+ ArrayFunctionSignature::Array {
+ arguments: vec![
+ ArrayFunctionArgument::Element,
+ ArrayFunctionArgument::Array,
+ ],
+ array_coercion: Some(ListCoercion::FixedSizedListToList),
Review Comment:
Yep, that's why I'm setting `array_coercion: Some(ListCoercion::FixedSizedListToList)` by default 👍
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1997523937
##########
datafusion/functions-nested/src/dimension.rs:
##########
@@ -204,59 +194,57 @@ pub fn array_dims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array] = take_function_args("array_dims", args)?;
let data = match array.data_type() {
- List(_) => {
- let array = as_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- LargeList(_) => {
- let array = as_large_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- array_type => {
- return exec_err!("array_dims does not support type '{array_type:?}'");
+ List(_) => as_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ LargeList(_) => as_large_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ arg_type => {
+ return exec_err!(
+ "array_dims does not support an argument of type {arg_type}"
+ );
}
};
let result = ListArray::from_iter_primitive::<UInt64Type, _, _>(data);
-
- Ok(Arc::new(result) as ArrayRef)
+ Ok(Arc::new(result))
}
/// Array_ndims SQL function
pub fn array_ndims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
- let [array_dim] = take_function_args("array_ndims", args)?;
+ let [array] = take_function_args("array_ndims", args)?;
fn general_list_ndims<O: OffsetSizeTrait>(
array: &GenericListArray<O>,
) -> Result<ArrayRef> {
- let mut data = Vec::new();
- let ndims = datafusion_common::utils::list_ndims(array.data_type());
-
+ let mut builder = UInt64Builder::with_capacity(array.len());
+ let ndims = list_ndims(array.data_type());
for arr in array.iter() {
if arr.is_some() {
- data.push(Some(ndims))
+ builder.append_value(ndims)
Review Comment:
I optimized it to use `vec![ndims, array.len()]` and just clone the null buffer from the array
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "thinkharderdev (via GitHub)" <gi...@apache.org>.
thinkharderdev commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2764520144
> @thinkharderdev shall we merge this PR?
I think it's good to go. There are still some open comments so I was waiting for another approval, but if we're all agreed then we can merge it
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1993818465
##########
datafusion/expr-common/src/signature.rs:
##########
@@ -865,6 +867,39 @@ impl Signature {
volatility,
}
}
+
+ /// Specialized Signature for ArrayPrepend and similar functions
+ pub fn element_and_array(volatility: Volatility) -> Self {
+ Signature {
+ type_signature: TypeSignature::ArraySignature(
+ ArrayFunctionSignature::Array {
+ arguments: vec![
+ ArrayFunctionArgument::Element,
+ ArrayFunctionArgument::Array,
+ ],
+ array_coercion: Some(ListCoercion::FixedSizedListToList),
Review Comment:
From a type signature PoV yes, it's possible to infer that the return type should also be a fixed-size list with size `n + 1` but the implementation itself is not able to handle it:
```rust
pub(crate) fn array_append_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array, _] = take_function_args("array_append", args)?;
match array.data_type() {
DataType::LargeList(_) => general_append_and_prepend::<i64>(args, true),
_ => general_append_and_prepend::<i32>(args, true),
}
}
```
It's unclear to me how an implementation for `FixedSizeList` would look like and I would say probably it's out of scope for this PR, it should be separate.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996516558
##########
datafusion/functions-nested/src/dimension.rs:
##########
@@ -204,59 +194,57 @@ pub fn array_dims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array] = take_function_args("array_dims", args)?;
let data = match array.data_type() {
- List(_) => {
- let array = as_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- LargeList(_) => {
- let array = as_large_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- array_type => {
- return exec_err!("array_dims does not support type '{array_type:?}'");
+ List(_) => as_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ LargeList(_) => as_large_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ arg_type => {
+ return exec_err!(
+ "array_dims does not support an argument of type {arg_type}"
+ );
}
};
let result = ListArray::from_iter_primitive::<UInt64Type, _, _>(data);
-
- Ok(Arc::new(result) as ArrayRef)
+ Ok(Arc::new(result))
}
/// Array_ndims SQL function
pub fn array_ndims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
- let [array_dim] = take_function_args("array_ndims", args)?;
+ let [array] = take_function_args("array_ndims", args)?;
fn general_list_ndims<O: OffsetSizeTrait>(
array: &GenericListArray<O>,
) -> Result<ArrayRef> {
- let mut data = Vec::new();
- let ndims = datafusion_common::utils::list_ndims(array.data_type());
-
+ let mut builder = UInt64Builder::with_capacity(array.len());
+ let ndims = list_ndims(array.data_type());
for arr in array.iter() {
if arr.is_some() {
- data.push(Some(ndims))
+ builder.append_value(ndims)
Review Comment:
I remember that builder is slower than `UInt64Array::from(vec![])`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996528078
##########
datafusion/functions-nested/src/extract.rs:
##########
@@ -200,6 +199,7 @@ fn array_element_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array, indexes] = take_function_args("array_element", args)?;
match &array.data_type() {
+ Null => Ok(Arc::new(NullArray::new(array.len()))),
Review Comment:
can we return the null with List i64 type (a default one) ?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2721791427
Also added a commit to fix `array_sort` for empty record batches
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2737984916
I see there's a conflict, need to resolve it
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2833989444
This missed the v47 train. Anything else needed to merge?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2721223840
Perhaps @Dandandan or @thinkharderdev or @avantgardnerio could help review this PR
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2738001345
One more thing, we need a decision if intersection with null should return null or empty array. I can see arguments for both, but the important thing for me is that it should be commutative - flipping the arguments shouldn't change the result.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1997522277
##########
datafusion/functions-nested/src/extract.rs:
##########
@@ -200,6 +199,7 @@ fn array_element_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array, indexes] = take_function_args("array_element", args)?;
match &array.data_type() {
+ Null => Ok(Arc::new(NullArray::new(array.len()))),
Review Comment:
I added this query as a test:
`select coalesce(array_element([], 1), array_element(NULL, 1), 'ok');`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996627020
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -4408,12 +4422,10 @@ select array_union(arrow_cast([], 'LargeList(Int64)'), arrow_cast([], 'LargeList
query ?
select array_union([[null]], []);
----
-[[NULL]]
+[[]]
-query ?
+query error DataFusion error: Error during planning: Failed to unify argument types of array_union:
Review Comment:
The problem is that the argument types don't make sense. How are we supposed to union `LargeList(List(Int64))` and `LargeList(Int64)`?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996470664
##########
datafusion/expr-common/src/signature.rs:
##########
@@ -865,6 +867,39 @@ impl Signature {
volatility,
}
}
+
+ /// Specialized Signature for ArrayPrepend and similar functions
+ pub fn element_and_array(volatility: Volatility) -> Self {
+ Signature {
+ type_signature: TypeSignature::ArraySignature(
+ ArrayFunctionSignature::Array {
+ arguments: vec![
+ ArrayFunctionArgument::Element,
+ ArrayFunctionArgument::Array,
+ ],
+ array_coercion: Some(ListCoercion::FixedSizedListToList),
Review Comment:
Generally if the list size is changed like (append operation) we will convert it to List. so append with fixed-size-list ends up with List
##########
datafusion/expr-common/src/signature.rs:
##########
@@ -865,6 +867,39 @@ impl Signature {
volatility,
}
}
+
+ /// Specialized Signature for ArrayPrepend and similar functions
+ pub fn element_and_array(volatility: Volatility) -> Self {
+ Signature {
+ type_signature: TypeSignature::ArraySignature(
+ ArrayFunctionSignature::Array {
+ arguments: vec![
+ ArrayFunctionArgument::Element,
+ ArrayFunctionArgument::Array,
+ ],
+ array_coercion: Some(ListCoercion::FixedSizedListToList),
Review Comment:
Generally if the list size is changed like (append operation) we will convert it to List, so append with fixed-size-list ends up with List
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996627243
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -6232,12 +6244,12 @@ select array_intersect(arrow_cast([1, 1, 2, 2, 3, 3], 'LargeList(Int64)'), null)
query ?
select array_intersect(null, [1, 1, 2, 2, 3, 3]);
----
-NULL
+[]
Review Comment:
Above we have
```
query ?
select array_intersect([1, 1, 2, 2, 3, 3], null);
----
[]
```
So I think it's better that `array_intersect` is commutative. I can make both `null` or both empty list but I think it should be the same if we flip the arguments. Which one should it be?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996627420
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -6232,12 +6244,12 @@ select array_intersect(arrow_cast([1, 1, 2, 2, 3, 3], 'LargeList(Int64)'), null)
query ?
select array_intersect(null, [1, 1, 2, 2, 3, 3]);
----
-NULL
+[]
Review Comment:
Also, below we have:
```
query ?
select array_intersect([], null);
----
[]
```
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -6232,12 +6244,12 @@ select array_intersect(arrow_cast([1, 1, 2, 2, 3, 3], 'LargeList(Int64)'), null)
query ?
select array_intersect(null, [1, 1, 2, 2, 3, 3]);
----
-NULL
+[]
Review Comment:
Also, below we have:
```
query ?
select array_intersect([], null);
----
[]
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996628327
##########
datafusion/functions-nested/src/extract.rs:
##########
@@ -200,6 +199,7 @@ fn array_element_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array, indexes] = take_function_args("array_element", args)?;
match &array.data_type() {
+ Null => Ok(Arc::new(NullArray::new(array.len()))),
Review Comment:
Or in this case similar nested expression with array element
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "thinkharderdev (via GitHub)" <gi...@apache.org>.
thinkharderdev commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2739947657
> > I recommend following whatever DuckDB (or postgres do) -- there is not muchv alue in DataFusion having different semantics from other systems
>
> * DuckDB doesn't have union for arrays: https://duckdb.org/docs/stable/sql/functions/list.html
>
> * `list_intersect` is not commutative in DuckDB (I would consider this a bug)
> * `select list_intersect(NULL, [1,2,3]);` returns null
> * `select list_intersect([1,2,3], NULL);` returns empty list
> * Postgres has neither union, not intersect for arrays: https://www.postgresql.org/docs/current/functions-array.html
I agree that it should be commutative. In PG at least `array_cat` is commutative with `array_cat(ARRAY[1,2,3],NULL) <=> array_cat(NULL, ARRAY[1,2,3]) <=> {1,2,3}`
So I would voter for `list_intersect` with `NULL` arg to return empty list.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996129842
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -1204,7 +1204,7 @@ select array_element([1, 2], NULL);
----
NULL
-query I
+query ?
Review Comment:
FYI @jayzhan211 and @goldmedal
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996526816
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -3075,22 +3086,26 @@ select array_concat(
----
[1, 2, 3]
-# Concatenating Mixed types (doesn't work)
-query error DataFusion error: Error during planning: It is not possible to concatenate arrays of different types\. Expected: List\(Field \{ name: "item", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: \{\} \}\), got: List\(Field \{ name: "item", data_type: LargeUtf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: \{\} \}\)
+# Concatenating Mixed types
+query ?
select array_concat(
[arrow_cast('1', 'Utf8'), arrow_cast('2', 'Utf8')],
[arrow_cast('3', 'LargeUtf8')]
);
+----
+[1, 2, 3]
-# Concatenating Mixed types (doesn't work)
-query error DataFusion error: Error during planning: It is not possible to concatenate arrays of different types\. Expected: List\(Field \{ name: "item", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: \{\} \}\), got: List\(Field \{ name: "item", data_type: Utf8View, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: \{\} \}\)
+# Concatenating Mixed types
+query ?
select array_concat(
[arrow_cast('1', 'Utf8'), arrow_cast('2', 'Utf8')],
[arrow_cast('3', 'Utf8View')]
);
+----
+[1, 2, 3]
Review Comment:
it would be nice to show the type
```
select arrow_typeof(array_concat(
[arrow_cast('1', 'Utf8'), arrow_cast('2', 'Utf8')],
[arrow_cast('3', 'Utf8View')]
));
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996511821
##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -364,98 +366,73 @@ fn get_valid_types(
return Ok(vec![vec![]]);
}
- let array_idx = arguments.iter().enumerate().find_map(|(idx, arg)| {
- if *arg == ArrayFunctionArgument::Array {
- Some(idx)
- } else {
- None
- }
- });
- let Some(array_idx) = array_idx else {
- return Err(internal_datafusion_err!("Function '{function_name}' expected at least one argument array argument"));
- };
- let Some(array_type) = array(¤t_types[array_idx]) else {
- return Ok(vec![vec![]]);
- };
+ let mut fixed_size = None;
+ let mut large_list = false;
+ let mut element_types = Vec::with_capacity(arguments.len());
+ for (argument, current_type) in arguments.iter().zip(current_types.iter()) {
+ match argument {
+ ArrayFunctionArgument::Array => match current_type {
+ DataType::FixedSizeList(field, size) => {
+ match array_coercion {
+ Some(ListCoercion::FixedSizedListToList) => (),
+ None if fixed_size.is_none() => fixed_size = Some(*size),
+ None if fixed_size == Some(*size) => (),
Review Comment:
if there are more than one fixed size list types like fixed(4), fixed(3).
The valid types should be `vec![fixed(4), fixed(3)]`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996627956
##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -364,98 +366,73 @@ fn get_valid_types(
return Ok(vec![vec![]]);
}
- let array_idx = arguments.iter().enumerate().find_map(|(idx, arg)| {
- if *arg == ArrayFunctionArgument::Array {
- Some(idx)
- } else {
- None
- }
- });
- let Some(array_idx) = array_idx else {
- return Err(internal_datafusion_err!("Function '{function_name}' expected at least one argument array argument"));
- };
- let Some(array_type) = array(¤t_types[array_idx]) else {
- return Ok(vec![vec![]]);
- };
+ let mut fixed_size = None;
+ let mut large_list = false;
+ let mut element_types = Vec::with_capacity(arguments.len());
+ for (argument, current_type) in arguments.iter().zip(current_types.iter()) {
+ match argument {
+ ArrayFunctionArgument::Array => match current_type {
+ DataType::FixedSizeList(field, size) => {
+ match array_coercion {
+ Some(ListCoercion::FixedSizedListToList) => (),
+ None if fixed_size.is_none() => fixed_size = Some(*size),
+ None if fixed_size == Some(*size) => (),
Review Comment:
Oh, I see what you mean. I will fix that. `current_type` is not unified so we can't return that.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1997523937
##########
datafusion/functions-nested/src/dimension.rs:
##########
@@ -204,59 +194,57 @@ pub fn array_dims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array] = take_function_args("array_dims", args)?;
let data = match array.data_type() {
- List(_) => {
- let array = as_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- LargeList(_) => {
- let array = as_large_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- array_type => {
- return exec_err!("array_dims does not support type '{array_type:?}'");
+ List(_) => as_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ LargeList(_) => as_large_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ arg_type => {
+ return exec_err!(
+ "array_dims does not support an argument of type {arg_type}"
+ );
}
};
let result = ListArray::from_iter_primitive::<UInt64Type, _, _>(data);
-
- Ok(Arc::new(result) as ArrayRef)
+ Ok(Arc::new(result))
}
/// Array_ndims SQL function
pub fn array_ndims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
- let [array_dim] = take_function_args("array_ndims", args)?;
+ let [array] = take_function_args("array_ndims", args)?;
fn general_list_ndims<O: OffsetSizeTrait>(
array: &GenericListArray<O>,
) -> Result<ArrayRef> {
- let mut data = Vec::new();
- let ndims = datafusion_common::utils::list_ndims(array.data_type());
-
+ let mut builder = UInt64Builder::with_capacity(array.len());
+ let ndims = list_ndims(array.data_type());
for arr in array.iter() {
if arr.is_some() {
- data.push(Some(ndims))
+ builder.append_value(ndims)
Review Comment:
I optimized it to use `vec![ndims; array.len()]` and just clone the null buffer from the array
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2738297657
> One more thing, we need a decision if intersection with null should return null or empty array. I can see arguments for both, but the important thing for me is that it should be commutative - flipping the arguments shouldn't change the result.
I recommend following whatever DuckDB (or postgres do) -- there is not muchv alue in DataFusion having different semantics from other systems
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "thinkharderdev (via GitHub)" <gi...@apache.org>.
thinkharderdev commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1993793767
##########
datafusion/expr-common/src/signature.rs:
##########
@@ -865,6 +867,39 @@ impl Signature {
volatility,
}
}
+
+ /// Specialized Signature for ArrayPrepend and similar functions
+ pub fn element_and_array(volatility: Volatility) -> Self {
+ Signature {
+ type_signature: TypeSignature::ArraySignature(
+ ArrayFunctionSignature::Array {
+ arguments: vec![
+ ArrayFunctionArgument::Element,
+ ArrayFunctionArgument::Array,
+ ],
+ array_coercion: Some(ListCoercion::FixedSizedListToList),
Review Comment:
tbh I'm not entirely clear on how the coercion comes into play but an append to a fixed size list would still be a fixed size list right?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996526106
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -4408,12 +4422,10 @@ select array_union(arrow_cast([], 'LargeList(Int64)'), arrow_cast([], 'LargeList
query ?
select array_union([[null]], []);
----
-[[NULL]]
+[[]]
-query ?
+query error DataFusion error: Error during planning: Failed to unify argument types of array_union:
Review Comment:
It seems so @joroKr21 can we keep null?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996628218
##########
datafusion/functions-nested/src/extract.rs:
##########
@@ -200,6 +199,7 @@ fn array_element_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array, indexes] = take_function_args("array_element", args)?;
match &array.data_type() {
+ Null => Ok(Arc::new(NullArray::new(array.len()))),
Review Comment:
I will write a test that shows the issue. But basically something like `array_union(make_array(), ['x', 'y', 'z'])` will be an issue because we can't union a list of ints and a list of strings.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2841686423
The issue has been fixed. Thank you for the quick response
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996528078
##########
datafusion/functions-nested/src/extract.rs:
##########
@@ -200,6 +199,7 @@ fn array_element_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array, indexes] = take_function_args("array_element", args)?;
match &array.data_type() {
+ Null => Ok(Arc::new(NullArray::new(array.len()))),
Review Comment:
can we return the null with List type?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996526390
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -6232,12 +6244,12 @@ select array_intersect(arrow_cast([1, 1, 2, 2, 3, 3], 'LargeList(Int64)'), null)
query ?
select array_intersect(null, [1, 1, 2, 2, 3, 3]);
----
-NULL
+[]
Review Comment:
is it possible to keep null?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2726151394
When we return `Null`, can we return with type other than null, for example List::i64 for list type, i64 for non-list type. I guess this reduce the null case we need to handle
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996513936
##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -364,98 +366,73 @@ fn get_valid_types(
return Ok(vec![vec![]]);
}
- let array_idx = arguments.iter().enumerate().find_map(|(idx, arg)| {
- if *arg == ArrayFunctionArgument::Array {
- Some(idx)
- } else {
- None
- }
- });
- let Some(array_idx) = array_idx else {
- return Err(internal_datafusion_err!("Function '{function_name}' expected at least one argument array argument"));
- };
- let Some(array_type) = array(¤t_types[array_idx]) else {
- return Ok(vec![vec![]]);
- };
+ let mut fixed_size = None;
+ let mut large_list = false;
+ let mut element_types = Vec::with_capacity(arguments.len());
+ for (argument, current_type) in arguments.iter().zip(current_types.iter()) {
+ match argument {
+ ArrayFunctionArgument::Array => match current_type {
+ DataType::FixedSizeList(field, size) => {
+ match array_coercion {
+ Some(ListCoercion::FixedSizedListToList) => (),
+ None if fixed_size.is_none() => fixed_size = Some(*size),
+ None if fixed_size == Some(*size) => (),
Review Comment:
If we found more than 1 fixed size list, return list might be the easier solution 🤔
##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -364,98 +366,73 @@ fn get_valid_types(
return Ok(vec![vec![]]);
}
- let array_idx = arguments.iter().enumerate().find_map(|(idx, arg)| {
- if *arg == ArrayFunctionArgument::Array {
- Some(idx)
- } else {
- None
- }
- });
- let Some(array_idx) = array_idx else {
- return Err(internal_datafusion_err!("Function '{function_name}' expected at least one argument array argument"));
- };
- let Some(array_type) = array(¤t_types[array_idx]) else {
- return Ok(vec![vec![]]);
- };
+ let mut fixed_size = None;
+ let mut large_list = false;
+ let mut element_types = Vec::with_capacity(arguments.len());
+ for (argument, current_type) in arguments.iter().zip(current_types.iter()) {
+ match argument {
+ ArrayFunctionArgument::Array => match current_type {
+ DataType::FixedSizeList(field, size) => {
+ match array_coercion {
+ Some(ListCoercion::FixedSizedListToList) => (),
+ None if fixed_size.is_none() => fixed_size = Some(*size),
+ None if fixed_size == Some(*size) => (),
Review Comment:
If we found more than 1 fixed size list, return list might be the easiest solution 🤔
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996515968
##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -364,98 +366,73 @@ fn get_valid_types(
return Ok(vec![vec![]]);
}
- let array_idx = arguments.iter().enumerate().find_map(|(idx, arg)| {
- if *arg == ArrayFunctionArgument::Array {
- Some(idx)
- } else {
- None
- }
- });
- let Some(array_idx) = array_idx else {
- return Err(internal_datafusion_err!("Function '{function_name}' expected at least one argument array argument"));
- };
- let Some(array_type) = array(¤t_types[array_idx]) else {
- return Ok(vec![vec![]]);
- };
+ let mut fixed_size = None;
+ let mut large_list = false;
+ let mut element_types = Vec::with_capacity(arguments.len());
+ for (argument, current_type) in arguments.iter().zip(current_types.iter()) {
+ match argument {
+ ArrayFunctionArgument::Array => match current_type {
+ DataType::FixedSizeList(field, size) => {
+ match array_coercion {
+ Some(ListCoercion::FixedSizedListToList) => (),
+ None if fixed_size.is_none() => fixed_size = Some(*size),
+ None if fixed_size == Some(*size) => (),
Review Comment:
But return the `current_type` makes more sense.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1997511842
##########
datafusion/functions-nested/src/dimension.rs:
##########
@@ -204,59 +194,57 @@ pub fn array_dims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
let [array] = take_function_args("array_dims", args)?;
let data = match array.data_type() {
- List(_) => {
- let array = as_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- LargeList(_) => {
- let array = as_large_list_array(&array)?;
- array
- .iter()
- .map(compute_array_dims)
- .collect::<Result<Vec<_>>>()?
- }
- array_type => {
- return exec_err!("array_dims does not support type '{array_type:?}'");
+ List(_) => as_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ LargeList(_) => as_large_list_array(&array)?
+ .iter()
+ .map(compute_array_dims)
+ .collect::<Result<Vec<_>>>()?,
+ arg_type => {
+ return exec_err!(
+ "array_dims does not support an argument of type {arg_type}"
+ );
}
};
let result = ListArray::from_iter_primitive::<UInt64Type, _, _>(data);
-
- Ok(Arc::new(result) as ArrayRef)
+ Ok(Arc::new(result))
}
/// Array_ndims SQL function
pub fn array_ndims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
- let [array_dim] = take_function_args("array_ndims", args)?;
+ let [array] = take_function_args("array_ndims", args)?;
fn general_list_ndims<O: OffsetSizeTrait>(
array: &GenericListArray<O>,
) -> Result<ArrayRef> {
- let mut data = Vec::new();
- let ndims = datafusion_common::utils::list_ndims(array.data_type());
-
+ let mut builder = UInt64Builder::with_capacity(array.len());
+ let ndims = list_ndims(array.data_type());
for arr in array.iter() {
if arr.is_some() {
- data.push(Some(ndims))
+ builder.append_value(ndims)
Review Comment:
Wow, that sounds pretty bad
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996471597
##########
datafusion/expr-common/src/signature.rs:
##########
@@ -865,6 +867,39 @@ impl Signature {
volatility,
}
}
+
+ /// Specialized Signature for ArrayPrepend and similar functions
+ pub fn element_and_array(volatility: Volatility) -> Self {
+ Signature {
+ type_signature: TypeSignature::ArraySignature(
+ ArrayFunctionSignature::Array {
+ arguments: vec![
+ ArrayFunctionArgument::Element,
+ ArrayFunctionArgument::Array,
+ ],
+ array_coercion: Some(ListCoercion::FixedSizedListToList),
Review Comment:
What we need is to provide customizable signature, so if they want List for append, they can add `array_coercion: Some(ListCoercion::FixedSizedListToList)`, if they want to keep fixed-size-list they can add `array_coercion: None`. Both cases should be possible.
For datafusion implementation, we choose to convert to List by default
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1996471597
##########
datafusion/expr-common/src/signature.rs:
##########
@@ -865,6 +867,39 @@ impl Signature {
volatility,
}
}
+
+ /// Specialized Signature for ArrayPrepend and similar functions
+ pub fn element_and_array(volatility: Volatility) -> Self {
+ Signature {
+ type_signature: TypeSignature::ArraySignature(
+ ArrayFunctionSignature::Array {
+ arguments: vec![
+ ArrayFunctionArgument::Element,
+ ArrayFunctionArgument::Array,
+ ],
+ array_coercion: Some(ListCoercion::FixedSizedListToList),
Review Comment:
What we need is to provide customizable signature, so if they want List for append, they can add `array_coercion: Some(ListCoercion::FixedSizedListToList)`, if they want to keep fixed-size-list they can add `array_coercion: None`. Both cases should be possible.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2737814758
Is this one ready for merge?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "thinkharderdev (via GitHub)" <gi...@apache.org>.
thinkharderdev commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2838284869
> This missed the v47 train. Anything else needed to merge?
@alamb @jayzhan211 Are you guys good with this?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2840909664
Looks like a semantic merge conflict with #15160
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2840387613
It appears the tests started failing on main after this PR was merged:
- https://github.com/apache/datafusion/actions/runs/14740728702/job/41378119017
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Saner handling of nulls inside arrays [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#issuecomment-2841023652
#15899
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org