risingwave_frontend/optimizer/plan_node/generic/mssql_query.rs
1// Copyright 2026 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use educe::Educe;
16use risingwave_common::catalog::{ColumnDesc, ColumnId, Schema};
17
18use super::GenericPlanNode;
19use crate::optimizer::optimizer_context::OptimizerContextRef;
20use crate::optimizer::property::FunctionalDependencySet;
21
22/// SQL Server connection parameters for an `mssql_query` plan.
23#[derive(Debug, Clone, PartialEq, Eq, Hash)]
24pub struct MssqlConnection {
25 pub hostname: String,
26 pub port: String,
27 pub username: String,
28 pub password: String,
29 pub database: String,
30 /// Whether all SQL Server traffic must use TLS.
31 pub encrypt: bool,
32 /// Whether to skip TLS certificate-chain and hostname validation.
33 /// This is a boolean setting, not certificate content or a file path.
34 pub trust_cert: bool,
35}
36
37/// Generic (logical) plan node for the `mssql_query` table function.
38/// Carries the connection parameters, the pre-discovered schema, and the
39/// user query. This is the shared body used by both
40/// [`crate::optimizer::plan_node::LogicalMssqlQuery`] and
41/// [`crate::optimizer::plan_node::BatchMssqlQuery`] via the
42/// convention-generic `GenericPlanNode` trait.
43#[derive(Debug, Clone, Educe)]
44#[educe(PartialEq, Eq, Hash)]
45pub struct MssqlQuery {
46 /// Result schema discovered at bind time by `describe_mssql_query`.
47 pub schema: Schema,
48 pub connection: MssqlConnection,
49 pub query: String,
50 #[educe(PartialEq(ignore))]
51 #[educe(Hash(ignore))]
52 pub ctx: OptimizerContextRef,
53}
54
55impl GenericPlanNode for MssqlQuery {
56 /// Return the pre-discovered result schema.
57 fn schema(&self) -> Schema {
58 self.schema.clone()
59 }
60
61 /// `mssql_query` does not produce a stream key — the executor returns
62 /// rows in whatever order SQL Server produces them.
63 fn stream_key(&self) -> Option<Vec<usize>> {
64 None
65 }
66
67 /// Return the optimizer context associated with this node.
68 fn ctx(&self) -> OptimizerContextRef {
69 self.ctx.clone()
70 }
71
72 /// No non-trivial functional dependencies are known for an arbitrary
73 /// user-provided query; report a fresh empty FD set.
74 fn functional_dependency(&self) -> FunctionalDependencySet {
75 FunctionalDependencySet::new(self.schema.len())
76 }
77}
78
79impl MssqlQuery {
80 /// Build the [`ColumnDesc`] list consumed by `BatchMssqlQuery::to_batch_prost_body`.
81 /// Column ids are placeholder-based — the executor does not depend on them.
82 pub fn columns(&self) -> Vec<ColumnDesc> {
83 self.schema
84 .fields
85 .iter()
86 .enumerate()
87 .map(|(i, f)| {
88 ColumnDesc::named(f.name.clone(), ColumnId::new(i as i32), f.data_type.clone())
89 })
90 .collect()
91 }
92}