sdf_parser_package/pkg/
functions.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use serde::{Deserialize, Serialize};

use sdf_parser_core::config::transform::{code::Dependency, StepInvocationWrapperV0_5_0};

/// All functions that can be used in the package
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "operator")]
#[serde(rename_all = "kebab-case")]
pub enum Function {
    Map(StepInvocationWrapperV0_5_0),
    Filter(StepInvocationWrapperV0_5_0),
    FilterMap(StepInvocationWrapperV0_5_0),
    FlatMap(StepInvocationWrapperV0_5_0),
    AssignKey(StepInvocationWrapperV0_5_0),
    AssignTimestamp(StepInvocationWrapperV0_5_0),
    UpdateState(StepInvocationWrapperV0_5_0),
    #[serde(rename = "aggregate")]
    WindowAggregate(StepInvocationWrapperV0_5_0),
}

impl Function {
    pub fn extra_deps(&self) -> Vec<Dependency> {
        self.inner().definition.extra_deps()
    }

    pub fn inner(&self) -> &StepInvocationWrapperV0_5_0 {
        match self {
            Self::Map(map) => map,
            Self::Filter(filter) => filter,
            Self::FilterMap(filter_map) => filter_map,
            Self::FlatMap(flat_map) => flat_map,
            Self::AssignKey(assign_key) => assign_key,
            Self::AssignTimestamp(assign_timestamp) => assign_timestamp,
            Self::UpdateState(update_state) => update_state,
            Self::WindowAggregate(window_aggregate) => window_aggregate,
        }
    }
}