Skip to content

Commit 7b86552

Browse files
fuyufjhxxchan
andauthored
fix: add back parser support of label and bump to 0.26.0 (#243)
* 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>
1 parent 99e8301 commit 7b86552

File tree

8 files changed

+76
-13
lines changed

8 files changed

+76
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.26.0] - 2025-01-06
11+
12+
* paser: Add back `label` support, which was removed in 0.25.0.
13+
* parser/runner: support `[statement|query] error retry` (Only support multi-line error message)
14+
1015
## [0.25.0] - 2024-12-26
1116

1217
* runner: Add `retry` clause to `statement ok` and `query ok|error`.

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"]
44

55
[workspace.package]
6-
version = "0.25.0"
6+
version = "0.26.0"
77
edition = "2021"
88
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
99
keywords = ["sql", "database", "parser", "cli"]

sqllogictest-bin/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ glob = "0.3"
2323
itertools = "0.13"
2424
quick-junit = { version = "0.5" }
2525
rand = "0.8"
26-
sqllogictest = { path = "../sqllogictest", version = "0.25" }
27-
sqllogictest-engines = { path = "../sqllogictest-engines", version = "0.25" }
26+
sqllogictest = { path = "../sqllogictest", version = "0.26" }
27+
sqllogictest-engines = { path = "../sqllogictest-engines", version = "0.26" }
2828
tokio = { version = "1", features = [
2929
"rt",
3030
"rt-multi-thread",

sqllogictest-engines/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ postgres-types = { version = "0.2.8", features = ["derive", "with-chrono-0_4"] }
2020
rust_decimal = { version = "1.36.0", features = ["tokio-pg"] }
2121
serde = { version = "1", features = ["derive"] }
2222
serde_json = "1"
23-
sqllogictest = { path = "../sqllogictest", version = "0.25" }
23+
sqllogictest = { path = "../sqllogictest", version = "0.26" }
2424
thiserror = "2"
2525
tokio = { version = "1", features = [
2626
"rt",

sqllogictest/src/parser.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub enum QueryExpect<T: ColumnType> {
9595
types: Vec<T>,
9696
sort_mode: Option<SortMode>,
9797
result_mode: Option<ResultMode>,
98+
label: Option<String>,
9899
results: Vec<String>,
99100
},
100101
/// Query should fail with the given error message.
@@ -108,6 +109,7 @@ impl<T: ColumnType> QueryExpect<T> {
108109
types: Vec::new(),
109110
sort_mode: None,
110111
result_mode: None,
112+
label: None,
111113
results: Vec::new(),
112114
}
113115
}
@@ -255,12 +257,18 @@ impl<T: ColumnType> std::fmt::Display for Record<T> {
255257
write!(f, "query ")?;
256258
match expected {
257259
QueryExpect::Results {
258-
types, sort_mode, ..
260+
types,
261+
sort_mode,
262+
label,
263+
..
259264
} => {
260265
write!(f, "{}", types.iter().map(|c| c.to_char()).join(""))?;
261266
if let Some(sort_mode) = sort_mode {
262267
write!(f, " {}", sort_mode.as_str())?;
263268
}
269+
if let Some(label) = label {
270+
write!(f, " {label}")?;
271+
}
264272
}
265273
QueryExpect::Error(err) => err.fmt_inline(f)?,
266274
}
@@ -281,6 +289,8 @@ impl<T: ColumnType> std::fmt::Display for Record<T> {
281289
for result in results {
282290
write!(f, "\n{result}")?;
283291
}
292+
293+
// query always ends with a blank line
284294
writeln!(f)?
285295
}
286296
QueryExpect::Error(err) => err.fmt_multiline(f)?,
@@ -815,24 +825,38 @@ fn parse_inner<T: ColumnType>(loc: &Location, script: &str) -> Result<Vec<Record
815825
}
816826
}
817827
[type_str, res @ ..] => {
828+
// query <type-string> [<sort-mode>] [<label>] [retry <attempts> backoff <backoff>]
818829
let types = type_str
819830
.chars()
820831
.map(|ch| {
821832
T::from_char(ch)
822833
.ok_or_else(|| ParseErrorKind::InvalidType(ch).at(loc.clone()))
823834
})
824835
.try_collect()?;
825-
let sort_mode = res.first().and_then(|&s| SortMode::try_from_str(s).ok()); // Could be `retry`
836+
let sort_mode = res.first().and_then(|&s| SortMode::try_from_str(s).ok()); // Could be `retry` or label
837+
838+
// To support `retry`, we assume the label must *not* be "retry"
839+
let label_start = if sort_mode.is_some() { 1 } else { 0 };
840+
let res = &res[label_start..];
841+
let label = res.first().and_then(|&s| {
842+
if s != "retry" {
843+
Some(s.to_owned())
844+
} else {
845+
None // `retry` is not a valid label
846+
}
847+
});
826848

827-
let retry_start = if sort_mode.is_some() { 1 } else { 0 };
849+
let retry_start = if label.is_some() { 1 } else { 0 };
850+
let res = &res[retry_start..];
828851
(
829852
QueryExpect::Results {
830853
types,
831854
sort_mode,
832855
result_mode: None,
856+
label,
833857
results: Vec::new(),
834858
},
835-
&res[retry_start..],
859+
res,
836860
)
837861
}
838862
[] => (QueryExpect::empty_results(), &[][..]),

sqllogictest/src/runner.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,20 +1640,22 @@ pub fn update_record_with_output<T: ColumnType>(
16401640
expected: match expected {
16411641
QueryExpect::Results {
16421642
sort_mode,
1643-
1643+
label,
16441644
result_mode,
16451645
..
16461646
} => QueryExpect::Results {
16471647
results,
16481648
types,
16491649
sort_mode,
16501650
result_mode,
1651+
label,
16511652
},
16521653
QueryExpect::Error(_) => QueryExpect::Results {
16531654
results,
16541655
types,
16551656
sort_mode: None,
16561657
result_mode: None,
1658+
label: None,
16571659
},
16581660
},
16591661
retry,

tests/retry/query_retry.slt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# SYNTAX: query <type-string> [<sort-mode>] [<label>] [retry <attempts> backoff <backoff>]
12
query I retry 3 backoff 5s
23
SELECT id FROM test;
34
----
@@ -15,6 +16,37 @@ SELECT id FROM test;
1516
----
1617
1
1718

19+
query I my_label retry 1 backoff 500ms
20+
SELECT id FROM test;
21+
----
22+
1
23+
24+
query I rowsort my_label retry 1 backoff 500ms
25+
SELECT id FROM test;
26+
----
27+
1
28+
29+
query I rowsort my_label
30+
SELECT id FROM test;
31+
----
32+
1
33+
34+
query I rowsort
35+
SELECT id FROM test;
36+
----
37+
1
38+
39+
query I my_label
40+
SELECT id FROM test;
41+
----
42+
1
43+
44+
query I
45+
SELECT id FROM test;
46+
----
47+
1
48+
49+
1850
query error retry 2 backoff 500ms
1951
SELECT id FROM test;
2052
----

0 commit comments

Comments
 (0)