Copilot commented on code in PR #1569:
URL: https://github.com/apache/iceberg-rust/pull/1569#discussion_r2337198594
##########
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());
Review Comment:
The parse error is silently ignored with `.ok()`. Consider logging the error
or providing more specific error handling to help debug timezone parsing
failures.
```suggestion
.and_then(|s| match s.as_ref().parse::<FixedOffset>() {
Ok(offset) => Some(offset),
Err(e) => {
eprintln!("Failed to parse timezone string '{}': {}",
s.as_ref(), e);
None
}
});
```
##########
crates/iceberg/src/spec/values.rs:
##########
@@ -1196,14 +1199,92 @@ impl Datum {
(PrimitiveLiteral::Int(val), _, PrimitiveType::Int) =>
Ok(Datum::int(*val)),
(PrimitiveLiteral::Int(val), _, PrimitiveType::Date) =>
Ok(Datum::date(*val)),
(PrimitiveLiteral::Int(val), _, PrimitiveType::Long) =>
Ok(Datum::long(*val)),
+ (PrimitiveLiteral::Int(val), PrimitiveType::Date,
PrimitiveType::Timestamp) => {
+ Ok(Datum::timestamp_micros(*val as i64 *
MICROS_PER_DAY))
+ }
+ (
+ PrimitiveLiteral::Int(val),
+ PrimitiveType::Date,
+ PrimitiveType::Timestamptz,
+ ) => Ok(Datum::timestamptz_micros(*val as i64 *
MICROS_PER_DAY)),
+ (
+ PrimitiveLiteral::Int(val),
+ PrimitiveType::Date,
+ PrimitiveType::TimestampNs,
+ ) => Ok(Datum::timestamp_nanos(
+ *val as i64 * MICROS_PER_DAY * NANOS_PER_MICRO,
+ )),
+ (
+ PrimitiveLiteral::Int(val),
+ PrimitiveType::Date,
+ PrimitiveType::TimestamptzNs,
+ ) => Ok(Datum::timestamptz_nanos(
+ *val as i64 * MICROS_PER_DAY * NANOS_PER_MICRO,
+ )),
(PrimitiveLiteral::Long(val), _, PrimitiveType::Int) => {
Ok(Datum::i64_to_i32(*val))
}
- (PrimitiveLiteral::Long(val), _, PrimitiveType::Timestamp)
=> {
- Ok(Datum::timestamp_micros(*val))
- }
- (PrimitiveLiteral::Long(val), _,
PrimitiveType::Timestamptz) => {
- Ok(Datum::timestamptz_micros(*val))
+ (PrimitiveLiteral::Long(val), source_type, target_type) =>
{
+ match (source_type, target_type) {
Review Comment:
[nitpick] The nested match statement with extensive pattern matching creates
high complexity. Consider extracting this logic into a separate helper function
like `convert_long_value` to improve readability and maintainability.
--
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]