MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / run_sql

Function run_sql

src/testdrive/src/action/sql.rs:34–153  ·  view source on GitHub ↗
(mut cmd: SqlCommand, state: &mut State)

Source from the content-addressed store, hash-verified

32use crate::parser::{FailSqlCommand, SqlCommand, SqlExpectedError, SqlOutput};
33
34pub async fn run_sql(mut cmd: SqlCommand, state: &mut State) -> Result<ControlFlow, anyhow::Error> {
35 use Statement::*;
36
37 state.rewrite_pos_start = cmd.expected_start;
38 state.rewrite_pos_end = cmd.expected_end;
39
40 let stmts = mz_sql_parser::parser::parse_statements(&cmd.query)
41 .with_context(|| format!("unable to parse SQL: {}", cmd.query))?;
42 if stmts.len() != 1 {
43 bail!("expected one statement, but got {}", stmts.len());
44 }
45 let stmt = stmts.into_element().ast;
46 if let SqlOutput::Full { expected_rows, .. } = &mut cmd.expected_output {
47 // TODO(benesch): one day we'll support SQL queries where order matters.
48 expected_rows.sort();
49 }
50
51 let should_retry = match &stmt {
52 // Do not retry FETCH statements as subsequent executions are likely
53 // to return an empty result. The original result would thus be lost.
54 Fetch(_) => false,
55 // EXPLAIN ... PLAN statements should always provide the expected result
56 // on the first try
57 ExplainPlan(_) => false,
58 // DDL statements should always provide the expected result on the first try
59 CreateConnection(_)
60 | CreateCluster(_)
61 | CreateClusterReplica(_)
62 | CreateDatabase(_)
63 | CreateSchema(_)
64 | CreateSource(_)
65 | CreateWebhookSource(_)
66 | CreateSink(_)
67 | CreateMaterializedView(_)
68 | CreateView(_)
69 | CreateTable(_)
70 | CreateTableFromSource(_)
71 | CreateIndex(_)
72 | CreateType(_)
73 | CreateRole(_)
74 | AlterObjectRename(_)
75 | AlterIndex(_)
76 | AlterSink(_)
77 | Discard(_)
78 | DropObjects(_)
79 | SetVariable(_) => false,
80 _ => true,
81 };
82
83 let query = &cmd.query;
84 print_query(query, Some(&stmt));
85 let expected_output = &cmd.expected_output;
86 state.error_line_count = 0;
87 state.error_string = "".to_string();
88 let (state, res) = match should_retry {
89 true => Retry::default()
90 .initial_backoff(state.initial_backoff)
91 .factor(state.backoff_factor)

Callers 1

runMethod · 0.85

Calls 15

print_queryFunction · 0.85
nowFunction · 0.85
try_run_sqlFunction · 0.85
is_var_truthyFunction · 0.85
run_consistency_checksFunction · 0.85
into_elementMethod · 0.80
sortMethod · 0.80
max_triesMethod · 0.80
max_durationMethod · 0.80
factorMethod · 0.80
initial_backoffMethod · 0.80

Tested by

no test coverage detected