Skip to content

Commit 9545437

Browse files
committed
Return Invalid instead of panicking for unknown types
1 parent 721632a commit 9545437

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

crates/duckdb/src/core/logical_type.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::ffi::*;
99
/// <https://duckdb.org/docs/api/c/types>
1010
#[repr(u32)]
1111
#[derive(Debug, PartialEq, Eq)]
12+
#[non_exhaustive]
1213
pub enum LogicalTypeId {
1314
/// Invalid
1415
Invalid = DUCKDB_TYPE_DUCKDB_TYPE_INVALID,
@@ -136,7 +137,9 @@ impl From<u32> for LogicalTypeId {
136137
DUCKDB_TYPE_DUCKDB_TYPE_STRING_LITERAL => Self::StringLiteral,
137138
DUCKDB_TYPE_DUCKDB_TYPE_INTEGER_LITERAL => Self::IntegerLiteral,
138139
DUCKDB_TYPE_DUCKDB_TYPE_TIME_NS => Self::TimeNs,
139-
_ => panic!(),
140+
// Return Invalid for unknown types to handle forward compatibility
141+
// when DuckDB adds new types in future versions
142+
_ => Self::Invalid,
140143
}
141144
}
142145
}

crates/duckdb/src/vtab/arrow.rs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ use arrow::{
2525
record_batch::RecordBatch,
2626
};
2727

28-
use libduckdb_sys::{
29-
duckdb_date, duckdb_hugeint, duckdb_interval, duckdb_string_t, duckdb_time, duckdb_timestamp, duckdb_vector,
30-
};
28+
use libduckdb_sys::{duckdb_date, duckdb_string_t, duckdb_time, duckdb_timestamp, duckdb_vector};
3129
use num::{cast::AsPrimitive, ToPrimitive};
3230

3331
/// A pointer to the Arrow record batch for the table function.
@@ -462,35 +460,25 @@ pub fn flat_vector_to_arrow_array(
462460

463461
Ok(Arc::new(structs))
464462
}
465-
LogicalTypeId::Struct => {
466-
todo!()
467-
}
468-
LogicalTypeId::Decimal => {
469-
todo!()
470-
}
471-
LogicalTypeId::Map => {
472-
todo!()
473-
}
474-
LogicalTypeId::List => {
475-
todo!()
476-
}
477-
LogicalTypeId::Union => {
478-
todo!()
479-
}
480-
LogicalTypeId::Interval => {
481-
let _data = vector.as_slice_with_len::<duckdb_interval>(len);
482-
todo!()
483-
}
484-
LogicalTypeId::Hugeint => {
485-
let _data = vector.as_slice_with_len::<duckdb_hugeint>(len);
486-
todo!()
487-
}
488-
LogicalTypeId::Enum => {
489-
todo!()
490-
}
491-
LogicalTypeId::Uuid => {
492-
todo!()
493-
}
463+
LogicalTypeId::Interval => todo!(),
464+
LogicalTypeId::Hugeint => todo!(),
465+
LogicalTypeId::Decimal => todo!(),
466+
LogicalTypeId::Enum => todo!(),
467+
LogicalTypeId::List => todo!(),
468+
LogicalTypeId::Struct => todo!(),
469+
LogicalTypeId::Map => todo!(),
470+
LogicalTypeId::Array => todo!(),
471+
LogicalTypeId::Uuid => todo!(),
472+
LogicalTypeId::Union => todo!(),
473+
LogicalTypeId::Bit => todo!(),
474+
LogicalTypeId::TimeTZ => todo!(),
475+
LogicalTypeId::UHugeint => todo!(),
476+
LogicalTypeId::Any => todo!(),
477+
LogicalTypeId::Bignum => todo!(),
478+
LogicalTypeId::SqlNull => todo!(),
479+
LogicalTypeId::StringLiteral => todo!(),
480+
LogicalTypeId::IntegerLiteral => todo!(),
481+
LogicalTypeId::TimeNs => todo!(),
494482
}
495483
}
496484

0 commit comments

Comments
 (0)