risingwave_frontend/optimizer/plan_node/
batch_iceberg_metadata_scan.rs1use pretty_xmlish::{Pretty, XmlNode};
16use risingwave_connector::sink::iceberg::IcebergMetadataTableType;
17use risingwave_connector::source::iceberg::IcebergTimeTravelInfo;
18use risingwave_pb::batch_plan::IcebergMetadataScanNode;
19use risingwave_pb::batch_plan::iceberg_metadata_scan_node::{MetadataType, TimeTravel};
20use risingwave_pb::batch_plan::plan_node::NodeBody;
21
22use super::batch::prelude::*;
23use super::utils::{Distill, childless_record, column_names_pretty};
24use super::{
25 BatchPlanRef as PlanRef, ExprRewritable, PlanBase, ToBatchPb, ToDistributedBatch, ToLocalBatch,
26 generic,
27};
28use crate::error::Result;
29use crate::optimizer::plan_node::expr_visitable::ExprVisitable;
30use crate::optimizer::property::{Distribution, Order};
31
32#[derive(Debug, Clone, PartialEq, Eq, Hash)]
33pub struct BatchIcebergMetadataScan {
34 pub base: PlanBase<Batch>,
35 pub core: generic::IcebergMetadataScan,
36}
37
38impl BatchIcebergMetadataScan {
39 pub fn new(core: generic::IcebergMetadataScan) -> Self {
40 let base = PlanBase::new_batch_with_core(&core, Distribution::Single, Order::any());
41 Self { base, core }
42 }
43
44 fn clone_with_dist(&self) -> Self {
45 Self {
46 base: self.base.clone_with_new_distribution(Distribution::Single),
47 core: self.core.clone(),
48 }
49 }
50}
51
52impl_plan_tree_node_for_leaf! { Batch, BatchIcebergMetadataScan }
53
54impl Distill for BatchIcebergMetadataScan {
55 fn distill<'a>(&self) -> XmlNode<'a> {
56 let fields = vec![
57 (
58 "metadata_type",
59 Pretty::debug(&self.core.metadata_type.suffix()),
60 ),
61 ("columns", column_names_pretty(self.schema())),
62 ];
63 childless_record("BatchIcebergMetadataScan", fields)
64 }
65}
66
67impl ToLocalBatch for BatchIcebergMetadataScan {
68 fn to_local(&self) -> Result<PlanRef> {
69 Ok(self.clone_with_dist().into())
70 }
71}
72
73impl ToDistributedBatch for BatchIcebergMetadataScan {
74 fn to_distributed(&self) -> Result<PlanRef> {
75 Ok(self.clone_with_dist().into())
76 }
77}
78
79impl ToBatchPb for BatchIcebergMetadataScan {
80 fn to_batch_prost_body(&self) -> NodeBody {
81 let metadata_type = match self.core.metadata_type {
82 IcebergMetadataTableType::Snapshots => MetadataType::Snapshots,
83 IcebergMetadataTableType::Manifests => MetadataType::Manifests,
84 IcebergMetadataTableType::Files => MetadataType::Files,
85 };
86 let time_travel =
87 self.core
88 .time_travel_info
89 .as_ref()
90 .map(|time_travel_info| match time_travel_info {
91 IcebergTimeTravelInfo::Version(snapshot_id) => {
92 TimeTravel::SnapshotId(*snapshot_id)
93 }
94 IcebergTimeTravelInfo::TimestampMs(timestamp_ms) => {
95 TimeTravel::TimestampMs(*timestamp_ms)
96 }
97 });
98
99 NodeBody::IcebergMetadataScan(IcebergMetadataScanNode {
100 with_properties: self.core.properties.clone(),
101 secret_refs: self.core.secret_refs.clone(),
102 metadata_type: metadata_type as i32,
103 time_travel,
104 })
105 }
106}
107
108impl ExprRewritable<Batch> for BatchIcebergMetadataScan {}
109
110impl ExprVisitable for BatchIcebergMetadataScan {}