Skip to content

Commit

Permalink
fix: add back parser support of label and bump to 0.26.0 (#243)
Browse files Browse the repository at this point in the history
* add back parser support of label

Signed-off-by: Eric Fu <fuyufjh@gmail.com>

* bump version

Signed-off-by: xxchan <xxchan22f@gmail.com>

---------

Signed-off-by: Eric Fu <fuyufjh@gmail.com>
Signed-off-by: xxchan <xxchan22f@gmail.com>
Co-authored-by: xxchan <xxchan22f@gmail.com>
  • Loading branch information
fuyufjh and xxchan authored Jan 6, 2025
1 parent 99e8301 commit 7b86552
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.26.0] - 2025-01-06

* paser: Add back `label` support, which was removed in 0.25.0.
* parser/runner: support `[statement|query] error retry` (Only support multi-line error message)

## [0.25.0] - 2024-12-26

* runner: Add `retry` clause to `statement ok` and `query ok|error`.
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"]

[workspace.package]
version = "0.25.0"
version = "0.26.0"
edition = "2021"
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
keywords = ["sql", "database", "parser", "cli"]
Expand Down
4 changes: 2 additions & 2 deletions sqllogictest-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ glob = "0.3"
itertools = "0.13"
quick-junit = { version = "0.5" }
rand = "0.8"
sqllogictest = { path = "../sqllogictest", version = "0.25" }
sqllogictest-engines = { path = "../sqllogictest-engines", version = "0.25" }
sqllogictest = { path = "../sqllogictest", version = "0.26" }
sqllogictest-engines = { path = "../sqllogictest-engines", version = "0.26" }
tokio = { version = "1", features = [
"rt",
"rt-multi-thread",
Expand Down
2 changes: 1 addition & 1 deletion sqllogictest-engines/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ postgres-types = { version = "0.2.8", features = ["derive", "with-chrono-0_4"] }
rust_decimal = { version = "1.36.0", features = ["tokio-pg"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqllogictest = { path = "../sqllogictest", version = "0.25" }
sqllogictest = { path = "../sqllogictest", version = "0.26" }
thiserror = "2"
tokio = { version = "1", features = [
"rt",
Expand Down
32 changes: 28 additions & 4 deletions sqllogictest/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub enum QueryExpect<T: ColumnType> {
types: Vec<T>,
sort_mode: Option<SortMode>,
result_mode: Option<ResultMode>,
label: Option<String>,
results: Vec<String>,
},
/// Query should fail with the given error message.
Expand All @@ -108,6 +109,7 @@ impl<T: ColumnType> QueryExpect<T> {
types: Vec::new(),
sort_mode: None,
result_mode: None,
label: None,
results: Vec::new(),
}
}
Expand Down Expand Up @@ -255,12 +257,18 @@ impl<T: ColumnType> std::fmt::Display for Record<T> {
write!(f, "query ")?;
match expected {
QueryExpect::Results {
types, sort_mode, ..
types,
sort_mode,
label,
..
} => {
write!(f, "{}", types.iter().map(|c| c.to_char()).join(""))?;
if let Some(sort_mode) = sort_mode {
write!(f, " {}", sort_mode.as_str())?;
}
if let Some(label) = label {
write!(f, " {label}")?;
}
}
QueryExpect::Error(err) => err.fmt_inline(f)?,
}
Expand All @@ -281,6 +289,8 @@ impl<T: ColumnType> std::fmt::Display for Record<T> {
for result in results {
write!(f, "\n{result}")?;
}

// query always ends with a blank line
writeln!(f)?
}
QueryExpect::Error(err) => err.fmt_multiline(f)?,
Expand Down Expand Up @@ -815,24 +825,38 @@ fn parse_inner<T: ColumnType>(loc: &Location, script: &str) -> Result<Vec<Record
}
}
[type_str, res @ ..] => {
// query <type-string> [<sort-mode>] [<label>] [retry <attempts> backoff <backoff>]
let types = type_str
.chars()
.map(|ch| {
T::from_char(ch)
.ok_or_else(|| ParseErrorKind::InvalidType(ch).at(loc.clone()))
})
.try_collect()?;
let sort_mode = res.first().and_then(|&s| SortMode::try_from_str(s).ok()); // Could be `retry`
let sort_mode = res.first().and_then(|&s| SortMode::try_from_str(s).ok()); // Could be `retry` or label

// To support `retry`, we assume the label must *not* be "retry"
let label_start = if sort_mode.is_some() { 1 } else { 0 };
let res = &res[label_start..];
let label = res.first().and_then(|&s| {
if s != "retry" {
Some(s.to_owned())
} else {
None // `retry` is not a valid label
}
});

let retry_start = if sort_mode.is_some() { 1 } else { 0 };
let retry_start = if label.is_some() { 1 } else { 0 };
let res = &res[retry_start..];
(
QueryExpect::Results {
types,
sort_mode,
result_mode: None,
label,
results: Vec::new(),
},
&res[retry_start..],
res,
)
}
[] => (QueryExpect::empty_results(), &[][..]),
Expand Down
4 changes: 3 additions & 1 deletion sqllogictest/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,20 +1640,22 @@ pub fn update_record_with_output<T: ColumnType>(
expected: match expected {
QueryExpect::Results {
sort_mode,

label,
result_mode,
..
} => QueryExpect::Results {
results,
types,
sort_mode,
result_mode,
label,
},
QueryExpect::Error(_) => QueryExpect::Results {
results,
types,
sort_mode: None,
result_mode: None,
label: None,
},
},
retry,
Expand Down
32 changes: 32 additions & 0 deletions tests/retry/query_retry.slt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SYNTAX: query <type-string> [<sort-mode>] [<label>] [retry <attempts> backoff <backoff>]
query I retry 3 backoff 5s
SELECT id FROM test;
----
Expand All @@ -15,6 +16,37 @@ SELECT id FROM test;
----
1

query I my_label retry 1 backoff 500ms
SELECT id FROM test;
----
1

query I rowsort my_label retry 1 backoff 500ms
SELECT id FROM test;
----
1

query I rowsort my_label
SELECT id FROM test;
----
1

query I rowsort
SELECT id FROM test;
----
1

query I my_label
SELECT id FROM test;
----
1

query I
SELECT id FROM test;
----
1


query error retry 2 backoff 500ms
SELECT id FROM test;
----
Expand Down

0 comments on commit 7b86552

Please sign in to comment.