sdf_parser_package/pkg/
functions.rs

1use serde::{Deserialize, Serialize};
2
3use sdf_parser_core::config::transform::{code::Dependency, StepInvocationWrapperV0_5_0};
4
5/// All functions that can be used in the package
6#[derive(Serialize, Deserialize, Debug, Clone)]
7#[serde(tag = "operator")]
8#[serde(rename_all = "kebab-case")]
9pub enum Function {
10    Map(StepInvocationWrapperV0_5_0),
11    Filter(StepInvocationWrapperV0_5_0),
12    FilterMap(StepInvocationWrapperV0_5_0),
13    FlatMap(StepInvocationWrapperV0_5_0),
14    AssignKey(StepInvocationWrapperV0_5_0),
15    AssignTimestamp(StepInvocationWrapperV0_5_0),
16    UpdateState(StepInvocationWrapperV0_5_0),
17    #[serde(rename = "aggregate")]
18    WindowAggregate(StepInvocationWrapperV0_5_0),
19}
20
21impl Function {
22    pub fn name(&self) -> Option<&str> {
23        self.inner().definition.name()
24    }
25    pub fn extra_deps(&self) -> Vec<Dependency> {
26        self.inner().definition.extra_deps()
27    }
28
29    pub fn inner(&self) -> &StepInvocationWrapperV0_5_0 {
30        match self {
31            Self::Map(map) => map,
32            Self::Filter(filter) => filter,
33            Self::FilterMap(filter_map) => filter_map,
34            Self::FlatMap(flat_map) => flat_map,
35            Self::AssignKey(assign_key) => assign_key,
36            Self::AssignTimestamp(assign_timestamp) => assign_timestamp,
37            Self::UpdateState(update_state) => update_state,
38            Self::WindowAggregate(window_aggregate) => window_aggregate,
39        }
40    }
41}