Skip to content
Snippets Groups Projects
Commit 70056c8b authored by Igor Kuznetsov's avatar Igor Kuznetsov
Browse files

feat: add api method for transforming text to Bool type

parent 7ebe1d66
No related branches found
No related tags found
1 merge request!1414sbroad import
use super::*;
use crate::ir::value::*;
use crate::ir::*;
use pretty_assertions::assert_eq;
......
//! Operators for expression transformations.
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::errors::QueryPlannerError;
use super::expression::Expression;
use super::relation::Table;
use super::{Node, Nodes, Plan};
use crate::errors::QueryPlannerError;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Binary operator returning Bool expression.
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub enum Bool {
/// `&&`
And,
......@@ -30,6 +33,27 @@ pub enum Bool {
Or,
}
impl Bool {
/// Create `Bool` from operator string.
///
/// # Errors
/// Returns `QueryPlannerError` when the operator is invalid.
pub fn from(s: &str) -> Result<Self, QueryPlannerError> {
match s.to_lowercase().as_str() {
"and" => Ok(Bool::And),
"or" => Ok(Bool::Or),
"=" => Ok(Bool::Eq),
"in" => Ok(Bool::In),
">" => Ok(Bool::Gt),
">=" => Ok(Bool::GtEq),
"<" => Ok(Bool::Lt),
"<=" => Ok(Bool::LtEq),
"!=" | "<>" => Ok(Bool::NotEq),
_ => Err(QueryPlannerError::InvalidBool),
}
}
}
/// Relational algebra operator returning a new tuple.
///
/// Transforms input tuple(s) into the output one using
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment