Skip to content

Commit 7b6fe67

Browse files
committed
Enable array child inspection
1 parent f58bd97 commit 7b6fe67

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

crates/duckdb/src/core/logical_type.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ impl LogicalTypeHandle {
327327
match self.id() {
328328
LogicalTypeId::Struct => duckdb_struct_type_child_type(self.ptr, idx as u64),
329329
LogicalTypeId::Union => duckdb_union_type_member_type(self.ptr, idx as u64),
330-
_ => panic!("not a struct or union"),
330+
LogicalTypeId::Array => duckdb_array_type_child_type(self.ptr),
331+
_ => panic!("not a struct, union, or array"),
331332
}
332333
};
333334
unsafe { Self::new(c_logical_type) }
@@ -362,26 +363,36 @@ mod test {
362363

363364
#[test]
364365
fn test_struct() {
365-
let fields = &[("hello", LogicalTypeHandle::from(crate::core::LogicalTypeId::Boolean))];
366+
let fields = &[("hello", LogicalTypeHandle::from(LogicalTypeId::Boolean))];
366367
let typ = LogicalTypeHandle::struct_type(fields);
367368

368369
assert_eq!(typ.num_children(), 1);
369370
assert_eq!(typ.child_name(0), "hello");
370-
assert_eq!(typ.child(0).id(), crate::core::LogicalTypeId::Boolean);
371+
assert_eq!(typ.child(0).id(), LogicalTypeId::Boolean);
372+
}
373+
374+
#[test]
375+
fn test_array() {
376+
let child = LogicalTypeHandle::from(LogicalTypeId::Integer);
377+
let array = LogicalTypeHandle::array(&child, 4);
378+
379+
assert_eq!(array.id(), LogicalTypeId::Array);
380+
assert_eq!(array.num_children(), 1);
381+
assert_eq!(array.child(0).id(), LogicalTypeId::Integer);
371382
}
372383

373384
#[test]
374385
fn test_decimal() {
375386
let typ = LogicalTypeHandle::decimal(10, 2);
376387

377-
assert_eq!(typ.id(), crate::core::LogicalTypeId::Decimal);
388+
assert_eq!(typ.id(), LogicalTypeId::Decimal);
378389
assert_eq!(typ.decimal_width(), 10);
379390
assert_eq!(typ.decimal_scale(), 2);
380391
}
381392

382393
#[test]
383394
fn test_decimal_methods() {
384-
let typ = LogicalTypeHandle::from(crate::core::LogicalTypeId::Varchar);
395+
let typ = LogicalTypeHandle::from(LogicalTypeId::Varchar);
385396

386397
assert_eq!(typ.decimal_width(), 0);
387398
assert_eq!(typ.decimal_scale(), 0);

0 commit comments

Comments
 (0)