colinmarc commented on code in PR #1569:
URL: https://github.com/apache/iceberg-rust/pull/1569#discussion_r2249173983
##########
crates/integrations/datafusion/src/physical_plan/expr_to_predicate.rs:
##########
@@ -214,18 +218,46 @@ fn scalar_value_to_datum(value: &ScalarValue) ->
Option<Datum> {
ScalarValue::LargeUtf8(Some(v)) => Some(Datum::string(v.clone())),
ScalarValue::Date32(Some(v)) => Some(Datum::date(*v)),
ScalarValue::Date64(Some(v)) => Some(Datum::date((*v / MILLIS_PER_DAY)
as i32)),
+ ScalarValue::TimestampSecond(Some(v), tz) => {
+ interpret_timestamptz_micros(v * MICROS_PER_SECOND, tz.as_deref())
+ }
+ ScalarValue::TimestampMillisecond(Some(v), tz) => {
+ interpret_timestamptz_micros(v * MICROS_PER_MILLISECOND,
tz.as_deref())
+ }
+ ScalarValue::TimestampMicrosecond(Some(v), tz) => {
+ interpret_timestamptz_micros(*v, tz.as_deref())
+ }
+ ScalarValue::TimestampNanosecond(Some(v), Some(_)) =>
Some(Datum::timestamptz_nanos(*v)),
+ ScalarValue::TimestampNanosecond(Some(v), None) =>
Some(Datum::timestamp_nanos(*v)),
_ => None,
}
}
+fn interpret_timestamptz_micros(micros: i64, tz: Option<impl AsRef<str>>) ->
Option<Datum> {
+ let offset = tz
+ .as_ref()
+ .and_then(|s| s.as_ref().parse::<FixedOffset>().ok());
+
+ match offset {
+ Some(off) => off
+ .timestamp_micros(micros)
+ .single()
+ .map(Datum::timestamptz_from_datetime),
+ None => Some(Datum::timestamp_micros(micros)),
+ }
+}
+
#[cfg(test)]
mod tests {
use std::collections::HashMap;
+ use chrono::DateTime;
use datafusion::arrow::datatypes::{DataType, Field, Schema, TimeUnit};
Review Comment:
Just a note that an earlier version of this PR was incorrect (it was
truncating to micros)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]