Skip to content

Commit

Permalink
Add Tz to Stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefffrey committed Mar 29, 2024
1 parent 8c0fe49 commit 3369b5d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rust-version = "1.70"
[dependencies]
arrow = { version = "50", features = ["prettyprint"] }
bytes = "1.4"
chrono-tz = "0.8.6"
clap = { version = "4.5.3", features = ["derive"], optional = true }
fallible-streaming-iterator = { version = "0.1" }
flate2 = "1"
Expand Down
5 changes: 2 additions & 3 deletions src/bin/orc-metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ fn main() -> Result<(), Box<dyn Error>> {
println!(
"writer timezone: {}",
stripe
.footer()
.writer_timezone
.clone()
.writer_tz()
.map(|tz| tz.to_string())
.unwrap_or("None".to_string())
);
println!();
Expand Down
28 changes: 19 additions & 9 deletions src/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ impl TryFrom<(&proto::StripeInformation, &proto::StripeStatistics)> for StripeMe

#[derive(Debug)]
pub struct Stripe {
footer: Arc<StripeFooter>,
columns: Vec<Column>,
stripe_offset: usize,
/// <(ColumnId, Kind), Bytes>
stream_map: Arc<StreamMap>,
number_of_rows: usize,
tz: Option<chrono_tz::Tz>,
}

impl Stripe {
Expand All @@ -113,7 +113,6 @@ impl Stripe {
.context(IoSnafu)?;
let footer = Arc::new(deserialize_stripe_footer(&footer, compression)?);

//TODO(weny): add tz
let columns = projected_data_type
.children()
.iter()
Expand All @@ -134,15 +133,21 @@ impl Stripe {
stream_offset += length;
}

let tz: Option<chrono_tz::Tz> = footer
.writer_timezone
.as_ref()
// TODO: make this return error
.map(|a| a.parse::<chrono_tz::Tz>().unwrap());

Ok(Self {
footer,
columns,
stripe_offset: stripe,
stream_map: Arc::new(StreamMap {
inner: stream_map,
compression,
}),
number_of_rows: info.number_of_rows() as usize,
tz,
})
}

Expand All @@ -163,7 +168,6 @@ impl Stripe {
.context(IoSnafu)?;
let footer = Arc::new(deserialize_stripe_footer(&footer, compression)?);

//TODO(weny): add tz
let columns = projected_data_type
.children()
.iter()
Expand All @@ -184,22 +188,24 @@ impl Stripe {
stream_offset += length;
}

let tz: Option<chrono_tz::Tz> = footer
.writer_timezone
.as_ref()
// TODO: make this return error
.map(|a| a.parse::<chrono_tz::Tz>().unwrap());

Ok(Self {
footer,
columns,
stripe_offset: stripe,
stream_map: Arc::new(StreamMap {
inner: stream_map,
compression,
}),
number_of_rows: info.number_of_rows() as usize,
tz,
})
}

pub fn footer(&self) -> &StripeFooter {
&self.footer
}

pub fn stripe_offset(&self) -> usize {
self.stripe_offset
}
Expand All @@ -215,6 +221,10 @@ impl Stripe {
pub fn columns(&self) -> &[Column] {
&self.columns
}

pub fn writer_tz(&self) -> Option<chrono_tz::Tz> {
self.tz
}
}

#[derive(Debug)]
Expand Down

0 comments on commit 3369b5d

Please sign in to comment.