Skip to content

Commit 2a451cc

Browse files
BugenZhaoxxchan
andauthored
feat: substitute __NOW__ to current timestamp in nanoseconds (#220)
Co-authored-by: xxchan <[email protected]>
1 parent 2441dff commit 2a451cc

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
**Breaking changes**:
1011
* 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.
12+
* substitution: add a special variable `__NOW__` which will be replaced with the current Unix timestamp in nanoseconds.
1113

1214
## [0.20.6] - 2024-06-21
1315

sqllogictest/src/substitution.rs

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ impl<'a> subst::VariableMap<'a> for Substitution {
2323
test_dir.path().to_string_lossy().into_owned().into()
2424
}
2525

26+
"__NOW__" => std::time::SystemTime::now()
27+
.duration_since(std::time::UNIX_EPOCH)
28+
.expect("failed to get current time")
29+
.as_nanos()
30+
.to_string()
31+
.into(),
32+
2633
key => Env.get(key),
2734
}
2835
}

tests/substitution/basic.slt

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ echo "$MY_USERNAME"
2525
statement ok
2626
path $__TEST_DIR__
2727

28+
# a special variable `__NOW__` to get the current timestamp in nanoseconds
29+
statement ok
30+
time $__NOW__
31+
2832
# non existent variables without default values are errors
2933
statement error No such variable
3034
check $NONEXISTENT_VARIABLE

tests/substitution/substitution.rs

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ impl sqllogictest::DB for FakeDB {
3737
x.to_string()
3838
}
3939
}
40+
Some(("time", x)) => {
41+
let _ = x.parse::<u128>().map_err(|_| FakeDBError)?;
42+
x.to_string()
43+
}
4044
_ => return Err(FakeDBError),
4145
};
4246

0 commit comments

Comments
 (0)