reifydb_flow_operator_sdk/
lib.rs1use std::collections::HashMap;
4
5use reifydb_core::{
6 CommitVersion, Row,
7 interface::{FlowNodeId, SourceId},
8};
9use reifydb_type::{RowNumber, Value};
10
11pub mod change;
12pub mod context;
13pub mod error;
14pub mod ffi;
15pub mod marshal;
16pub mod stateful;
17pub mod store;
18pub mod testing;
19
20pub use change::FlowChangeBuilder;
21pub use context::OperatorContext;
22pub use error::{FFIError, Result};
23pub use reifydb_core::{
24 CowVec,
25 key::EncodableKey,
26 value::encoded::{EncodedKey, EncodedValues},
27};
28pub use stateful::State;
29pub use store::Store;
30
31#[derive(Debug, Clone)]
33pub enum FlowChangeOrigin {
34 External(SourceId),
36 Internal(FlowNodeId),
38}
39
40#[derive(Debug, Clone)]
42pub enum FlowDiff {
43 Insert {
45 post: Row,
47 },
48 Update {
50 pre: Row,
52 post: Row,
54 },
55 Remove {
57 pre: Row,
59 },
60}
61
62#[derive(Debug, Clone)]
64pub struct FlowChange {
65 pub origin: FlowChangeOrigin,
67 pub diffs: Vec<FlowDiff>,
69 pub version: CommitVersion,
71}
72
73impl FlowChange {
74 pub fn external(source: SourceId, version: CommitVersion, diffs: Vec<FlowDiff>) -> Self {
76 Self {
77 origin: FlowChangeOrigin::External(source),
78 diffs,
79 version,
80 }
81 }
82
83 pub fn internal(from: FlowNodeId, version: CommitVersion, diffs: Vec<FlowDiff>) -> Self {
85 Self {
86 origin: FlowChangeOrigin::Internal(from),
87 diffs,
88 version,
89 }
90 }
91}
92
93pub trait FFIOperatorMetadata {
96 const NAME: &'static str;
98 const VERSION: u32;
100}
101
102pub trait FFIOperator: Send + Sync + 'static {
105 fn new(operator_id: FlowNodeId, config: &HashMap<String, Value>) -> Result<Self>
107 where
108 Self: Sized;
109
110 fn apply(&mut self, ctx: &mut OperatorContext, input: FlowChange) -> Result<FlowChange>;
112
113 fn get_rows(&mut self, ctx: &mut OperatorContext, row_numbers: &[RowNumber]) -> Result<Vec<Option<Row>>>;
115}
116
117pub trait FFIOperatorWithMetadata: FFIOperator + FFIOperatorMetadata {}
118impl<T> FFIOperatorWithMetadata for T where T: FFIOperator + FFIOperatorMetadata {}
119
120pub mod prelude {
122 pub use reifydb_core::{
123 CowVec, Row,
124 key::EncodableKey,
125 value::encoded::{EncodedKey, EncodedValues},
126 };
127 pub use reifydb_type::{RowNumber, Value};
128
129 pub use crate::{
130 FFIOperator, FFIOperatorMetadata, FFIOperatorWithMetadata, FlowChange, FlowChangeBuilder,
131 FlowChangeOrigin, FlowDiff,
132 context::OperatorContext,
133 error::{FFIError, Result},
134 stateful::State,
135 store::Store,
136 };
137}