sdf_parser_package/pkg/
functions.rs

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