Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
stay complient with arrow spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 27, 2021
1 parent 99a12aa commit 7cf0c61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
35 changes: 19 additions & 16 deletions src/io/csv/write/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ use super::iterator::{BufStreamingIterator, StreamingIterator};

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct SerializeOptions {
// used for date32
pub date_format: String,
/// used for dat64
pub datetime_format: String,
// used for time32/64
pub time_format: String,
// used for timestamp
/// used for date32
pub date32_format: String,
/// used for date64
pub date64_format: String,
/// used for time32
pub time32_format: String,
/// used for time64
pub time64_format: String,
/// used for timestamp
pub timestamp_format: String,
}

impl Default for SerializeOptions {
fn default() -> Self {
Self {
date_format: "%F".to_string(),
datetime_format: "%FT%H:%M:%S.%9f".to_string(),
time_format: "%T".to_string(),
date32_format: "%F".to_string(),
date64_format: "%F".to_string(),
time32_format: "%T".to_string(),
time64_format: "%T".to_string(),
timestamp_format: "%FT%H:%M:%S.%9f".to_string(),
}
}
Expand Down Expand Up @@ -129,23 +132,23 @@ pub fn new_serializer<'a>(
i32,
temporal_conversions::date32_to_datetime,
array,
&options.date_format
&options.date32_format
)
}
DataType::Time32(TimeUnit::Second) => {
dyn_date!(
i32,
temporal_conversions::time32s_to_time,
array,
&options.time_format
&options.time32_format
)
}
DataType::Time32(TimeUnit::Millisecond) => {
dyn_date!(
i32,
temporal_conversions::time32ms_to_time,
array,
&options.time_format
&options.time32_format
)
}
DataType::Int64 => {
Expand All @@ -156,23 +159,23 @@ pub fn new_serializer<'a>(
i64,
temporal_conversions::date64_to_datetime,
array,
&options.datetime_format
&options.date64_format
)
}
DataType::Time64(TimeUnit::Microsecond) => {
dyn_date!(
i64,
temporal_conversions::time64us_to_time,
array,
&options.time_format
&options.time64_format
)
}
DataType::Time64(TimeUnit::Nanosecond) => {
dyn_date!(
i64,
temporal_conversions::time64ns_to_time,
array,
&options.time_format
&options.time64_format
)
}
DataType::Timestamp(TimeUnit::Second, None) => {
Expand Down
3 changes: 2 additions & 1 deletion tests/it/io/csv/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ fn write_csv_custom_options() -> Result<()> {
let mut writer = WriterBuilder::new().delimiter(b'|').from_writer(write);

let options = SerializeOptions {
time_format: "%r".to_string(),
time32_format: "%r".to_string(),
time64_format: "%r".to_string(),
..Default::default()
};
write_batch(&mut writer, &batch, &options)?;
Expand Down

0 comments on commit 7cf0c61

Please sign in to comment.