From d91499d2565da8747581e5b7c27cd0c306def86e Mon Sep 17 00:00:00 2001 From: Eric Fu Date: Fri, 3 Jan 2025 16:28:14 +0800 Subject: [PATCH 1/3] impl Signed-off-by: Eric Fu --- sqllogictest/src/parser.rs | 32 ++++++++++++++++++++------------ tests/retry/query_retry.slt | 14 ++++++++++++-- tests/retry/statement_retry.slt | 12 +++++++++++- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/sqllogictest/src/parser.rs b/sqllogictest/src/parser.rs index 9e0b2ce..b069469 100644 --- a/sqllogictest/src/parser.rs +++ b/sqllogictest/src/parser.rs @@ -755,12 +755,16 @@ fn parse_inner(loc: &Location, script: &str) -> Result { let (mut expected, res) = match res { ["ok", retry @ ..] => (StatementExpect::Ok, retry), - ["error", err_tokens @ ..] => { - // NOTE: `statement error` can't be used with `retry` now because all the - // tokens after `error` are treated as error message. - let error = ExpectedError::parse_inline_tokens(err_tokens) - .map_err(|e| e.at(loc.clone()))?; - (StatementExpect::Error(error), &[][..]) + ["error", res @ ..] => { + if res.len() == 4 && res[0] == "retry" && res[2] == "backoff" { + // `statement error retry backoff ` + // To keep syntax simple, let's assume the error message must be multiline. + (StatementExpect::Error(ExpectedError::Empty), res) + } else { + let error = ExpectedError::parse_inline_tokens(res) + .map_err(|e| e.at(loc.clone()))?; + (StatementExpect::Error(error), &[][..]) + } } ["count", count_str, retry @ ..] => { let count = count_str.parse::().map_err(|_| { @@ -799,12 +803,16 @@ fn parse_inner(loc: &Location, script: &str) -> Result { let (mut expected, res) = match res { - ["error", err_tokens @ ..] => { - // NOTE: `query error` can't be used with `retry` now because all the tokens - // after `error` are treated as error message. - let error = ExpectedError::parse_inline_tokens(err_tokens) - .map_err(|e| e.at(loc.clone()))?; - (QueryExpect::Error(error), &[][..]) + ["error", res @ ..] => { + if res.len() == 4 && res[0] == "retry" && res[2] == "backoff" { + // `query error retry backoff ` + // To keep syntax simple, let's assume the error message must be multiline. + (QueryExpect::Error(ExpectedError::Empty), res) + } else { + let error = ExpectedError::parse_inline_tokens(res) + .map_err(|e| e.at(loc.clone()))?; + (QueryExpect::Error(error), &[][..]) + } } [type_str, res @ ..] => { let types = type_str diff --git a/tests/retry/query_retry.slt b/tests/retry/query_retry.slt index 0c030ab..209bf40 100644 --- a/tests/retry/query_retry.slt +++ b/tests/retry/query_retry.slt @@ -10,7 +10,17 @@ SELECT id FROM test ORDER BY random(); 2 3 -query I retry 1 backoff 500ms +query I retry 2 backoff 500ms SELECT id FROM test; ---- -1 \ No newline at end of file +1 + +query error retry 2 backoff 500ms +SELECT id FROM test; +---- +table not found + +query error +SELECT id FROM test; +---- +table not found diff --git a/tests/retry/statement_retry.slt b/tests/retry/statement_retry.slt index 6559ce6..110f5d0 100644 --- a/tests/retry/statement_retry.slt +++ b/tests/retry/statement_retry.slt @@ -2,4 +2,14 @@ statement ok retry 3 backoff 5s INSERT INTO test VALUES (1); statement count 5 retry 2 backoff 1s -UPDATE test SET value = value + 1; \ No newline at end of file +UPDATE test SET value = value + 1; + +statement error retry 2 backoff 500ms +UPDATE test SET value = value + 1; +---- +table not found + +statement error +UPDATE test SET value = value + 1; +---- +table not found From dce9f1d64aa6c5a156549a49edf303138537c658 Mon Sep 17 00:00:00 2001 From: Eric Fu Date: Fri, 3 Jan 2025 16:31:23 +0800 Subject: [PATCH 2/3] readme Signed-off-by: Eric Fu --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 7032b49..f17aa28 100644 --- a/README.md +++ b/README.md @@ -140,10 +140,22 @@ SELECT id FROM test; ---- 1 +query error retry 3 backoff 5s +SELECT id FROM test; +---- +database error: table not found + statement ok retry 3 backoff 5s UPDATE test SET id = 1; + +statement error +UPDATE test SET value = value + 1; +---- +database error: table not found ``` +Due to the limitation of syntax, the retry clause can't be used along with the single-line regex error message extension. + ### Extension: Environment variable substitution in query and statement It needs to be enabled by adding `control substitution on` to the test file. From 9e99409a170fb51b70d5100f9e0acd590d93f29f Mon Sep 17 00:00:00 2001 From: Eric Fu Date: Fri, 3 Jan 2025 16:43:05 +0800 Subject: [PATCH 3/3] minor fixes Signed-off-by: Eric Fu --- README.md | 1 + tests/retry/query_retry.slt | 2 ++ tests/retry/statement_retry.slt | 2 ++ 3 files changed, 5 insertions(+) diff --git a/README.md b/README.md index f17aa28..f449e82 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ SELECT id FROM test; ---- database error: table not found + statement ok retry 3 backoff 5s UPDATE test SET id = 1; diff --git a/tests/retry/query_retry.slt b/tests/retry/query_retry.slt index 209bf40..73f450e 100644 --- a/tests/retry/query_retry.slt +++ b/tests/retry/query_retry.slt @@ -20,7 +20,9 @@ SELECT id FROM test; ---- table not found + query error SELECT id FROM test; ---- table not found + diff --git a/tests/retry/statement_retry.slt b/tests/retry/statement_retry.slt index 110f5d0..c53a7ef 100644 --- a/tests/retry/statement_retry.slt +++ b/tests/retry/statement_retry.slt @@ -9,7 +9,9 @@ UPDATE test SET value = value + 1; ---- table not found + statement error UPDATE test SET value = value + 1; ---- table not found +