From d5734d50767a951341dfa41a702786d8c37b47df Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Tue, 25 Jun 2024 17:56:34 +0800 Subject: [PATCH 1/3] feat: substitute `__NOW__` Signed-off-by: Bugen Zhao --- sqllogictest/src/substitution.rs | 7 +++++++ tests/substitution/basic.slt | 4 ++++ tests/substitution/substitution.rs | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/sqllogictest/src/substitution.rs b/sqllogictest/src/substitution.rs index f350163..d66041a 100644 --- a/sqllogictest/src/substitution.rs +++ b/sqllogictest/src/substitution.rs @@ -23,6 +23,13 @@ impl<'a> subst::VariableMap<'a> for Substitution { test_dir.path().to_string_lossy().into_owned().into() } + "__NOW__" => std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .expect("failed to get current time") + .as_nanos() + .to_string() + .into(), + key => Env.get(key), } } diff --git a/tests/substitution/basic.slt b/tests/substitution/basic.slt index bc7d130..7ff4378 100644 --- a/tests/substitution/basic.slt +++ b/tests/substitution/basic.slt @@ -25,6 +25,10 @@ echo "$MY_USERNAME" statement ok path $__TEST_DIR__ +# a special variable `__NOW__` to get the current timestamp in nanoseconds +statement ok +time $__NOW__ + # non existent variables without default values are errors statement error No such variable check $NONEXISTENT_VARIABLE diff --git a/tests/substitution/substitution.rs b/tests/substitution/substitution.rs index 8b62d81..a7e5607 100644 --- a/tests/substitution/substitution.rs +++ b/tests/substitution/substitution.rs @@ -37,6 +37,10 @@ impl sqllogictest::DB for FakeDB { x.to_string() } } + Some(("time", x)) => { + let _ = x.parse::().map_err(|_| FakeDBError)?; + x.to_string() + } _ => return Err(FakeDBError), }; From 6d854fa0514a0e4e2dfb71e30af904e7c3a64e3d Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Tue, 25 Jun 2024 17:58:59 +0800 Subject: [PATCH 2/3] update change log Signed-off-by: Bugen Zhao --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0243d..e51e7ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased * runner: `RecordOutput` is now returned by `Runner::run` (or `Runner::run_async`). This allows users to access the output of each record, or check whether the record is skipped. +* substitution: add a special variable `__NOW__` which will be replaced with the current timestamp in nanoseconds. ## [0.20.6] - 2024-06-21 From b0c8230d61bd92b38dd3aff20bd1e563376013c9 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Wed, 26 Jun 2024 15:32:07 +0800 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: xxchan Signed-off-by: Bugen Zhao --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e51e7ea..189f6e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +**Breaking changes**: * runner: `RecordOutput` is now returned by `Runner::run` (or `Runner::run_async`). This allows users to access the output of each record, or check whether the record is skipped. -* substitution: add a special variable `__NOW__` which will be replaced with the current timestamp in nanoseconds. +* substitution: add a special variable `__NOW__` which will be replaced with the current Unix timestamp in nanoseconds. ## [0.20.6] - 2024-06-21