Skip to content

Commit

Permalink
Fix to support UTC timezone
Browse files Browse the repository at this point in the history
Related to #1019
  • Loading branch information
andrei-ionescu authored and wjones127 committed Dec 21, 2022
1 parent ee19039 commit 9dc51fb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions rust/src/delta_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ impl TryFrom<&ArrowDataType> for schema::SchemaDataType {
ArrowDataType::Timestamp(TimeUnit::Microsecond, None) => {
Ok(schema::SchemaDataType::primitive("timestamp".to_string()))
}
ArrowDataType::Timestamp(TimeUnit::Microsecond, Some(tz))
if tz.eq_ignore_ascii_case("utc") =>
{
Ok(schema::SchemaDataType::primitive("timestamp".to_string()))
}
ArrowDataType::Struct(fields) => {
let converted_fields: Result<Vec<schema::SchemaField>, _> =
fields.iter().map(|field| field.try_into()).collect();
Expand Down Expand Up @@ -708,4 +713,32 @@ mod tests {
arrow::error::ArrowError::SchemaError(_error),
));
}

#[test]
fn test_arrow_from_delta_timestamp_type() {
let timestamp_field = crate::SchemaDataType::primitive("timestamp".to_string());
assert_eq!(
<ArrowDataType as TryFrom<&crate::SchemaDataType>>::try_from(&timestamp_field).unwrap(),
ArrowDataType::Timestamp(TimeUnit::Microsecond, None)
);
}

#[test]
fn test_delta_from_arrow_timestamp_type() {
let timestamp_field = ArrowDataType::Timestamp(TimeUnit::Microsecond, None);
assert_eq!(
<crate::SchemaDataType as TryFrom<&ArrowDataType>>::try_from(&timestamp_field).unwrap(),
crate::SchemaDataType::primitive("timestamp".to_string())
);
}

#[test]
fn test_delta_from_arrow_timestamp_type_with_tz() {
let timestamp_field =
ArrowDataType::Timestamp(TimeUnit::Microsecond, Some("UTC".to_string()));
assert_eq!(
<crate::SchemaDataType as TryFrom<&ArrowDataType>>::try_from(&timestamp_field).unwrap(),
crate::SchemaDataType::primitive("timestamp".to_string())
);
}
}

0 comments on commit 9dc51fb

Please sign in to comment.