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

Added more serialization options for csv writer. #453

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/io/csv/write/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ use super::iterator::{BufStreamingIterator, StreamingIterator};

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct SerializeOptions {
pub date_format: String,
pub time_format: String,
/// 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(),
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 @@ -123,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 @@ -150,23 +159,23 @@ pub fn new_serializer<'a>(
i64,
temporal_conversions::date64_to_datetime,
array,
&options.date_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