Skip to content

Commit

Permalink
fix: deprecations flaged by clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Solomon committed Nov 18, 2023
1 parent 583412a commit c659594
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 15 deletions.
6 changes: 5 additions & 1 deletion dozer-ingestion/grpc/src/adapter/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ fn map_record(rec: Vec<grpc_types::types::Value>, schema: &Schema) -> Result<Rec
chrono::NaiveDateTime::from_timestamp_opt(a.seconds, a.nanos as u32)
.map(|t| {
dozer_types::types::Field::Timestamp(
chrono::DateTime::<chrono::Utc>::from_utc(t, chrono::Utc).into(),
chrono::DateTime::<chrono::Utc>::from_naive_utc_and_offset(
t,
chrono::Utc,
)
.into(),
)
})
.unwrap_or(dozer_types::types::Field::Null),
Expand Down
4 changes: 2 additions & 2 deletions dozer-ingestion/mysql/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'a> IntoField<'a> for Value {
FieldType::Decimal => Field::Decimal(from_value_opt::<Decimal>(value)?),
FieldType::Timestamp => {
let date_time = from_value_opt::<NaiveDateTime>(value)?;
Field::Timestamp(DateTime::from_utc(date_time, Utc.fix()))
Field::Timestamp(DateTime::from_naive_utc_and_offset(date_time, Utc.fix()))
}
FieldType::Date => Field::Date(from_value_opt::<NaiveDate>(value)?),
FieldType::Json => {
Expand Down Expand Up @@ -311,7 +311,7 @@ mod tests {
Value::Int(9).into_field(&FieldType::Decimal).unwrap()
);
assert_eq!(
Field::Timestamp(DateTime::from_utc(
Field::Timestamp(DateTime::from_naive_utc_and_offset(
NaiveDateTime::new(
NaiveDate::from_ymd_opt(2023, 8, 17).unwrap(),
NaiveTime::from_hms_micro_opt(10, 30, 0, 0).unwrap(),
Expand Down
11 changes: 7 additions & 4 deletions dozer-ingestion/postgres/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ pub fn postgres_type_to_field(
"%Y-%m-%d %H:%M:%S%.f"
};
let date = NaiveDateTime::parse_from_str(date_string.as_str(), format)?;
Ok(Field::Timestamp(DateTime::from_utc(date, Utc.fix())))
Ok(Field::Timestamp(DateTime::from_naive_utc_and_offset(
date,
Utc.fix(),
)))
}
Type::TIMESTAMPTZ => {
let date: DateTime<FixedOffset> = DateTime::parse_from_str(
Expand Down Expand Up @@ -312,7 +315,7 @@ mod tests {
let value = rust_decimal::Decimal::from_f64(8.28).unwrap();
test_conversion!("8.28", Type::NUMERIC, Field::Decimal(value));

let value = DateTime::from_utc(
let value = DateTime::from_naive_utc_and_offset(
NaiveDate::from_ymd_opt(2022, 9, 16)
.unwrap()
.and_hms_opt(5, 56, 29)
Expand All @@ -325,7 +328,7 @@ mod tests {
Field::Timestamp(value)
);

let value = DateTime::from_utc(
let value = DateTime::from_naive_utc_and_offset(
NaiveDate::from_ymd_opt(2022, 9, 16)
.unwrap()
.and_hms_milli_opt(7, 59, 29, 321)
Expand All @@ -338,7 +341,7 @@ mod tests {
Field::Timestamp(value)
);

let value = DateTime::from_utc(
let value = DateTime::from_naive_utc_and_offset(
NaiveDate::from_ymd_opt(2022, 9, 16)
.unwrap()
.and_hms_micro_opt(3, 56, 30, 959787)
Expand Down
5 changes: 4 additions & 1 deletion dozer-ingestion/tests/test_suite/connectors/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ fn fields_to_arrow<'a, F: IntoIterator<Item = &'a Field>>(
let mut builder = arrow::array::TimestampNanosecondArray::builder(count);
for field in fields {
match field {
Field::Timestamp(value) => builder.append_value(value.timestamp_nanos()),
Field::Timestamp(value) => builder
.append_value(value.timestamp_nanos_opt().expect(
"value can not be represented in a timestamp with nanosecond precision.",
)),
Field::Null => builder.append_null(),
_ => panic!("Unexpected field type"),
}
Expand Down
5 changes: 4 additions & 1 deletion dozer-sql/expression/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ pub(crate) fn evaluate_date_part(
DateTimeField::Second => ts.second().to_i64(),
DateTimeField::Millisecond | DateTimeField::Milliseconds => ts.timestamp_millis().to_i64(),
DateTimeField::Microsecond | DateTimeField::Microseconds => ts.timestamp_micros().to_i64(),
DateTimeField::Nanoseconds | DateTimeField::Nanosecond => ts.timestamp_nanos().to_i64(),
DateTimeField::Nanoseconds | DateTimeField::Nanosecond => ts
.timestamp_nanos_opt()
.expect("value can not be represented in a timestamp with nanosecond precision.")
.to_i64(),
DateTimeField::Quarter => ts.month0().to_i64().map(|m| m / 3 + 1),
DateTimeField::Epoch => ts.timestamp().to_i64(),
DateTimeField::Week => ts.iso_week().week().to_i64(),
Expand Down
2 changes: 1 addition & 1 deletion dozer-sql/expression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod tests {
return ArbitraryDateTime(DateTime::default());
}
let time = NaiveTime::from_num_seconds_from_midnight_opt(secs, nano).unwrap();
let datetime = DateTime::<FixedOffset>::from_local(
let datetime = DateTime::<FixedOffset>::from_naive_utc_and_offset(
NaiveDateTime::new(date.unwrap(), time),
timezone_east,
);
Expand Down
5 changes: 4 additions & 1 deletion dozer-tests/src/sql_tests/helper/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ fn get_record_from_json(data: String, schema: &Schema) -> Record {
)
.unwrap();

Field::Timestamp(DateTime::from_utc(naive_date_time, Utc.fix()))
Field::Timestamp(DateTime::from_naive_utc_and_offset(
naive_date_time,
Utc.fix(),
))
}
_ => panic!("Unsupported field type: {field_type:?}"),
};
Expand Down
8 changes: 5 additions & 3 deletions dozer-types/src/arrow_types/to_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ pub fn map_record_to_arrow(
None as Option<i256>,
])) as ArrayRef,
(Field::Timestamp(v), FieldType::Timestamp) => {
Arc::new(arrow_array::TimestampNanosecondArray::from_iter_values([
v.timestamp_nanos()
])) as ArrayRef
Arc::new(arrow_array::TimestampNanosecondArray::from_iter_values([{
v.timestamp_nanos_opt().expect(
"value can not be represented in a timestamp with nanosecond precision.",
)
}])) as ArrayRef
}
(Field::Null, FieldType::Timestamp) => {
Arc::new(arrow_array::TimestampNanosecondArray::from(vec![
Expand Down
2 changes: 1 addition & 1 deletion dozer-types/src/field_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl From<Decimal> for Field {

impl From<NaiveDateTime> for Field {
fn from(value: NaiveDateTime) -> Self {
Field::Timestamp(DateTime::from_utc(value, Utc.fix()))
Field::Timestamp(DateTime::from_naive_utc_and_offset(value, Utc.fix()))
}
}

Expand Down

0 comments on commit c659594

Please sign in to comment.