You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "blaginin (via GitHub)" <gi...@apache.org> on 2024/11/16 17:11:35 UTC
[PR] Coerce Array inner types [datafusion]
blaginin opened a new pull request, #13452:
URL: https://github.com/apache/datafusion/pull/13452
## Which issue does this PR close?
Closes #12291
## Rationale for this change
Currently, we don't attempt to coerce inner list types, and so this works (although it shouldn't)
```sql
SELECT make_array(2) x UNION ALL SELECT make_array(now()) x;
```
## What changes are included in this PR?
Now we’ll try to coerce inner types instead of just using the type of the first array.
## Are these changes tested?
Yes, added a test
## Are there any user-facing changes?
No
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1848967601
##########
datafusion/functions-nested/src/make_array.rs:
##########
@@ -198,7 +198,6 @@ pub(crate) fn make_array_inner(arrays: &[ArrayRef]) -> Result<ArrayRef> {
let array = new_null_array(&DataType::Int64, length);
Ok(Arc::new(array_into_list_array_nullable(array)))
}
- LargeList(..) => array_array::<i64>(arrays, data_type),
Review Comment:
I don't think this line was correct. According to the signature, the function output is always a `List`. However, this one sometimes returns a `LargeList`.
I added a test to illustrate this:
https://github.com/apache/datafusion/blob/91b468d0f337a73c65021c50ce889890cde9bccf/datafusion/sqllogictest/test_files/array.slt#L1160
--
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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845132858
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+macro_rules! coerce_list_children {
+ ($LHS_TYPE:expr, $RHS_TYPE:expr) => {
+ Arc::new(Arc::unwrap_or_clone(Arc::clone($LHS_TYPE)).with_data_type(
+ comparison_coercion($LHS_TYPE.data_type(), $RHS_TYPE.data_type())?,
+ ))
+ };
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (List(lhs_field), List(rhs_field))
+ | (List(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), List(rhs_field)) => {
+ Some(List(coerce_list_children!(lhs_field, rhs_field)))
+ }
+
+ (LargeList(lhs_field), List(rhs_field))
+ | (List(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), LargeList(rhs_field)) => {
+ Some(LargeList(coerce_list_children!(lhs_field, rhs_field)))
Review Comment:
see https://github.com/apache/datafusion/issues/13325#issuecomment-2479607530 for example
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#issuecomment-2481839966
```
query error DataFusion error: type_coercion\ncaused by\nError during planning: Incompatible inputs for Union: Previous inputs were of type List(.*), but got incompatible type List(.*) on column 'x'
SELECT make_array(2) x UNION ALL SELECT make_array(now()) x;
query ?
select make_array(arrow_cast(2, 'UInt8')) x UNION ALL SELECT make_array(arrow_cast(-2, 'Int8')) x;
----
[-2]
[2]
```
The queries has nothing to do with the list coercion.
I checked the query and it already works correctly in main branch.
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1850200368
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1134,46 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+/// Coerces two fields together, ensuring the field data (name and nullability) is correctly set.
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ let data_types = vec![lhs_field.data_type().clone(), rhs_field.data_type().clone()];
+ Some(Arc::new(
+ (**lhs_field)
+ .clone()
+ .with_data_type(type_union_resolution(&data_types)?)
+ .with_nullable(lhs_field.is_nullable() || rhs_field.is_nullable()),
+ ))
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (
+ LargeList(lhs_field),
+ List(rhs_field) | LargeList(rhs_field) | FixedSizeList(rhs_field, _),
Review Comment:
Is ListView already supported in arrow? I would prefer to handle list view if there is corresponding test as well.
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1850744670
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1134,46 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+/// Coerces two fields together, ensuring the field data (name and nullability) is correctly set.
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ let data_types = vec![lhs_field.data_type().clone(), rhs_field.data_type().clone()];
+ Some(Arc::new(
+ (**lhs_field)
+ .clone()
+ .with_data_type(type_union_resolution(&data_types)?)
+ .with_nullable(lhs_field.is_nullable() || rhs_field.is_nullable()),
+ ))
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (
+ LargeList(lhs_field),
+ List(rhs_field) | LargeList(rhs_field) | FixedSizeList(rhs_field, _),
Review Comment:
TBH I'd as well would handle this separately with a proper test. I'll put a ticket
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#issuecomment-2480687262
That was a very fast review 😅🙏
--
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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1849980264
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1134,46 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+/// Coerces two fields together, ensuring the field data (name and nullability) is correctly set.
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ let data_types = vec![lhs_field.data_type().clone(), rhs_field.data_type().clone()];
+ Some(Arc::new(
+ (**lhs_field)
+ .clone()
+ .with_data_type(type_union_resolution(&data_types)?)
+ .with_nullable(lhs_field.is_nullable() || rhs_field.is_nullable()),
+ ))
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (
+ LargeList(lhs_field),
+ List(rhs_field) | LargeList(rhs_field) | FixedSizeList(rhs_field, _),
Review Comment:
- Let's maybe add listview to the mix. it's hard to test, but why not be future-proof here?
- let's maybe reorder clauses so that it's clear that any list types are handled
```rust
match (lhs_type, rhs_type) {
// Coerce to the left side FixedSizeList type if the list lengths are the same,
// otherwise coerce to list with the left type for dynamic length
(FixedSizeList(lhs_field, ls), FixedSizeList(rhs_field, rs)) if ls == rs => Some(
FixedSizeList(coerce_list_children(lhs_field, rhs_field)?, *rs),
),
// Left is a LargeList[View] or right is a LargeList[View]
(
LargeList(lhs_field) | LargeListView(lhs_field),
List(rhs_field)
| ListView(rhs_field)
| LargeList(rhs_field)
| LargeListView(rhs_field)
| FixedSizeList(rhs_field, _),
)
| (
List(lhs_field)
| ListView(lhs_field)
| FixedSizeList(lhs_field, _)
| LargeList(lhs_field)
| LargeListView(lhs_field),
LargeList(rhs_field) | LargeListView(rhs_field),
) => Some(LargeList(coerce_list_children(lhs_field, rhs_field)?)),
// Left and right are lists
(
List(lhs_field) | ListView(lhs_field) | FixedSizeList(lhs_field, _),
List(rhs_field) | ListView(rhs_field) | FixedSizeList(rhs_field, _),
) => Some(List(coerce_list_children(lhs_field, rhs_field)?)),
_ => None,
}
```
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1848706493
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
Okay, that's fair! I've switched to `type_union_resolution` and will create a ticket to handle large arrays and nulls
--
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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1848081174
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
i am fine assuming the answer to this question is 'nope':
_can there be a problem if we coerce two lists and they have different field names?_
i hope it is 'nope, no problem'
@alamb @jayzhan211 please confirm
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1849445797
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -1155,6 +1155,12 @@ select column1, column5 from arrays_values_without_nulls;
[21, 22, 23, 24, 25, 26, 27, 28, 29, 30] [6, 7]
[31, 32, 33, 34, 35, 26, 37, 38, 39, 40] [8, 9]
+# make array with arrays of different types
+query ?
+select make_array(make_array(1), arrow_cast(make_array(-1), 'LargeList(Int8)'))
+----
+[[1], [-1]]
Review Comment:
```suggestion
[[1], [-1]]
query T
select arrow_typeof(make_array(make_array(1), arrow_cast(make_array(-1), 'LargeList(Int8)')));
----
List(Field { name: "item", data_type: LargeList(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })
```
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1850744915
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1134,46 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+/// Coerces two fields together, ensuring the field data (name and nullability) is correctly set.
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ let data_types = vec![lhs_field.data_type().clone(), rhs_field.data_type().clone()];
+ Some(Arc::new(
+ (**lhs_field)
+ .clone()
+ .with_data_type(type_union_resolution(&data_types)?)
+ .with_nullable(lhs_field.is_nullable() || rhs_field.is_nullable()),
+ ))
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (
+ LargeList(lhs_field),
+ List(rhs_field) | LargeList(rhs_field) | FixedSizeList(rhs_field, _),
Review Comment:
but will reorder the arms
--
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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845466179
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
@alamb can there be a problem if we coerce two lists and they have different field _names_?
@blaginin the resulting field nullability should be OR of nullability of sources
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
+ lhs_field.data_type(),
+ rhs_field.data_type(),
+ )?),
+ ))
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (
+ LargeList(lhs_field),
+ List(rhs_field) | LargeList(rhs_field) | FixedSizeList(rhs_field, _),
+ )
+ | (FixedSizeList(lhs_field, _) | List(lhs_field), LargeList(rhs_field)) => {
Review Comment:
maintain consistent ordering to make the code easier to follow
```suggestion
| (List(lhs_field) | FixedSizeList(lhs_field, _) , LargeList(rhs_field)) => {
```
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
+ lhs_field.data_type(),
+ rhs_field.data_type(),
+ )?),
+ ))
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
Review Comment:
You can add some test cases of what used to fail and now it doesn't.
For example query unioning list(uint8) with list(int32) where right values don't fit int8 (too big or negative).
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
`Arc::unwrap_or_clone` feels unnecessarly indirect, given the fact we know for sure that there are 2+ arcs to the field.
Use ordinary clone
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
> comparison_coercion
should we use `type_union_resolution` 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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845825232
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
I think we should use `type_union_resolution` here since we need to preserve dictionary when we union two array. But comparison coercion we don't preserve dictionary type, only inner type matters
--
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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845129045
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+macro_rules! coerce_list_children {
+ ($LHS_TYPE:expr, $RHS_TYPE:expr) => {
+ Arc::new(Arc::unwrap_or_clone(Arc::clone($LHS_TYPE)).with_data_type(
+ comparison_coercion($LHS_TYPE.data_type(), $RHS_TYPE.data_type())?,
+ ))
+ };
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (List(lhs_field), List(rhs_field))
+ | (List(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), List(rhs_field)) => {
+ Some(List(coerce_list_children!(lhs_field, rhs_field)))
+ }
+
+ (LargeList(lhs_field), List(rhs_field))
+ | (List(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), LargeList(rhs_field)) => {
+ Some(LargeList(coerce_list_children!(lhs_field, rhs_field)))
Review Comment:
nit: handle large list first
nit2 the pattern will be simpler if you put `|`s inside the `(..., ...)`
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+macro_rules! coerce_list_children {
+ ($LHS_TYPE:expr, $RHS_TYPE:expr) => {
+ Arc::new(Arc::unwrap_or_clone(Arc::clone($LHS_TYPE)).with_data_type(
+ comparison_coercion($LHS_TYPE.data_type(), $RHS_TYPE.data_type())?,
+ ))
+ };
+}
Review Comment:
Can this be an ordinary function?
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+macro_rules! coerce_list_children {
+ ($LHS_TYPE:expr, $RHS_TYPE:expr) => {
+ Arc::new(Arc::unwrap_or_clone(Arc::clone($LHS_TYPE)).with_data_type(
+ comparison_coercion($LHS_TYPE.data_type(), $RHS_TYPE.data_type())?,
+ ))
+ };
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (List(lhs_field), List(rhs_field))
+ | (List(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), List(rhs_field)) => {
+ Some(List(coerce_list_children!(lhs_field, rhs_field)))
+ }
+
+ (LargeList(lhs_field), List(rhs_field))
+ | (List(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), LargeList(rhs_field)) => {
+ Some(LargeList(coerce_list_children!(lhs_field, rhs_field)))
+ }
+
// Coerce to the left side FixedSizeList type if the list lengths are the same,
// otherwise coerce to list with the left type for dynamic length
- (FixedSizeList(lf, ls), FixedSizeList(_, rs)) => {
+ (FixedSizeList(lhs_field, ls), FixedSizeList(rhs_field, rs)) => {
if ls == rs {
- Some(lhs_type.clone())
+ Some(FixedSizeList(
+ coerce_list_children!(lhs_field, rhs_field),
+ *rs,
+ ))
} else {
- Some(List(Arc::clone(lf)))
+ Some(List(Arc::clone(lhs_field)))
Review Comment:
coerce_list_elements here to
--
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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845180708
##########
datafusion/sqllogictest/test_files/union.slt:
##########
@@ -763,9 +763,5 @@ SELECT NULL WHERE FALSE;
1
# Test Union of List Types. Issue: https://github.com/apache/datafusion/issues/12291
-query error
-SELECT make_array(2) x UNION ALL SELECT make_array(now()) x;
-----
-DataFusion error: type_coercion
-caused by
-Error during planning: Incompatible inputs for Union: Previous inputs were of type List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), but got incompatible type List(Field { name: "item", data_type: Timestamp(Nanosecond, Some("+00:00")), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }) on column 'x'
+query error DataFusion error: type_coercion
Review Comment:
This works, but doesn't prove that the error message is useful and actionable when end user sees it.
Let's include more detail. It's ok to keep full error message, or write a pattern to make it shorter.
--
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] Coerce Array inner types [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#issuecomment-2489647429
@jayzhan211 are you good to 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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1849952529
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
I think https://github.com/apache/datafusion/issues/13481 is a complain that list item name isn't preserved in some cases. I don't know when it would matter though. From SQL perspective, it shouldn'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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1849444068
##########
datafusion/functions-nested/src/make_array.rs:
##########
@@ -198,7 +198,6 @@ pub(crate) fn make_array_inner(arrays: &[ArrayRef]) -> Result<ArrayRef> {
let array = new_null_array(&DataType::Int64, length);
Ok(Arc::new(array_into_list_array_nullable(array)))
}
- LargeList(..) => array_array::<i64>(arrays, data_type),
Review Comment:
```
query ?
select make_array(make_array(1), arrow_cast(make_array(-1), 'LargeList(Int8)'));
----
[[1], [-1]]
query T
select arrow_typeof(make_array(make_array(1), arrow_cast(make_array(-1), 'LargeList(Int8)')));
----
List(Field { name: "item", data_type: LargeList(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })
```
It seems correct 🤔 ?
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1848967601
##########
datafusion/functions-nested/src/make_array.rs:
##########
@@ -198,7 +198,6 @@ pub(crate) fn make_array_inner(arrays: &[ArrayRef]) -> Result<ArrayRef> {
let array = new_null_array(&DataType::Int64, length);
Ok(Arc::new(array_into_list_array_nullable(array)))
}
- LargeList(..) => array_array::<i64>(arrays, data_type),
Review Comment:
I don't think this line was correct. According to the signature, the function output is always a List. However, this one sometimes returns a LargeList.
I added a test to illustrate this:
https://github.com/apache/datafusion/blob/91b468d0f337a73c65021c50ce889890cde9bccf/datafusion/sqllogictest/test_files/array.slt#L1160
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1846981214
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
Given that this PR doesn’t change names behaviour, let’s go as is and then fix it separately in that PR you highlighted?
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845634892
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
So both will work, but IMO the current version is a bit better as it makes code aligned with the dictionally behaviour (`dictionary_comparison_coercion` uses `comparison_coercion`)
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1847603879
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
```
query T
select arrow_typeof(x) from (select make_array(arrow_cast('a', 'Dictionary(Int8, Utf8)')) x UNION ALL SELECT make_array(arrow_cast('b', 'Dictionary(Int8, LargeUtf8)'))) x;
----
List(Field { name: "item", data_type: LargeUtf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })
List(Field { name: "item", data_type: LargeUtf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })
```
Shouldn't the result be like
```
query T
select arrow_typeof(x) from (select make_array(arrow_cast('a', 'Dictionary(Int8, Utf8)')) x UNION ALL SELECT make_array(arrow_cast('b', 'Dictionary(Int8, LargeUtf8)'))) x;
----
List(Field { name: "item", data_type: Dict(), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })
List(Field { name: "item", data_type: Dict(), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })
```
--
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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1846963480
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
https://github.com/apache/datafusion/pull/13468 seems related to 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] Coerce Array inner types [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1848248080
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,47 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
Review Comment:
Could you add a comment here explaining why this function is needed -- specifically that it is setting the DataType / field name correctly?
--
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] Coerce Array inner types [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1848246249
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
I don't think there is any problem in theory. I am a little fuzzy about what the semantic meaning of the Field's name in a `DataType::List` means -- sometimes the code is overly pedantic when comparing but I think semantically two lists are the same if their element's types are the same (and nullness and metadata). I don't think the field name should be compared
However, I remember there have been issues before on this point
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1849445122
##########
datafusion/functions-nested/src/make_array.rs:
##########
@@ -198,7 +198,6 @@ pub(crate) fn make_array_inner(arrays: &[ArrayRef]) -> Result<ArrayRef> {
let array = new_null_array(&DataType::Int64, length);
Ok(Arc::new(array_into_list_array_nullable(array)))
}
- LargeList(..) => array_array::<i64>(arrays, data_type),
Review Comment:
I see. You fix it :) Thanks
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1850200368
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1134,46 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+/// Coerces two fields together, ensuring the field data (name and nullability) is correctly set.
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ let data_types = vec![lhs_field.data_type().clone(), rhs_field.data_type().clone()];
+ Some(Arc::new(
+ (**lhs_field)
+ .clone()
+ .with_data_type(type_union_resolution(&data_types)?)
+ .with_nullable(lhs_field.is_nullable() || rhs_field.is_nullable()),
+ ))
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (
+ LargeList(lhs_field),
+ List(rhs_field) | LargeList(rhs_field) | FixedSizeList(rhs_field, _),
Review Comment:
Is ListView already supported in arrow? I would prefer to handle list view if there is corresponding test as well to ensure the test coverage
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 merged PR #13452:
URL: https://github.com/apache/datafusion/pull/13452
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845825232
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
I think we should use `type_union_resolution` here since we need to preserve dictionary when we union two array. But comparison coercion doesn't preserve dictionary type, only inner type matters
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1847604516
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
> Also, I think type_union_resolution is a bit more limiting than comparison_coercion, and so, for example, if I switch to it, the following two queries will stop working
It indicates we need to handle more coercion for `type_union_resolution`.
`dictionary_comparison_coercion ` should not preserve dict if both are dict. There is a logic to **optionally preserve dict if one of them is dict, one is not**
--
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] Coerce Array inner types [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1848078597
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
`greatest(x, y, z)` should be equivalent to `select max(a) from select x as a union all select y as a select z as a` and also should be equivalent to `select array_max(array[x, y, z])`
all these should converge x, y, z to the common super type, and i believe type_union_resolution is supposedly doing just 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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1847145537
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}
}
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
+ Some(Arc::new(
+ Arc::unwrap_or_clone(Arc::clone(lhs_field)).with_data_type(comparison_coercion(
Review Comment:
I may have misunderstood your point, but I am pretty sure `comparison_coercion` preserves dicts:
https://github.com/apache/datafusion/blob/22c1f54411a02009629b3a76a43bd4343add045d/datafusion/expr-common/src/type_coercion/binary.rs#L637
For example, this query correctly casts `Dict(Utf8)` to `Dict(LargeUtf8)`
```sql
select arrow_typeof(x) from (select make_array(arrow_cast('a', 'Dictionary(Int8, Utf8)')) x UNION ALL SELECT make_array(arrow_cast('b', 'Dictionary(Int8, LargeUtf8)'))) x;
```
Also, I think `type_union_resolution` is a bit more limiting than `comparison_coercion`, and so, for example, if I switch to it, the following two queries will stop working:
```sql
-- type_union_resolution can't cast nulls
select make_array(arrow_cast('a', 'Utf8')) x UNION ALL SELECT make_array(NULL) x;
-- type_union_resolution can't handle large lists (or fixed lists)
select make_array(make_array(1)) x UNION ALL SELECT make_array(arrow_cast(make_array(-1), 'LargeList(Int8)')) x;
```
--
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] Coerce Array inner types [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845189844
##########
datafusion/sqllogictest/test_files/union.slt:
##########
@@ -763,9 +763,5 @@ SELECT NULL WHERE FALSE;
1
# Test Union of List Types. Issue: https://github.com/apache/datafusion/issues/12291
-query error
-SELECT make_array(2) x UNION ALL SELECT make_array(now()) x;
-----
-DataFusion error: type_coercion
-caused by
-Error during planning: Incompatible inputs for Union: Previous inputs were of type List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), but got incompatible type List(Field { name: "item", data_type: Timestamp(Nanosecond, Some("+00:00")), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }) on column 'x'
+query error DataFusion error: type_coercion
Review Comment:
fair! Expanded the error in https://github.com/apache/datafusion/pull/13452/commits/d169abcedf979602cbd689a332a576ffcc2ad4bf
--
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] Coerce Array inner types [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#issuecomment-2489790329
Thanks @blaginin @alamb @findepi
--
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