You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/10/20 23:18:37 UTC
[arrow-rs] branch master updated: Parquet record api support timestamp before epoch (#2899)
This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 8be820995 Parquet record api support timestamp before epoch (#2899)
8be820995 is described below
commit 8be8209958dfd3ee51c28da9bc3e4daf4c40a146
Author: Anthony Poncet <an...@gmail.com>
AuthorDate: Fri Oct 21 01:18:32 2022 +0200
Parquet record api support timestamp before epoch (#2899)
* Parquet record api support timestamp before epoch
* Revert submodule changes
---
parquet/src/record/api.rs | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/parquet/src/record/api.rs b/parquet/src/record/api.rs
index 7e1c484bf..22b8a7978 100644
--- a/parquet/src/record/api.rs
+++ b/parquet/src/record/api.rs
@@ -799,13 +799,21 @@ fn convert_date_to_string(value: u32) -> String {
format!("{}", dt.format("%Y-%m-%d %:z"))
}
+/// Helper method to convert Parquet timestamp into a string.
+/// Input `value` is a number of seconds since the epoch in UTC.
+/// Datetime is displayed in local timezone.
+#[inline]
+fn convert_timestamp_secs_to_string(value: i64) -> String {
+ let dt = Utc.timestamp(value, 0);
+ format!("{}", dt.format("%Y-%m-%d %H:%M:%S %:z"))
+}
+
/// Helper method to convert Parquet timestamp into a string.
/// Input `value` is a number of milliseconds since the epoch in UTC.
/// Datetime is displayed in local timezone.
#[inline]
fn convert_timestamp_millis_to_string(value: u64) -> String {
- let dt = Utc.timestamp((value / 1000) as i64, 0);
- format!("{}", dt.format("%Y-%m-%d %H:%M:%S %:z"))
+ convert_timestamp_secs_to_string(value as i64 / 1000)
}
/// Helper method to convert Parquet timestamp into a string.
@@ -813,7 +821,7 @@ fn convert_timestamp_millis_to_string(value: u64) -> String {
/// Datetime is displayed in local timezone.
#[inline]
fn convert_timestamp_micros_to_string(value: u64) -> String {
- convert_timestamp_millis_to_string(value / 1000)
+ convert_timestamp_secs_to_string(value as i64 / 1000000)
}
/// Helper method to convert Parquet decimal into a string.
@@ -1082,7 +1090,7 @@ mod tests {
}
#[test]
- fn test_convert_timestamp_to_string() {
+ fn test_convert_timestamp_millis_to_string() {
fn check_datetime_conversion(y: u32, m: u32, d: u32, h: u32, mi: u32, s: u32) {
let datetime = chrono::NaiveDate::from_ymd(y as i32, m, d).and_hms(h, mi, s);
let dt = Utc.from_utc_datetime(&datetime);
@@ -1091,6 +1099,25 @@ mod tests {
assert_eq!(res, exp);
}
+ check_datetime_conversion(1969, 9, 10, 1, 2, 3);
+ check_datetime_conversion(2010, 1, 2, 13, 12, 54);
+ check_datetime_conversion(2011, 1, 3, 8, 23, 1);
+ check_datetime_conversion(2012, 4, 5, 11, 6, 32);
+ check_datetime_conversion(2013, 5, 12, 16, 38, 0);
+ check_datetime_conversion(2014, 11, 28, 21, 15, 12);
+ }
+
+ #[test]
+ fn test_convert_timestamp_micros_to_string() {
+ fn check_datetime_conversion(y: u32, m: u32, d: u32, h: u32, mi: u32, s: u32) {
+ let datetime = chrono::NaiveDate::from_ymd(y as i32, m, d).and_hms(h, mi, s);
+ let dt = Utc.from_utc_datetime(&datetime);
+ let res = convert_timestamp_micros_to_string(dt.timestamp_micros() as u64);
+ let exp = format!("{}", dt.format("%Y-%m-%d %H:%M:%S %:z"));
+ assert_eq!(res, exp);
+ }
+
+ check_datetime_conversion(1969, 9, 10, 1, 2, 3);
check_datetime_conversion(2010, 1, 2, 13, 12, 54);
check_datetime_conversion(2011, 1, 3, 8, 23, 1);
check_datetime_conversion(2012, 4, 5, 11, 6, 32);