Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(dev): fix deprecations #1238

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/stdlib/from_unix_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,31 @@ mod tests {

integer {
args: func_args![value: 1_431_648_000],
want: Ok(chrono::Utc.ymd(2015, 5, 15).and_hms_opt(0, 0, 0).expect("invalid timestamp")),
want: Ok(Utc.with_ymd_and_hms(2015, 5, 15, 0, 0, 0).unwrap()),
tdef: TypeDef::timestamp().fallible(),
}

integer_seconds {
args: func_args![value: 1_609_459_200_i64, unit: "seconds"],
want: Ok(chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0,0,0,0)),
want: Ok(Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap()),
tdef: TypeDef::timestamp().fallible(),
}

integer_milliseconds {
args: func_args![value: 1_609_459_200_000_i64, unit: "milliseconds"],
want: Ok(chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0,0,0,0)),
want: Ok(Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap()),
tdef: TypeDef::timestamp().fallible(),
}

integer_microseconds {
args: func_args![value: 1_609_459_200_000_000_i64, unit: "microseconds"],
want: Ok(chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0,0,0,0)),
want: Ok(Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap()),
tdef: TypeDef::timestamp().fallible(),
}

integer_nanoseconds {
args: func_args![value: 1_609_459_200_000_000_000_i64, unit: "nanoseconds"],
want: Ok(chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0,0,0,0)),
want: Ok(Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap()),
tdef: TypeDef::timestamp().fallible(),
}

Expand All @@ -229,7 +229,7 @@ mod tests {
}

timestamp_type_invalid {
args: func_args![value: chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0,0,0,0)],
args: func_args![value: Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap()],
want: Err("unable to coerce timestamp into timestamp"),
tdef: TypeDef::timestamp().fallible(),
}
Expand Down
1 change: 0 additions & 1 deletion src/stdlib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![deny(warnings, clippy::pedantic)]
#![allow(
deprecated,
clippy::needless_pass_by_value, // allowed in initial deny commit
)]

Expand Down
5 changes: 3 additions & 2 deletions src/stdlib/parse_apache_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ mod tests {
tz: TimeZone::default(),
}

