reifydb_flow_operator_sdk/
context.rs1use reifydb_core::{EncodedKey, interface::FlowNodeId};
4use reifydb_flow_operator_abi::FFIContext;
5use reifydb_type::RowNumber;
6
7use crate::{
8 stateful::{RowNumberProvider, State},
9 store::Store,
10};
11
12pub struct OperatorContext {
14 pub(crate) ctx: *mut FFIContext,
15}
16
17impl OperatorContext {
18 pub fn new(ctx: *mut FFIContext) -> Self {
23 assert!(!ctx.is_null(), "FFIContext pointer must not be null");
24 Self {
25 ctx,
26 }
27 }
28
29 pub fn operator_id(&self) -> FlowNodeId {
31 unsafe { FlowNodeId((*self.ctx).operator_id) }
32 }
33
34 pub fn state(&mut self) -> State<'_> {
36 State::new(self)
37 }
38
39 pub fn store(&mut self) -> Store<'_> {
41 Store::new(self)
42 }
43
44 pub fn catalog(&mut self) -> crate::Catalog<'_> {
46 crate::Catalog::new(self)
47 }
48
49 pub fn get_or_create_row_number(&mut self, key: &EncodedKey) -> crate::Result<(RowNumber, bool)> {
58 let provider = RowNumberProvider::new(self.operator_id());
59 provider.get_or_create_row_number(self, key)
60 }
61}