risingwave_frontend/optimizer/plan_node/
to_prost.rs1use anyhow::anyhow;
16use risingwave_pb::batch_plan::plan_node as pb_batch_node;
17use risingwave_pb::stream_plan::stream_node as pb_stream_node;
18
19use super::*;
20
21pub trait TryToBatchPb {
22 fn try_to_batch_prost_body(&self) -> SchedulerResult<pb_batch_node::NodeBody> {
23 Err(anyhow!(
26 "Node {} cannot be convert to batch node",
27 std::any::type_name::<Self>()
28 )
29 .into())
30 }
31}
32
33pub trait ToBatchPb {
34 fn to_batch_prost_body(&self) -> pb_batch_node::NodeBody;
35}
36
37impl<T: ToBatchPb> TryToBatchPb for T {
38 fn try_to_batch_prost_body(&self) -> SchedulerResult<pb_batch_node::NodeBody> {
39 Ok(self.to_batch_prost_body())
40 }
41}
42
43pub trait TryToStreamPb {
44 fn try_to_stream_prost_body(
45 &self,
46 _state: &mut BuildFragmentGraphState,
47 ) -> SchedulerResult<pb_stream_node::NodeBody> {
48 Err(anyhow!(
51 "Node {} cannot be convert to stream node",
52 std::any::type_name::<Self>()
53 )
54 .into())
55 }
56}
57
58impl<T: StreamNode> TryToStreamPb for T {
59 fn try_to_stream_prost_body(
60 &self,
61 state: &mut BuildFragmentGraphState,
62 ) -> SchedulerResult<pb_stream_node::NodeBody> {
63 Ok(self.to_stream_prost_body(state))
64 }
65}
66
67pub trait StreamNode {
68 fn to_stream_prost_body(&self, state: &mut BuildFragmentGraphState)
69 -> pb_stream_node::NodeBody;
70}