use crate::planner::{argument::TransformationArgument, arithmetic::ArithmeticArgument};
use crate::catalog::ComparisonExprPos;
use crate::parser::ComparisonOperator;
use std::fmt;
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub(crate) struct ComparisonExprArgument {
left: ArithmeticArgument,
operator: ComparisonOperator,
right: ArithmeticArgument,
}
impl ComparisonExprArgument {
pub(crate) fn from_comparison_expr(
compare_expr: &ComparisonExprPos,
left_arguments: &[TransformationArgument],
right_arguments: &[TransformationArgument],
) -> Self {
let left = ArithmeticArgument::from_arithmeticpos(compare_expr.left(), left_arguments);
let right = ArithmeticArgument::from_arithmeticpos(compare_expr.right(), right_arguments);
let operator = compare_expr.operator().clone();
Self {
left,
operator,
right,
}
}
pub(crate) fn operator(&self) -> &ComparisonOperator {
&self.operator
}
pub(crate) fn left(&self) -> &ArithmeticArgument {
&self.left
}
pub(crate) fn right(&self) -> &ArithmeticArgument {
&self.right
}
}
impl fmt::Display for ComparisonExprArgument {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} {} {}", self.left, self.operator, self.right)
}
}