alamb commented on code in PR #6853:
URL: https://github.com/apache/arrow-rs/pull/6853#discussion_r1874409116
##########
arrow-schema/src/ffi.rs:
##########
@@ -685,66 +686,68 @@ impl TryFrom<&DataType> for FFI_ArrowSchema {
}
}
-fn get_format_string(dtype: &DataType) -> Result<String, ArrowError> {
+fn get_format_string(dtype: &DataType) -> Result<Cow<'static, str>,
ArrowError> {
match dtype {
- DataType::Null => Ok("n".to_string()),
- DataType::Boolean => Ok("b".to_string()),
- DataType::Int8 => Ok("c".to_string()),
- DataType::UInt8 => Ok("C".to_string()),
- DataType::Int16 => Ok("s".to_string()),
- DataType::UInt16 => Ok("S".to_string()),
- DataType::Int32 => Ok("i".to_string()),
- DataType::UInt32 => Ok("I".to_string()),
- DataType::Int64 => Ok("l".to_string()),
- DataType::UInt64 => Ok("L".to_string()),
- DataType::Float16 => Ok("e".to_string()),
- DataType::Float32 => Ok("f".to_string()),
- DataType::Float64 => Ok("g".to_string()),
- DataType::BinaryView => Ok("vz".to_string()),
- DataType::Binary => Ok("z".to_string()),
- DataType::LargeBinary => Ok("Z".to_string()),
- DataType::Utf8View => Ok("vu".to_string()),
- DataType::Utf8 => Ok("u".to_string()),
- DataType::LargeUtf8 => Ok("U".to_string()),
- DataType::FixedSizeBinary(num_bytes) => Ok(format!("w:{num_bytes}")),
- DataType::FixedSizeList(_, num_elems) => Ok(format!("+w:{num_elems}")),
- DataType::Decimal128(precision, scale) =>
Ok(format!("d:{precision},{scale}")),
- DataType::Decimal256(precision, scale) =>
Ok(format!("d:{precision},{scale},256")),
- DataType::Date32 => Ok("tdD".to_string()),
- DataType::Date64 => Ok("tdm".to_string()),
- DataType::Time32(TimeUnit::Second) => Ok("tts".to_string()),
- DataType::Time32(TimeUnit::Millisecond) => Ok("ttm".to_string()),
- DataType::Time64(TimeUnit::Microsecond) => Ok("ttu".to_string()),
- DataType::Time64(TimeUnit::Nanosecond) => Ok("ttn".to_string()),
- DataType::Timestamp(TimeUnit::Second, None) => Ok("tss:".to_string()),
- DataType::Timestamp(TimeUnit::Millisecond, None) =>
Ok("tsm:".to_string()),
- DataType::Timestamp(TimeUnit::Microsecond, None) =>
Ok("tsu:".to_string()),
- DataType::Timestamp(TimeUnit::Nanosecond, None) =>
Ok("tsn:".to_string()),
- DataType::Timestamp(TimeUnit::Second, Some(tz)) =>
Ok(format!("tss:{tz}")),
- DataType::Timestamp(TimeUnit::Millisecond, Some(tz)) =>
Ok(format!("tsm:{tz}")),
- DataType::Timestamp(TimeUnit::Microsecond, Some(tz)) =>
Ok(format!("tsu:{tz}")),
- DataType::Timestamp(TimeUnit::Nanosecond, Some(tz)) =>
Ok(format!("tsn:{tz}")),
- DataType::Duration(TimeUnit::Second) => Ok("tDs".to_string()),
- DataType::Duration(TimeUnit::Millisecond) => Ok("tDm".to_string()),
- DataType::Duration(TimeUnit::Microsecond) => Ok("tDu".to_string()),
- DataType::Duration(TimeUnit::Nanosecond) => Ok("tDn".to_string()),
- DataType::Interval(IntervalUnit::YearMonth) => Ok("tiM".to_string()),
- DataType::Interval(IntervalUnit::DayTime) => Ok("tiD".to_string()),
- DataType::Interval(IntervalUnit::MonthDayNano) =>
Ok("tin".to_string()),
- DataType::List(_) => Ok("+l".to_string()),
- DataType::LargeList(_) => Ok("+L".to_string()),
- DataType::Struct(_) => Ok("+s".to_string()),
- DataType::Map(_, _) => Ok("+m".to_string()),
- DataType::RunEndEncoded(_, _) => Ok("+r".to_string()),
+ DataType::Null => Ok(Cow::Borrowed("n")),
Review Comment:
This syntax is totally fine (and very explicit)
I think you can express the same thing using `into` which is less verbose:
For example
```suggestion
DataType::Null => Ok("n".into()),
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]