sql_fun_sqlast/sem/scalar_expr/arith_expr/
null_if.rs1use crate::sem::{AnalysisError, SemScalarExpr, TypeReference, scalar_expr::SemScalarExprNode};
2
3use super::ArithExpr;
4
5#[derive(Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize)]
6pub struct NullIfExpr {
7 return_value: SemScalarExpr,
8 comparison_value: SemScalarExpr,
9}
10
11impl NullIfExpr {
12 pub fn is_not_null(&self) -> Option<bool> {
13 Some(false)
14 }
15
16 pub fn is_strict(&self) -> bool {
17 false
18 }
19}
20
21impl SemScalarExprNode for NullIfExpr {
22 fn get_type(&self) -> Option<TypeReference> {
23 self.return_value.get_type()
24 }
25
26 fn is_not_null(&self) -> Option<bool> {
27 Some(false)
28 }
29}
30
31impl ArithExpr {
32 pub fn build_null_if<TParseContext>(
34 context: TParseContext,
35 lexpr: Option<SemScalarExpr>,
36 rexpr: Option<SemScalarExpr>,
37 ) -> Result<(SemScalarExpr, TParseContext), AnalysisError> {
38 let Some(lexpr) = lexpr else {
39 AnalysisError::raise_unexpected_none("nullif.lexpr")?
40 };
41 let Some(rexpr) = rexpr else {
42 AnalysisError::raise_unexpected_none("nullif.rexpr")?
43 };
44
45 let result = Self::NullIfExpr(Box::new(NullIfExpr {
46 return_value: lexpr,
47 comparison_value: rexpr,
48 }));
49 Ok((SemScalarExpr::Arith(result), context))
50 }
51}