mz_sql/plan/statement/
validate.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Queries that validate CONNECTION objects.
11
12use crate::ast::ValidateConnectionStatement;
13use crate::names::Aug;
14use crate::plan::statement::{StatementContext, StatementDesc};
15use crate::plan::{Plan, PlanError, ValidateConnectionPlan};
16use crate::session::vars;
17
18pub fn describe_validate_connection(
19    _: &StatementContext,
20    _: ValidateConnectionStatement<Aug>,
21) -> Result<StatementDesc, PlanError> {
22    Ok(StatementDesc::new(None))
23}
24
25pub fn plan_validate_connection(
26    scx: &StatementContext,
27    stmt: ValidateConnectionStatement<Aug>,
28) -> Result<Plan, PlanError> {
29    scx.require_feature_flag(&vars::ENABLE_CONNECTION_VALIDATION_SYNTAX)?;
30    let item = scx.get_item_by_resolved_name(&stmt.name)?;
31
32    // Validate the target of the validate statement.
33    match item.connection() {
34        Ok(connection) => Ok(Plan::ValidateConnection(ValidateConnectionPlan {
35            id: item.id(),
36            connection,
37        })),
38        Err(_) => {
39            sql_bail!(
40                "cannot validate {} '{}'",
41                item.item_type(),
42                stmt.name.full_name_str()
43            );
44        }
45    }
46}