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

Function execute_request

src/environmentd/src/http/sql.rs:1236–1372  ·  view source on GitHub ↗

Executes an entire [`SqlRequest`]. See the user-facing documentation about the HTTP API for a description of the semantics of this function. Executes a SQL request and sends results to the provided sender. Made visible to http submodules (like mcp) via `pub(in crate::http)` to allow reuse of SQL execution logic.

(
    client: &mut AuthedClient,
    request: SqlRequest,
    sender: &mut S,
)

Source from the content-addressed store, hash-verified

1234/// Made visible to http submodules (like mcp) via `pub(in crate::http)` to allow
1235/// reuse of SQL execution logic.
1236pub(in crate::http) async fn execute_request<S: ResultSender>(
1237 client: &mut AuthedClient,
1238 request: SqlRequest,
1239 sender: &mut S,
1240) -> Result<(), Error> {
1241 let client = &mut client.client;
1242
1243 // This API prohibits executing statements with responses whose
1244 // semantics are at odds with an HTTP response.
1245 fn check_prohibited_stmts<S: ResultSender>(
1246 sender: &S,
1247 stmt: &Statement<Raw>,
1248 ) -> Result<(), Error> {
1249 let kind: StatementKind = stmt.into();
1250 let execute_responses = Plan::generated_from(&kind)
1251 .into_iter()
1252 .map(ExecuteResponse::generated_from)
1253 .flatten()
1254 .collect::<Vec<_>>();
1255
1256 // Special-case `COPY TO` statements that are not `COPY ... TO STDOUT`, since
1257 // StatementKind::Copy links to several `ExecuteResponseKind`s that are not supported,
1258 // but this specific statement should be allowed.
1259 let is_valid_copy = matches!(
1260 stmt,
1261 Statement::Copy(CopyStatement {
1262 direction: CopyDirection::To,
1263 target: CopyTarget::Expr(_),
1264 ..
1265 }) | Statement::Copy(CopyStatement {
1266 direction: CopyDirection::From,
1267 target: CopyTarget::Expr(_),
1268 ..
1269 })
1270 );
1271
1272 if !is_valid_copy
1273 && execute_responses.iter().any(|execute_response| {
1274 // Returns true if a statement or execute response are unsupported.
1275 match execute_response {
1276 ExecuteResponseKind::Subscribing if sender.allow_subscribe() => false,
1277 ExecuteResponseKind::Fetch
1278 | ExecuteResponseKind::Subscribing
1279 | ExecuteResponseKind::CopyFrom
1280 | ExecuteResponseKind::DeclaredCursor
1281 | ExecuteResponseKind::ClosedCursor => true,
1282 // Various statements generate `PeekPlan` (`SELECT`, `COPY`,
1283 // `EXPLAIN`, `SHOW`) which has both `SendRows` and `CopyTo` as its
1284 // possible response types. but `COPY` needs be picked out because
1285 // http don't support its response type
1286 ExecuteResponseKind::CopyTo if matches!(kind, StatementKind::Copy) => true,
1287 _ => false,
1288 }
1289 })
1290 {
1291 return Err(Error::Unsupported(stmt.to_ast_string_simple()));
1292 }
1293 Ok(())

Callers 4

execute_promsql_queryFunction · 0.85
handle_sqlFunction · 0.85
run_ws_requestFunction · 0.85
execute_sqlFunction · 0.85

Calls 15

check_prohibited_stmtsFunction · 0.85
execute_stmt_groupFunction · 0.85
send_and_retireFunction · 0.85
SqlResultEnum · 0.85
unwrapMethod · 0.80
parseFunction · 0.70
errFunction · 0.50
as_strMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
to_stringMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected