risingwave_frontend/optimizer/plan_node/generic/
dedup.rsuse pretty_xmlish::{Pretty, Str, XmlNode};
use risingwave_common::catalog::{FieldDisplay, Schema};
use super::{DistillUnit, GenericPlanNode, GenericPlanRef};
use crate::optimizer::plan_node::utils::childless_record;
use crate::optimizer::property::FunctionalDependencySet;
use crate::OptimizerContextRef;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Dedup<PlanRef> {
pub input: PlanRef,
pub dedup_cols: Vec<usize>,
}
impl<PlanRef: GenericPlanRef> Dedup<PlanRef> {
fn dedup_cols_pretty<'a>(&self) -> Pretty<'a> {
Pretty::Array(
self.dedup_cols
.iter()
.map(|i| FieldDisplay(self.input.schema().fields.get(*i).unwrap()))
.map(|fd| Pretty::display(&fd))
.collect(),
)
}
}
impl<PlanRef: GenericPlanRef> DistillUnit for Dedup<PlanRef> {
fn distill_with_name<'a>(&self, name: impl Into<Str<'a>>) -> XmlNode<'a> {
childless_record(name, vec![("dedup_cols", self.dedup_cols_pretty())])
}
}
impl<PlanRef: GenericPlanRef> GenericPlanNode for Dedup<PlanRef> {
fn schema(&self) -> Schema {
self.input.schema().clone()
}
fn stream_key(&self) -> Option<Vec<usize>> {
Some(self.dedup_cols.clone())
}
fn ctx(&self) -> OptimizerContextRef {
self.input.ctx()
}
fn functional_dependency(&self) -> FunctionalDependencySet {
self.input.functional_dependency().clone()
}
}