Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy committed Mar 28, 2024
1 parent d6f605a commit f866873
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 38 deletions.
4 changes: 3 additions & 1 deletion src/query/script/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ impl<C: Client> Executor<C> {
}

Err(ErrorCode::ScriptExecutionError(format!(
"max steps exceeded: {}",
"Execution of script has exceeded the limit of {} steps, \
which usually means you may have an infinite loop. Otherwise, \
You can increase the limit with `set script_max_steps = 10000;`.",
self.max_steps
)))
}
Expand Down
41 changes: 5 additions & 36 deletions src/query/script/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use databend_common_script::Client;
use databend_common_script::Executor;
use goldenfile::Mint;

fn run_script(file: &mut dyn Write, src: &str, client: Option<MockClient>) {
fn run_script(file: &mut dyn Write, src: &str) {
let src = unindent::unindent(src);
let src = src.trim();

Expand All @@ -49,7 +49,7 @@ fn run_script(file: &mut dyn Write, src: &str, client: Option<MockClient>) {
script_stmts,
)?;
let ir = compile(&ast)?;
let client = client.unwrap();
let client = mock_client();
let query_log = client.query_log.clone();
let mut executor = Executor::load(client, ir.clone(), 1000);
let result = executor.run()?;
Expand Down Expand Up @@ -97,7 +97,6 @@ fn test_script() {
INSERT INTO t1 VALUES (1, 2, 3);
DROP TABLE t1;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -106,14 +105,12 @@ fn test_script() {
LET y := x + 1;
LET z RESULTSET := SELECT :y + 1;
"#,
mock_client(),
);
run_script(
file,
r#"
RETURN;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -125,7 +122,6 @@ fn test_script() {
END FOR;
RETURN sum;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -136,7 +132,6 @@ fn test_script() {
END FOR;
RETURN sum;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -148,7 +143,6 @@ fn test_script() {
END FOR;
RETURN sum;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -159,7 +153,6 @@ fn test_script() {
END WHILE;
RETURN x;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -171,7 +164,6 @@ fn test_script() {
END REPEAT;
RETURN x;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -189,7 +181,6 @@ fn test_script() {
END LOOP;
END LOOP loop_label;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -201,7 +192,6 @@ fn test_script() {
END LOOP;
RETURN x;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -213,7 +203,6 @@ fn test_script() {
ELSE RETURN 'OTHER';
END CASE;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -225,7 +214,6 @@ fn test_script() {
ELSE RETURN 'OTHER';
END CASE;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -237,7 +225,6 @@ fn test_script() {
ELSE RETURN 'OTHER';
END CASE;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -249,7 +236,6 @@ fn test_script() {
ELSE RETURN 'OTHER';
END CASE;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -261,7 +247,6 @@ fn test_script() {
ELSE RETURN 'OTHER';
END CASE;
"#,
mock_client(),
);
run_script(
file,
Expand All @@ -273,7 +258,6 @@ fn test_script() {
ELSE RETURN 'OTHER';
END CASE;
"#,
mock_client(),
);
}

Expand All @@ -287,55 +271,48 @@ fn test_script_error() {
r#"
LET x := y + 1;
"#,
None,
);
run_script(
file,
r#"
LET x := 1;
LET x RESULTSET := SELECT 1;
"#,
None,
);
run_script(
file,
r#"
LET x RESULTSET := SELECT 1;
LET x := 1;
"#,
None,
);
run_script(
file,
r#"
LET x RESULTSET := SELECT 1;
LET y := x;
"#,
None,
);
run_script(
file,
r#"
LET x := 1;
LET y := x.a;
"#,
None,
);
run_script(
file,
r#"
LET x := 'min';
LET y := IDENTIFIER(:x)([1,2]);
"#,
None,
);
run_script(
file,
r#"
LET x := 1;
LET y := :x + 1;
"#,
None,
);
run_script(
file,
Expand All @@ -345,21 +322,18 @@ fn test_script_error() {
BREAK;
END FOR;
"#,
None,
);
run_script(
file,
r#"
BREAK;
"#,
None,
);
run_script(
file,
r#"
CONTINUE;
"#,
None,
);
run_script(
file,
Expand All @@ -368,7 +342,6 @@ fn test_script_error() {
BREAK foo;
END LOOP bar;
"#,
None,
);
run_script(
file,
Expand All @@ -377,7 +350,6 @@ fn test_script_error() {
CONTINUE foo;
END LOOP bar;
"#,
None,
);
run_script(
file,
Expand All @@ -386,12 +358,11 @@ fn test_script_error() {
CONTINUE;
END LOOP;
"#,
mock_client(),
);
}

fn mock_client() -> Option<MockClient> {
let client = MockClient::new()
fn mock_client() -> MockClient {
MockClient::new()
.response_when(
"SELECT * FROM numbers(3)",
MockBlock::named(vec!["number"], vec![
Expand Down Expand Up @@ -545,9 +516,7 @@ fn mock_client() -> Option<MockClient> {
.response_when(
"SELECT NOT is_true(3 < 3)",
MockBlock::unnamed(vec![vec![Literal::Boolean(true)]]),
);

Some(client)
)
}

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/query/script/tests/it/testdata/script-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ LOOP
CONTINUE;
END LOOP;
---------- Output ----------
max steps exceeded: 1000
Execution of script has exceeded the limit of 1000 steps, which usually means you may have an infinite loop. Otherwise, You can increase the limit with `set script_max_steps = 10000;`.


0 comments on commit f866873

Please sign in to comment.