risingwave_frontend/optimizer/plan_node/generic/
mysql_query.rs1use 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#[derive(Debug, Clone, Educe)]
23#[educe(PartialEq, Eq, Hash)]
24pub struct MySqlQuery {
25 pub schema: Schema,
26 pub hostname: String,
27 pub port: String,
28 pub username: String,
29 pub password: String,
30 pub database: String,
31 pub query: String,
32
33 #[educe(PartialEq(ignore))]
34 #[educe(Hash(ignore))]
35 pub ctx: OptimizerContextRef,
36}
37
38impl GenericPlanNode for MySqlQuery {
39 fn schema(&self) -> Schema {
40 self.schema.clone()
41 }
42
43 fn stream_key(&self) -> Option<Vec<usize>> {
44 None
45 }
46
47 fn ctx(&self) -> OptimizerContextRef {
48 self.ctx.clone()
49 }
50
51 fn functional_dependency(&self) -> FunctionalDependencySet {
52 FunctionalDependencySet::new(self.schema.len())
53 }
54}
55
56impl MySqlQuery {
57 pub fn columns(&self) -> Vec<ColumnDesc> {
58 self.schema
59 .fields
60 .iter()
61 .enumerate()
62 .map(|(i, f)| {
63 ColumnDesc::named(f.name.clone(), ColumnId::new(i as i32), f.data_type.clone())
64 })
65 .collect()
66 }
67}