Skip to content

Instantly share code, notes, and snippets.

@tisonkun
Created December 27, 2024 00:07
Show Gist options
  • Save tisonkun/183e761fdf8d26a4799f91f6ba3cbe80 to your computer and use it in GitHub Desktop.
Save tisonkun/183e761fdf8d26a4799f91f6ba3cbe80 to your computer and use it in GitHub Desktop.
Upgrade jiff to 0.1.16
From 76a4ce05b5d160e1a9526efc2a8cd3feb14c673a Mon Sep 17 00:00:00 2001
From: tison <wander4096@gmail.com>
Date: Fri, 27 Dec 2024 07:38:15 +0800
Subject: [PATCH] chore: bump jiff version to 0.1.16
Signed-off-by: tison <wander4096@gmail.com>
---
Cargo.lock | 26 +++++------------------
Cargo.toml | 5 +----
cmd/scopeql/Cargo.toml | 1 +
cmd/scopeql/src/client.rs | 8 ++++---
crates/expr/src/render.rs | 6 ++----
crates/protos/Cargo.toml | 4 ++--
crates/protos/src/http/statement.rs | 6 ++----
crates/rowset/src/datum.rs | 9 ++------
crates/rowset/src/hash.rs | 6 ++----
crates/server/Cargo.toml | 1 -
crates/server/src/http/statements.rs | 20 +++++++++++------
tests/functional/tests/it/common_tests.rs | 4 ++--
tests/utility/Cargo.toml | 2 +-
tests/utility/src/harness.rs | 4 ++--
14 files changed, 41 insertions(+), 61 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 62bc3af7a..80d76d5bf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2290,22 +2290,6 @@ dependencies = [
"libm",
]
-[[package]]
-name = "humantime"
-version = "2.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
-
-[[package]]
-name = "humantime-serde"
-version = "1.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "57a3db5ea5923d99402c94e9feb261dc5ee9b4efa158b0315f788cf549cc200c"
-dependencies = [
- "humantime",
- "serde",
-]
-
[[package]]
name = "hybrid-array"
version = "0.2.3"
@@ -2699,9 +2683,9 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
[[package]]
name = "jiff"
-version = "0.1.15"
+version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "db69f08d4fb10524cacdb074c10b296299d71274ddbc830a8ee65666867002e9"
+checksum = "24a46169c7a10358cdccfb179910e8a5a392fc291bdb409da9aeece5b19786d8"
dependencies = [
"jiff-tzdb-platform",
"serde",
@@ -3858,8 +3842,8 @@ dependencies = [
name = "protos"
version = "0.1.0-alpha.6"
dependencies = [
- "humantime-serde",
"insta",
+ "jiff",
"serde",
"serde_json",
]
@@ -4443,6 +4427,7 @@ dependencies = [
"csv",
"dirs",
"error-stack",
+ "jiff",
"nu-ansi-term",
"protos",
"reedline",
@@ -4568,7 +4553,6 @@ dependencies = [
"function",
"futures",
"humansize",
- "humantime",
"insta",
"itertools 0.13.0",
"jiff",
@@ -5295,6 +5279,7 @@ dependencies = [
"fastrace",
"futures",
"insta",
+ "jiff",
"parse-display",
"protos",
"regex",
@@ -5302,7 +5287,6 @@ dependencies = [
"rowset",
"runtime",
"scopeguard",
- "serde",
"server",
"sqlx",
"storage",
diff --git a/Cargo.toml b/Cargo.toml
index 63afca7d1..c06ac6791 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -93,12 +93,10 @@ futures = { version = "0.3" }
gix-discover = { version = "0.37" }
hex = { version = "0.4" }
humansize = { version = "2" }
-humantime = { version = "2.1" }
-humantime-serde = { version = "1.1" }
indent = { version = "0.1" }
insta = { version = "1.41", features = ["json", "filters"] }
itertools = { version = "0.13" }
-jiff = { version = "0.1.13", features = ["serde"] }
+jiff = { version = "0.1.16", features = ["serde"] }
local-ip-address = { version = "0.6" }
log = { version = "0.4", features = ["kv_std"] }
logforth = { version = "0.19", features = [
@@ -153,7 +151,6 @@ rspack-codespan-reporting = { version = "0.11" }
scopeguard = { version = "1.2" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
-sha2 = { version = "0.10" }
shadow-rs = { version = "0.37" }
smallvec = { version = "1.13" }
sqlx = { version = "0.8", features = ["postgres", "runtime-tokio-rustls"] }
diff --git a/cmd/scopeql/Cargo.toml b/cmd/scopeql/Cargo.toml
index ae4649048..77a7ea9af 100644
--- a/cmd/scopeql/Cargo.toml
+++ b/cmd/scopeql/Cargo.toml
@@ -12,6 +12,7 @@ client = { workspace = true }
csv = { workspace = true }
dirs = { workspace = true }
error-stack = { workspace = true }
+jiff = { workspace = true }
nu-ansi-term = { workspace = true }
protos = { workspace = true }
reedline = { workspace = true }
diff --git a/cmd/scopeql/src/client.rs b/cmd/scopeql/src/client.rs
index 591dd0b66..2e3dec05b 100644
--- a/cmd/scopeql/src/client.rs
+++ b/cmd/scopeql/src/client.rs
@@ -5,6 +5,7 @@ use client::HTTPResponse;
use error_stack::Result;
use error_stack::ResultExt;
use error_stack::bail;
+use jiff::SignedDuration;
use protos::http::Format;
use protos::http::IngestData;
use protos::http::IngestRequest;
@@ -19,8 +20,8 @@ use rowset::encode_arrow;
use crate::error::Error;
-const DEFAULT_FIRST_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
-const DEFAULT_FETCH_INTERVAL: Duration = Duration::from_secs(1);
+const DEFAULT_FIRST_SYNC_TIMEOUT: SignedDuration = SignedDuration::from_secs(30);
+const DEFAULT_FETCH_INTERVAL: SignedDuration = SignedDuration::from_secs(1);
#[derive(Debug)]
pub struct ScopeQLClient {
@@ -41,6 +42,7 @@ impl ScopeQLClient {
pub async fn submit_statements(&self, statements: String) -> Result<String, Error> {
let make_error = || Error::Internal(format!("failed to submit statements: {statements}"));
+ let default_fetch_interval: Duration = DEFAULT_FETCH_INTERVAL.try_into().unwrap();
let params = StatementRequestParams {
format: Format::Table,
};
@@ -92,7 +94,7 @@ impl ScopeQLClient {
.ok_or_else(make_error)?);
}
"running" => {
- tokio::time::sleep(DEFAULT_FETCH_INTERVAL).await;
+ tokio::time::sleep(default_fetch_interval).await;
continue;
}
status => {
diff --git a/crates/expr/src/render.rs b/crates/expr/src/render.rs
index 7b7d49e62..7ac2f15a6 100644
--- a/crates/expr/src/render.rs
+++ b/crates/expr/src/render.rs
@@ -211,10 +211,8 @@ fn render_datum(datum: &Datum) -> Literal {
Datum::String(v) => Literal::String(v.clone()),
Datum::Boolean(v) => Literal::Boolean(*v),
Datum::Timestamp(v) => Literal::String(format!("{v:.6}")),
- // TODO(tisonkun): when jiff support human readable format, switch to it
- // ref: https://github.com/BurntSushi/jiff/issues/111#issuecomment-2365253921
- Datum::Interval(v) => Literal::String(format!("{v}")),
+ Datum::Interval(v) => Literal::String(format!("{v:?}")),
Datum::Variant(v) => Literal::String(format!("{v:?}")),
- Datum::Null => todo!(),
+ Datum::Null => Literal::Null,
}
}
diff --git a/crates/protos/Cargo.toml b/crates/protos/Cargo.toml
index 6a04d1564..7681651a7 100644
--- a/crates/protos/Cargo.toml
+++ b/crates/protos/Cargo.toml
@@ -5,12 +5,12 @@ edition.workspace = true
version.workspace = true
[dependencies]
-humantime-serde = { workspace = true }
+jiff = { workspace = true }
serde = { workspace = true }
-serde_json = { workspace = true }
[dev-dependencies]
insta = { workspace = true }
+serde_json = { workspace = true }
[lints]
workspace = true
diff --git a/crates/protos/src/http/statement.rs b/crates/protos/src/http/statement.rs
index 31df72a45..6dec6660e 100644
--- a/crates/protos/src/http/statement.rs
+++ b/crates/protos/src/http/statement.rs
@@ -1,5 +1,4 @@
-use std::time::Duration;
-
+use jiff::SignedDuration;
use serde::Deserialize;
use serde::Serialize;
@@ -37,8 +36,7 @@ pub struct StatementRequest {
/// with [StatementResponse::status] set to "running". Note that the statement will
/// continue to run in the background in this case.
#[serde(default)]
- #[serde(with = "humantime_serde")]
- pub wait_timeout: Option<Duration>,
+ pub wait_timeout: Option<SignedDuration>,
#[serde(flatten)]
pub params: StatementRequestParams,
}
diff --git a/crates/rowset/src/datum.rs b/crates/rowset/src/datum.rs
index f8147ea9c..e01c80065 100644
--- a/crates/rowset/src/datum.rs
+++ b/crates/rowset/src/datum.rs
@@ -366,10 +366,7 @@ impl hash::Hash for DatumRef<'_> {
DatumRef::String(v) => v.hash(state),
DatumRef::Boolean(v) => v.hash(state),
DatumRef::Interval(v) => v.hash(state),
- DatumRef::Timestamp(v) => {
- // TODO(anon): jiff::Timestamp does not implement Hash while SignedDuration does
- v.as_jiff_duration().hash(state);
- }
+ DatumRef::Timestamp(v) => v.hash(state),
DatumRef::Variant(v) => v.hash(state),
DatumRef::Null => {}
}
@@ -420,9 +417,7 @@ impl fmt::Display for DatumRef<'_> {
DatumRef::String(v) => write!(f, "{v}"),
DatumRef::Boolean(v) => write!(f, "{v}"),
DatumRef::Timestamp(v) => write!(f, "{v:.6}"),
- // TODO(tisonkun): when jiff support human readable format, switch to it
- // ref: https://github.com/BurntSushi/jiff/issues/111#issuecomment-2365253921
- DatumRef::Interval(v) => write!(f, "{v}"),
+ DatumRef::Interval(v) => write!(f, "{v:?}"),
DatumRef::Variant(v) => write!(f, "{v:?}"),
DatumRef::Null => write!(f, "NULL"),
}
diff --git a/crates/rowset/src/hash.rs b/crates/rowset/src/hash.rs
index 3e69c8496..6095ccc16 100644
--- a/crates/rowset/src/hash.rs
+++ b/crates/rowset/src/hash.rs
@@ -36,8 +36,7 @@ pub fn hash_datum(datum: DatumRef) -> u64 {
hasher.write_u8(v as u8);
}
DatumRef::Timestamp(v) => {
- v.as_second().hash(&mut hasher);
- v.subsec_nanosecond().hash(&mut hasher);
+ v.hash(&mut hasher);
}
DatumRef::Interval(v) => {
v.hash(&mut hasher);
@@ -74,8 +73,7 @@ fn hash_variant(hasher: &mut impl Hasher, variant: VariantRef) {
hasher.write_u8(v as u8);
}
VariantRef::Timestamp(v) => {
- v.as_second().hash(hasher);
- v.subsec_nanosecond().hash(hasher);
+ v.hash(hasher);
}
VariantRef::Interval(v) => {
v.hash(hasher);
diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml
index 0b30142ea..b5e0b3329 100644
--- a/crates/server/Cargo.toml
+++ b/crates/server/Cargo.toml
@@ -18,7 +18,6 @@ fastrace = { workspace = true }
function = { workspace = true }
futures = { workspace = true }
humansize = { workspace = true }
-humantime = { workspace = true }
itertools = { workspace = true }
jiff = { workspace = true }
local-ip-address = { workspace = true }
diff --git a/crates/server/src/http/statements.rs b/crates/server/src/http/statements.rs
index 4057915b7..d3d85e100 100644
--- a/crates/server/src/http/statements.rs
+++ b/crates/server/src/http/statements.rs
@@ -1,6 +1,6 @@
use std::sync::Arc;
-use std::time::Duration;
+use jiff::SignedDuration;
use meta::StatementSource;
use poem::Request;
use poem::handler;
@@ -31,7 +31,7 @@ use crate::http::error::ErrorWithCode;
const STATUS_RUNNING: &str = "running";
const STATUS_FINISHED: &str = "finished";
-const MAX_WAIT_TIMEOUT: Duration = Duration::from_secs(60);
+const MAX_WAIT_TIMEOUT: SignedDuration = SignedDuration::from_secs(60);
#[handler]
#[fastrace::trace]
@@ -57,13 +57,21 @@ pub async fn statements(
if let Some(wait_timeout) = wait_timeout {
if wait_timeout > MAX_WAIT_TIMEOUT {
return Err(poem::Error::from_string(
- format!(
- "wait_timeout exceeds {}",
- humantime::format_duration(MAX_WAIT_TIMEOUT)
- ),
+ format!("wait_timeout {wait_timeout} exceeds {MAX_WAIT_TIMEOUT:?}"),
+ HTTPStatusCode::BAD_REQUEST,
+ ));
+ } else if wait_timeout.is_negative() {
+ return Err(poem::Error::from_string(
+ format!("wait_timeout {wait_timeout} must be zero or positive"),
HTTPStatusCode::BAD_REQUEST,
));
}
+ let Ok(wait_timeout) = wait_timeout.try_into() else {
+ return Err(poem::Error::from_string(
+ format!("wait_timeout {wait_timeout} cannot be converted to Duration"),
+ HTTPStatusCode::BAD_REQUEST,
+ ));
+ };
// * Err(..) wait timeout
// * Ok(Err(..)) insufficient resources; execute later
diff --git a/tests/functional/tests/it/common_tests.rs b/tests/functional/tests/it/common_tests.rs
index 889cc5aca..8909209f0 100644
--- a/tests/functional/tests/it/common_tests.rs
+++ b/tests/functional/tests/it/common_tests.rs
@@ -2303,7 +2303,7 @@ async fn test_integer_to_timestamp_duration(mut testkit: Testkit) {
@"2024-09-19T13:18:36.888082Z"
);
- execute_one_value!(testkit, "values (60000000000::interval)", @"PT1m");
+ execute_one_value!(testkit, "values (60000000000::interval)", @"1m");
}
#[test(harness)]
@@ -2346,7 +2346,7 @@ async fn test_timestamp_arith(mut testkit: Testkit) {
execute_one_value!(
testkit,
"values ('2024-09-22T13:18:36Z'::timestamp, '2024-09-22T14:18:36Z'::timestamp) select $1 - $0",
- @"PT1h"
+ @"1h"
);
execute_one_value!(
testkit,
diff --git a/tests/utility/Cargo.toml b/tests/utility/Cargo.toml
index 1b89846be..9488a4fa8 100644
--- a/tests/utility/Cargo.toml
+++ b/tests/utility/Cargo.toml
@@ -11,6 +11,7 @@ client = { workspace = true }
fastrace = { workspace = true }
futures = { workspace = true }
insta = { workspace = true }
+jiff = { workspace = true }
parse-display = { workspace = true }
protos = { workspace = true }
regex = { workspace = true }
@@ -18,7 +19,6 @@ reqwest = { workspace = true }
rowset = { workspace = true }
runtime = { workspace = true, features = ["test"] }
scopeguard = { workspace = true }
-serde = { workspace = true }
server = { workspace = true }
sqlx = { workspace = true }
storage = { workspace = true }
diff --git a/tests/utility/src/harness.rs b/tests/utility/src/harness.rs
index a9a3b87fd..77f362ce4 100644
--- a/tests/utility/src/harness.rs
+++ b/tests/utility/src/harness.rs
@@ -3,12 +3,12 @@ use std::future::Future;
use std::path::Path;
use std::process::ExitCode;
use std::random;
-use std::time::Duration;
use backon::ExponentialBuilder;
use client::HTTPClient;
use client::HTTPResponse;
use fastrace::prelude::*;
+use jiff::SignedDuration;
use protos::ErrorCode;
use protos::config::HTTPServerConfig;
use protos::config::InternalServerConfig;
@@ -42,7 +42,7 @@ use crate::make_test_env_state;
use crate::make_test_name;
use crate::option_enabled;
-const DEFAULT_WAIT_TIMEOUT: Duration = Duration::from_secs(30);
+const DEFAULT_WAIT_TIMEOUT: SignedDuration = SignedDuration::from_secs(30);
pub macro execute {
($testkit:expr, $statement:expr) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment