Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark (Large)ListView as nested and support in equal data type #6995

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions arrow-schema/src/datatype.rs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't we should use wildcard pattern in this file for matching data type

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given how rarely this enumeration changes, I'm inclined to optimise for legibility and continue to use wildcard matches

Original file line number Diff line number Diff line change
Expand Up @@ -552,16 +552,21 @@ impl DataType {
matches!(self, Int16 | Int32 | Int64)
}

/// Returns true if this type is nested (List, FixedSizeList, LargeList, Struct, Union,
/// Returns true if this type is nested (List, FixedSizeList, LargeList, ListView. LargeListView, Struct, Union,
/// or Map), or a dictionary of a nested type
#[inline]
pub fn is_nested(&self) -> bool {
use DataType::*;
match self {
Dictionary(_, v) => DataType::is_nested(v.as_ref()),
List(_) | FixedSizeList(_, _) | LargeList(_) | Struct(_) | Union(_, _) | Map(_, _) => {
true
}
List(_)
| FixedSizeList(_, _)
| LargeList(_)
| ListView(_)
| LargeListView(_)
| Struct(_)
| Union(_, _)
| Map(_, _) => true,
_ => false,
}
}
Expand All @@ -578,7 +583,9 @@ impl DataType {
pub fn equals_datatype(&self, other: &DataType) -> bool {
match (&self, other) {
(DataType::List(a), DataType::List(b))
| (DataType::LargeList(a), DataType::LargeList(b)) => {
| (DataType::LargeList(a), DataType::LargeList(b))
| (DataType::ListView(a), DataType::ListView(b))
| (DataType::LargeListView(a), DataType::LargeListView(b)) => {
a.is_nullable() == b.is_nullable() && a.data_type().equals_datatype(b.data_type())
}
(DataType::FixedSizeList(a, a_size), DataType::FixedSizeList(b, b_size)) => {
Expand Down Expand Up @@ -725,7 +732,9 @@ impl DataType {
pub fn contains(&self, other: &DataType) -> bool {
match (self, other) {
(DataType::List(f1), DataType::List(f2))
| (DataType::LargeList(f1), DataType::LargeList(f2)) => f1.contains(f2),
| (DataType::LargeList(f1), DataType::LargeList(f2))
| (DataType::ListView(f1), DataType::ListView(f2))
| (DataType::LargeListView(f1), DataType::LargeListView(f2)) => f1.contains(f2),
(DataType::FixedSizeList(f1, s1), DataType::FixedSizeList(f2, s2)) => {
s1 == s2 && f1.contains(f2)
}
Expand Down Expand Up @@ -1006,11 +1015,16 @@ mod tests {
#[test]
fn test_nested() {
let list = DataType::List(Arc::new(Field::new("foo", DataType::Utf8, true)));
let list_view = DataType::ListView(Arc::new(Field::new("foo", DataType::Utf8, true)));
let large_list_view =
DataType::LargeListView(Arc::new(Field::new("foo", DataType::Utf8, true)));

assert!(!DataType::is_nested(&DataType::Boolean));
assert!(!DataType::is_nested(&DataType::Int32));
assert!(!DataType::is_nested(&DataType::Utf8));
assert!(DataType::is_nested(&list));
assert!(DataType::is_nested(&list_view));
assert!(DataType::is_nested(&large_list_view));

assert!(!DataType::is_nested(&DataType::Dictionary(
Box::new(DataType::Int32),
Expand Down
Loading