From d27b872200ca00e6eb88abd8fac7218ae6b2f7f3 Mon Sep 17 00:00:00 2001 From: Yingwen Date: Mon, 11 Sep 2023 19:06:31 +0800 Subject: [PATCH] fix: panic in try_into_vector() (#2351) --- src/datatypes/src/vectors/helper.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/datatypes/src/vectors/helper.rs b/src/datatypes/src/vectors/helper.rs index 645d235c20c8..37e2cbb47be7 100644 --- a/src/datatypes/src/vectors/helper.rs +++ b/src/datatypes/src/vectors/helper.rs @@ -287,7 +287,11 @@ impl Helper { TimeUnit::Millisecond => { Arc::new(TimeMillisecondVector::try_from_arrow_time_array(array)?) } - _ => unimplemented!("Arrow array datatype: {:?}", array.as_ref().data_type()), + // Arrow use time32 for second/millisecond. + _ => unreachable!( + "unexpected arrow array datatype: {:?}", + array.as_ref().data_type() + ), }, ArrowDataType::Time64(unit) => match unit { TimeUnit::Microsecond => { @@ -296,7 +300,11 @@ impl Helper { TimeUnit::Nanosecond => { Arc::new(TimeNanosecondVector::try_from_arrow_time_array(array)?) } - _ => unimplemented!("Arrow array datatype: {:?}", array.as_ref().data_type()), + // Arrow use time64 for microsecond/nanosecond. + _ => unreachable!( + "unexpected arrow array datatype: {:?}", + array.as_ref().data_type() + ), }, ArrowDataType::Interval(unit) => match unit { IntervalUnit::YearMonth => Arc::new( @@ -320,7 +328,10 @@ impl Helper { | ArrowDataType::Decimal256(_, _) | ArrowDataType::Map(_, _) | ArrowDataType::RunEndEncoded(_, _) => { - unimplemented!("Arrow array datatype: {:?}", array.as_ref().data_type()) + return error::UnsupportedArrowTypeSnafu { + arrow_type: array.as_ref().data_type().clone(), + } + .fail() } }) } @@ -351,6 +362,7 @@ mod tests { TimestampSecondArray, UInt16Array, UInt32Array, UInt64Array, UInt8Array, }; use arrow::datatypes::{Field, Int32Type}; + use arrow_array::DictionaryArray; use common_time::time::Time; use common_time::{Date, DateTime, Interval}; @@ -489,6 +501,11 @@ mod tests { check_try_into_vector(Time32MillisecondArray::from(vec![1, 2, 3])); check_try_into_vector(Time64MicrosecondArray::from(vec![1, 2, 3])); check_try_into_vector(Time64NanosecondArray::from(vec![1, 2, 3])); + + let values = StringArray::from_iter_values(["a", "b", "c"]); + let keys = Int8Array::from_iter_values([0, 0, 1, 2]); + let array: ArrayRef = Arc::new(DictionaryArray::try_new(keys, Arc::new(values)).unwrap()); + Helper::try_into_vector(array).unwrap_err(); } #[test]