reifydb_flow_operator_sdk/
lib.rs1#![cfg_attr(not(debug_assertions), deny(warnings))]
4
5use std::collections::HashMap;
6
7use reifydb_core::{
8 CommitVersion, Row,
9 interface::{FlowNodeId, SourceId},
10};
11use reifydb_type::{RowNumber, TypeConstraint, Value};
12
13pub mod catalog;
14pub mod change;
15pub mod context;
16pub mod error;
17pub mod ffi;
18pub mod marshal;
19pub mod stateful;
20pub mod store;
21pub mod testing;
22
23pub use catalog::Catalog;
24pub use change::FlowChangeBuilder;
25pub use context::OperatorContext;
26pub use error::{FFIError, Result};
27pub use reifydb_core::{
28 CowVec,
29 key::EncodableKey,
30 value::encoded::{EncodedKey, EncodedValues},
31};
32pub use stateful::State;
33pub use store::Store;
34
35#[derive(Debug, Clone)]
37pub enum FlowChangeOrigin {
38 External(SourceId),
40 Internal(FlowNodeId),
42}
43
44#[derive(Debug, Clone)]
46pub enum FlowDiff {
47 Insert {
49 post: Row,
51 },
52 Update {
54 pre: Row,
56 post: Row,
58 },
59 Remove {
61 pre: Row,
63 },
64}
65
66#[derive(Debug, Clone)]
68pub struct FlowChange {
69 pub origin: FlowChangeOrigin,
71 pub diffs: Vec<FlowDiff>,
73 pub version: CommitVersion,
75}
76
77impl FlowChange {
78 pub fn external(source: SourceId, version: CommitVersion, diffs: Vec<FlowDiff>) -> Self {
80 Self {
81 origin: FlowChangeOrigin::External(source),
82 diffs,
83 version,
84 }
85 }
86
87 pub fn internal(from: FlowNodeId, version: CommitVersion, diffs: Vec<FlowDiff>) -> Self {
89 Self {
90 origin: FlowChangeOrigin::Internal(from),
91 diffs,
92 version,
93 }
94 }
95}
96
97#[derive(Debug, Clone)]
99pub struct OperatorColumnDef {
100 pub name: &'static str,
102 pub field_type: TypeConstraint,
104 pub description: &'static str,
106}
107
108pub trait FFIOperatorMetadata {
111 const NAME: &'static str;
113 const API: u32;
115 const VERSION: &'static str;
117 const DESCRIPTION: &'static str;
119 const INPUT_COLUMNS: &'static [OperatorColumnDef];
121 const OUTPUT_COLUMNS: &'static [OperatorColumnDef];
123 const CAPABILITIES: u32;
126}
127
128pub trait FFIOperator: Send + Sync + 'static {
131 fn new(operator_id: FlowNodeId, config: &HashMap<String, Value>) -> Result<Self>
133 where
134 Self: Sized;
135
136 fn apply(&mut self, ctx: &mut OperatorContext, input: FlowChange) -> Result<FlowChange>;
138
139 fn get_rows(&mut self, ctx: &mut OperatorContext, row_numbers: &[RowNumber]) -> Result<Vec<Option<Row>>>;
141}
142
143pub trait FFIOperatorWithMetadata: FFIOperator + FFIOperatorMetadata {}
144impl<T> FFIOperatorWithMetadata for T where T: FFIOperator + FFIOperatorMetadata {}
145
146pub mod prelude {
148 pub use reifydb_core::{
149 CowVec, Row,
150 key::EncodableKey,
151 value::encoded::{EncodedKey, EncodedValues},
152 };
153 pub use reifydb_flow_operator_abi::{
154 CAPABILITY_ALL_STANDARD, CAPABILITY_DELETE, CAPABILITY_DROP, CAPABILITY_GET_ROWS, CAPABILITY_INSERT,
155 CAPABILITY_TICK, CAPABILITY_UPDATE, has_capability,
156 };
157 pub use reifydb_type::{RowNumber, Type, TypeConstraint, Value};
158
159 pub use crate::{
160 Catalog, FFIOperator, FFIOperatorMetadata, FFIOperatorWithMetadata, FlowChange, FlowChangeBuilder,
161 FlowChangeOrigin, FlowDiff, OperatorColumnDef,
162 context::OperatorContext,
163 error::{FFIError, Result},
164 stateful::State,
165 store::Store,
166 };
167}