You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/11/10 20:41:52 UTC
[arrow-rs] branch master updated: Recurse into Dictionary value type in DataType::is_nested (#3083)
This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new ed20bf143 Recurse into Dictionary value type in DataType::is_nested (#3083)
ed20bf143 is described below
commit ed20bf1431de784c6193cf2e21bcc6d178aa5de1
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Fri Nov 11 09:41:46 2022 +1300
Recurse into Dictionary value type in DataType::is_nested (#3083)
---
arrow-schema/src/datatype.rs | 47 +++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs
index 9037f7c9a..759fc3964 100644
--- a/arrow-schema/src/datatype.rs
+++ b/arrow-schema/src/datatype.rs
@@ -328,18 +328,20 @@ impl DataType {
)
}
- /// Returns true if this type is nested (List, FixedSizeList, LargeList, Struct, Union, or Map)
+ /// Returns true if this type is nested (List, FixedSizeList, LargeList, Struct, Union,
+ /// or Map), or a dictionary of a nested type
pub fn is_nested(t: &DataType) -> bool {
use DataType::*;
- matches!(
- t,
+ match t {
+ Dictionary(_, v) => DataType::is_nested(v.as_ref()),
List(_)
- | FixedSizeList(_, _)
- | LargeList(_)
- | Struct(_)
- | Union(_, _, _)
- | Map(_, _)
- )
+ | FixedSizeList(_, _)
+ | LargeList(_)
+ | Struct(_)
+ | Union(_, _, _)
+ | Map(_, _) => true,
+ _ => false,
+ }
}
/// Compares the datatype with another, ignoring nested field names
@@ -489,4 +491,31 @@ mod tests {
),
]);
}
+
+ #[test]
+ fn test_nested() {
+ let list = DataType::List(Box::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(&DataType::Dictionary(
+ Box::new(DataType::Int32),
+ Box::new(DataType::Boolean)
+ )));
+ assert!(!DataType::is_nested(&DataType::Dictionary(
+ Box::new(DataType::Int32),
+ Box::new(DataType::Int64)
+ )));
+ assert!(!DataType::is_nested(&DataType::Dictionary(
+ Box::new(DataType::Int32),
+ Box::new(DataType::LargeUtf8)
+ )));
+ assert!(DataType::is_nested(&DataType::Dictionary(
+ Box::new(DataType::Int32),
+ Box::new(list)
+ )));
+ }
}