log_line_valid_with_local_timestamp_format {
log_line_valid_with_local_timestamp_format {
args: func_args![value: format!("[{}] - - - -",
Utc.ymd(2000, 10, 10).and_hms(20,55,36)
Utc.with_ymd_and_hms(2000, 10, 10, 20, 55, 36).unwrap()
.with_timezone(&Local)
.format("%a %b %d %H:%M:%S %Y")
),
Expand All @@ -367,6 +367,7 @@ mod tests {
tz: TimeZone::default(),
}


log_line_valid_with_timezone {
args: func_args![
value: "[2021/06/03 09:30:50] - - - -",
Expand Down
16 changes: 8 additions & 8 deletions src/stdlib/parse_glog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::compiler::prelude::*;
use chrono::{offset::TimeZone, Utc};
use chrono::{offset::TimeZone, NaiveDateTime, Utc};
use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::BTreeMap;
Expand All @@ -23,13 +23,13 @@ fn parse_glog(bytes: Value) -> Resolved {
log.insert("level".into(), Value::Bytes(level.to_owned().into()));
}
if let Some(timestamp) = captures.name("timestamp").map(|capture| capture.as_str()) {
log.insert(
"timestamp".into(),
Value::Timestamp(
Utc.datetime_from_str(timestamp, "%Y%m%d %H:%M:%S%.f")
.map_err(|error| format!("failed parsing timestamp {timestamp}: {error}"))?,
),
);
match NaiveDateTime::parse_from_str(timestamp, "%Y%m%d %H:%M:%S%.f") {
Ok(naive_dt) => {
let utc_dt = Utc.from_utc_datetime(&naive_dt);
log.insert("timestamp".into(), Value::Timestamp(utc_dt));
}
Err(e) => return Err(format!("failed parsing timestamp {timestamp}: {e}").into()),
};
}
if let Some(id) = captures.name("id").map(|capture| capture.as_str()) {
log.insert(
Expand Down
17 changes: 9 additions & 8 deletions src/stdlib/parse_klog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::compiler::prelude::*;
use chrono::{offset::TimeZone, Datelike, Utc};
use chrono::{Datelike, NaiveDateTime, Utc};
use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::BTreeMap;
Expand All @@ -25,13 +25,14 @@ fn parse_klog(bytes: Value) -> Resolved {
if let Some(timestamp) = captures.name("timestamp").map(|capture| capture.as_str()) {
let month = captures.name("month").map(|capture| capture.as_str());
let year = resolve_year(month);
log.insert(
"timestamp".into(),
Value::Timestamp(
Utc.datetime_from_str(&format!("{year}{timestamp}"), "%Y%m%d %H:%M:%S%.f")
.map_err(|error| format!("failed parsing timestamp {timestamp}: {error}"))?,
),
);

match NaiveDateTime::parse_from_str(&format!("{year}{timestamp}"), "%Y%m%d %H:%M:%S%.f") {
Ok(naive_dt) => {
let utc_dt = naive_dt.and_utc();
log.insert("timestamp".into(), Value::Timestamp(utc_dt));
}
Err(e) => return Err(format!("failed parsing timestamp {timestamp}: {e}").into()),
}
}
if let Some(id) = captures.name("id").map(|capture| capture.as_str()) {
log.insert(
Expand Down
22 changes: 11 additions & 11 deletions src/stdlib/parse_syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn inner_kind() -> BTreeMap<Field, Kind> {
#[cfg(test)]
mod tests {
use crate::btreemap;
use chrono::TimeZone;
use chrono::{TimeZone, Timelike};

use super::*;

Expand All @@ -187,7 +187,7 @@ mod tests {
want: Ok(btreemap! {
"severity" => "notice",
"facility" => "user",
"timestamp" => chrono::Utc.ymd(2020, 3, 13).and_hms_milli(20, 45, 38, 119),
"timestamp" => Utc.with_ymd_and_hms(2020, 3, 13, 20, 45, 38).unwrap().with_nanosecond(119_000_000).unwrap(),
"hostname" => "dynamicwireless.name",
"appname" => "non",
"procid" => 2426,
Expand Down Expand Up @@ -215,7 +215,7 @@ mod tests {
"facility" => "local0",
"severity" => "notice",
"message" => "Proxy sticky-servers started.",
"timestamp" => chrono::Utc.ymd(Utc::now().year(), 6, 13).and_hms_milli(16, 33, 35, 0),
"timestamp" => Utc.with_ymd_and_hms(Utc::now().year(), 6, 13, 16, 33, 35).unwrap(),
"appname" => "haproxy",
"procid" => 73411,
}),
Expand All @@ -226,7 +226,7 @@ mod tests {
args: func_args![value: "Jun 13 16:33:35 haproxy[73411]: I am missing a pri."],
want: Ok(btreemap! {
"message" => "I am missing a pri.",
"timestamp" => chrono::Utc.ymd(Utc::now().year(), 6, 13).and_hms_milli(16, 33, 35, 0),
"timestamp" => Utc.with_ymd_and_hms(Utc::now().year(), 6, 13, 16, 33, 35).unwrap(),
"appname" => "haproxy",
"procid" => 73411,
}),
Expand All @@ -243,7 +243,7 @@ mod tests {
"message" => "qwerty",
"procid" => 8449,
"severity" => "notice",
"timestamp" => chrono::Utc.ymd(2019, 2, 13).and_hms_milli(19, 48, 34, 0),
"timestamp" => Utc.with_ymd_and_hms(2019, 2, 13, 19, 48, 34).unwrap(),
"version" => 1,
"empty" => btreemap! {},
}),
Expand All @@ -260,7 +260,7 @@ mod tests {
"message" => "qwerty",
"procid" => 8449,
"severity" => "notice",
"timestamp" => chrono::Utc.ymd(2019, 2, 13).and_hms_milli(19, 48, 34, 0),
"timestamp" => Utc.with_ymd_and_hms(2019, 2, 13, 19, 48, 34).unwrap(),
"version" => 1,
"non_empty" => btreemap! {
"x" => "1",
Expand All @@ -280,7 +280,7 @@ mod tests {
"message" => "qwerty",
"procid" => 8449,
"severity" => "notice",
"timestamp" => chrono::Utc.ymd(2019, 2, 13).and_hms_milli(19, 48, 34, 0),
"timestamp" => Utc.with_ymd_and_hms(2019, 2, 13, 19, 48, 34).unwrap(),
"version" => 1,
"empty" => btreemap! {},
"non_empty" => btreemap! {
Expand All @@ -297,7 +297,7 @@ mod tests {
"facility" => "local0",
"hostname" => "master",
"severity" => "err",
"timestamp" => chrono::Utc.ymd(chrono::Utc::now().year(), 6, 8).and_hms_milli(11, 54, 8, 0),
"timestamp" => Utc.with_ymd_and_hms(Utc::now().year(), 6, 8, 11, 54, 8).unwrap(),
"message" => "[Tue Jun 08 11:54:08.929301 2021] [php7:emerg] [pid 1374899] [client 95.223.77.60:41888] rest of message",
}),
tdef: TypeDef::object(inner_kind()).fallible(),
Expand All @@ -315,7 +315,7 @@ mod tests {
"message" => "An application event log entry...",
"msgid" => "ID47",
"severity" => "notice",
"timestamp" => chrono::Utc.ymd(2003, 10, 11).and_hms_milli(22,14,15,3),
"timestamp" => Utc.with_ymd_and_hms(2003, 10, 11, 22, 14, 15).unwrap().with_nanosecond(3_000_000).unwrap(),
"version" => 1
}),
tdef: TypeDef::object(inner_kind()).fallible(),
Expand All @@ -333,7 +333,7 @@ mod tests {
"message" => "An application event log entry...",
"msgid" => "ID47",
"severity" => "notice",
"timestamp" => chrono::Utc.ymd(2003, 10, 11).and_hms_milli(22,14,15,3),
"timestamp" => Utc.with_ymd_and_hms(2003, 10, 11, 22, 14, 15).unwrap().with_nanosecond(3_000_000).unwrap(),
"version" => 1
}),
tdef: TypeDef::object(inner_kind()).fallible(),
Expand All @@ -351,7 +351,7 @@ mod tests {
"message" => "An application event log entry...",
"msgid" => "ID47",
"severity" => "notice",
"timestamp" => chrono::Utc.ymd(2003,10,11).and_hms_milli(22,14,15,3),
"timestamp" => Utc.with_ymd_and_hms(2003, 10, 11, 22, 14, 15).unwrap().with_nanosecond(3_000_000).unwrap(),
"version" => 1
}),
tdef: TypeDef::object(inner_kind()).fallible(),
Expand Down
4 changes: 2 additions & 2 deletions src/stdlib/tag_types_externally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ mod tests {
}

tag_timestamp {
args: func_args![value: Utc.ymd(2021, 1, 1).and_hms_milli(0, 0, 0, 0)],
args: func_args![value: Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap()],
want: Ok(btreemap! {
"timestamp" => Utc.ymd(2021, 1, 1).and_hms_milli(0, 0, 0, 0)
"timestamp" => Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap()
}),
tdef: TypeDef::object(Collection::any()),
}
Expand Down
3 changes: 2 additions & 1 deletion src/stdlib/to_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ mod tests {
}

timestamp {
args: func_args![value: Utc.ymd(2014, 7, 8).and_hms_milli(9, 10, 11, 12)],
args: func_args![value: Utc.with_ymd_and_hms(2014, 7, 8, 9, 10, 11).unwrap().with_nanosecond(12_000_000).unwrap()],

want: Ok(1_404_810_611.012),
tdef: TypeDef::float().infallible(),
}
Expand Down
12 changes: 6 additions & 6 deletions src/stdlib/to_unix_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,46 +151,46 @@ impl FunctionExpression for ToUnixTimestampFn {

#[cfg(test)]
mod test {
use chrono::TimeZone;
use chrono::{TimeZone, Utc};

use super::*;

test_function![
to_unix_timestamp => ToUnixTimestamp;

seconds {
args: func_args![value: chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0, 0, 0, 0),
args: func_args![value: Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap(),
unit: "seconds"
],
want: Ok(1_609_459_200_i64),
tdef: TypeDef::integer().infallible(),
}

milliseconds {
args: func_args![value: chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0, 0, 0, 0),
args: func_args![value: Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap(),
unit: "milliseconds"
],
want: Ok(1_609_459_200_000_i64),
tdef: TypeDef::integer().infallible(),
}

microseconds {
args: func_args![value: chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0, 0, 0, 0),
args: func_args![value: Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap(),
unit: "microseconds"
],
want: Ok(1_609_459_200_000_000_i64),
tdef: TypeDef::integer().infallible(),
}

nanoseconds {
args: func_args![value: chrono::Utc.ymd(2021, 1, 1).and_hms_milli(0, 0, 0, 0),
args: func_args![value: Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap(),
unit: "nanoseconds"
],
want: Ok(1_609_459_200_000_000_000_i64),
tdef: TypeDef::integer().infallible(),
}
out_of_range {
args: func_args![value: chrono::Utc.ymd(0, 1, 1).and_hms_milli(0, 0, 0, 0),
args: func_args![value: Utc.with_ymd_and_hms(0, 1, 1, 0, 0, 0).unwrap(),
unit: "nanoseconds"
],
want: Err("can't convert out of range timestamp"),
Expand Down
Loading