Skip to main content

qql_core/ast/
formula.rs

1use super::{FilterExpr, Value};
2use alloc::boxed::Box;
3use alloc::string::String;
4use alloc::vec::Vec;
5
6#[derive(Debug, Clone, PartialEq)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub enum FormulaExpr {
9    Constant {
10        value: f64,
11    },
12    Variable {
13        name: String,
14    },
15    Sum {
16        left: Box<FormulaExpr>,
17        right: Box<FormulaExpr>,
18    },
19    Sub {
20        left: Box<FormulaExpr>,
21        right: Box<FormulaExpr>,
22    },
23    Mul {
24        left: Box<FormulaExpr>,
25        right: Box<FormulaExpr>,
26    },
27    Div {
28        left: Box<FormulaExpr>,
29        right: Box<FormulaExpr>,
30        by_zero_default: Option<f64>,
31    },
32    Neg {
33        operand: Box<FormulaExpr>,
34    },
35    Abs {
36        x: Box<FormulaExpr>,
37    },
38    Sqrt {
39        x: Box<FormulaExpr>,
40    },
41    Log {
42        x: Box<FormulaExpr>,
43    },
44    Ln {
45        x: Box<FormulaExpr>,
46    },
47    Exp {
48        x: Box<FormulaExpr>,
49    },
50    Pow {
51        base: Box<FormulaExpr>,
52        exponent: Box<FormulaExpr>,
53    },
54    GeoDistance {
55        lat: f64,
56        lon: f64,
57        field: String,
58    },
59    Decay {
60        kind: String,
61        x: Box<FormulaExpr>,
62        target: Option<Box<FormulaExpr>>,
63        scale: Option<f64>,
64        midpoint: Option<f64>,
65    },
66    Case {
67        cond: Box<FilterExpr>,
68        then_: Box<FormulaExpr>,
69        else_: Box<FormulaExpr>,
70    },
71    MatchCondition {
72        field: String,
73        values: Vec<Value>,
74    },
75    Datetime {
76        value: String,
77    },
78    DatetimeKey {
79        key: String,
80    },
81}