Skip to content

Commit f58bd97

Browse files
committed
Introduce LogicalTypeId::Unsupported
1 parent 9545437 commit f58bd97

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

crates/duckdb/src/core/logical_type.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ pub enum LogicalTypeId {
9191
IntegerLiteral = DUCKDB_TYPE_DUCKDB_TYPE_INTEGER_LITERAL,
9292
/// Time NS
9393
TimeNs = DUCKDB_TYPE_DUCKDB_TYPE_TIME_NS,
94+
/// DuckDB returned a type that this wrapper does not yet recognize
95+
Unsupported = u32::MAX,
9496
}
9597

9698
impl From<u32> for LogicalTypeId {
@@ -137,9 +139,8 @@ impl From<u32> for LogicalTypeId {
137139
DUCKDB_TYPE_DUCKDB_TYPE_STRING_LITERAL => Self::StringLiteral,
138140
DUCKDB_TYPE_DUCKDB_TYPE_INTEGER_LITERAL => Self::IntegerLiteral,
139141
DUCKDB_TYPE_DUCKDB_TYPE_TIME_NS => Self::TimeNs,
140-
// Return Invalid for unknown types to handle forward compatibility
141-
// when DuckDB adds new types in future versions
142-
_ => Self::Invalid,
142+
// Unknown / forward compatible types
143+
_ => Self::Unsupported,
143144
}
144145
}
145146
}
@@ -285,8 +286,12 @@ impl LogicalTypeHandle {
285286

286287
/// Logical type ID
287288
pub fn id(&self) -> LogicalTypeId {
288-
let duckdb_type_id = unsafe { duckdb_get_type_id(self.ptr) };
289-
duckdb_type_id.into()
289+
self.raw_id().into()
290+
}
291+
292+
/// Raw logical type id returned by DuckDB C API
293+
pub fn raw_id(&self) -> u32 {
294+
unsafe { duckdb_get_type_id(self.ptr) }
290295
}
291296

292297
/// Logical type children num
@@ -412,4 +417,9 @@ mod test {
412417
let debug_str = format!("{invalid_type:?}");
413418
assert_eq!(debug_str, "Invalid");
414419
}
420+
421+
#[test]
422+
fn test_unknown_type() {
423+
assert_eq!(LogicalTypeId::from(999_999), LogicalTypeId::Unsupported);
424+
}
415425
}

crates/duckdb/src/vtab/arrow.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,11 @@ pub fn flat_vector_to_arrow_array(
259259
vector: &mut FlatVector,
260260
len: usize,
261261
) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
262-
let type_id = vector.logical_type().id();
262+
let raw_type_id = vector.logical_type().raw_id();
263+
let type_id = LogicalTypeId::from(raw_type_id);
263264
match type_id {
264-
LogicalTypeId::Invalid => Err("Cannot convert invalid logical type to arrow array".into()),
265+
LogicalTypeId::Invalid => Err("Cannot convert invalid logical type returned by DuckDB".into()),
266+
LogicalTypeId::Unsupported => Err(format!("Unsupported DuckDB logical type ID {raw_type_id}").into()),
265267
LogicalTypeId::Integer => {
266268
let data = vector.as_slice_with_len::<i32>(len);
267269

0 commit comments

Comments
 (0)