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

feat: substitute __NOW__ to current timestamp in nanoseconds #220

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
BugenZhao marked this conversation as resolved.
Show resolved Hide resolved

## [0.20.6] - 2024-06-21

Expand Down
7 changes: 7 additions & 0 deletions sqllogictest/src/substitution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/substitution/basic.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/substitution/substitution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ impl sqllogictest::DB for FakeDB {
x.to_string()
}
}
Some(("time", x)) => {
let _ = x.parse::<u128>().map_err(|_| FakeDBError)?;
x.to_string()
}
_ => return Err(FakeDBError),
};

Expand Down
Loading