Skip to main content

substrait/parse/text/simple_extensions/
boolean_expr.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Boolean expressions retained in type derivations without evaluation.
4
5use std::fmt;
6
7use super::types::IntegerParameter;
8
9/// A boolean-valued expression. Integer and type expressions cannot be used as conditions.
10#[derive(Clone, Debug, PartialEq)]
11pub enum BooleanExpr {
12    /// A comparison of two integers.
13    Compare {
14        /// The comparison operator.
15        op: ComparisonOp,
16        /// The left integer operand.
17        left: Box<IntegerParameter>,
18        /// The right integer operand.
19        right: Box<IntegerParameter>,
20    },
21}
22
23/// A comparison of integer expressions.
24#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25pub enum ComparisonOp {
26    /// Greater than.
27    Greater,
28}
29
30impl fmt::Display for ComparisonOp {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        match self {
33            Self::Greater => f.write_str(">"),
34        }
35    }
36}
37
38impl fmt::Display for BooleanExpr {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            Self::Compare { op, left, right } => write!(f, "({left}) {op} ({right})"),
42        }
43    }
44}