Skip to main content

openpql_pql_parser/ast/
selector_kind.rs

1use super::fmt;
2
3/// Aggregate kind used by a selector.
4#[derive(Clone, Copy, PartialEq, Eq, derive_more::Debug)]
5pub enum SelectorKind {
6    /// Mean over matching rows.
7    #[debug("avg")]
8    Avg,
9    /// Count of matching rows.
10    #[debug("count")]
11    Count,
12    /// Maximum value.
13    #[debug("max")]
14    Max,
15    /// Minimum value.
16    #[debug("min")]
17    Min,
18}
19
20impl fmt::Display for SelectorKind {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match *self {
23            Self::Avg => f.write_str("AVG"),
24            Self::Count => f.write_str("COUNT"),
25            Self::Max => f.write_str("MAX"),
26            Self::Min => f.write_str("MIN"),
27        }
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn test_display() {
37        assert_eq!(SelectorKind::Avg.to_string(), "AVG");
38        assert_eq!(SelectorKind::Count.to_string(), "COUNT");
39        assert_eq!(SelectorKind::Max.to_string(), "MAX");
40        assert_eq!(SelectorKind::Min.to_string(), "MIN");
41    }
42}