From 5763f53c32353ba882894c8b88c7de9a5be2b306 Mon Sep 17 00:00:00 2001 From: Ian Joiner <14581281+iajoiner@users.noreply.github.com> Date: Thu, 7 Nov 2024 02:24:24 -0500 Subject: [PATCH] refactor!: replace operator in unary and binaryop-related errors with string This makes it easier to migrate from a particular implementation of parser and remove the need to pass in UnaryOp / BinaryOp --- .../base/database/column_operation_error.rs | 9 ++++---- .../base/database/column_type_operation.rs | 8 +++---- .../base/database/owned_column_operation.rs | 21 +++++++++---------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/crates/proof-of-sql/src/base/database/column_operation_error.rs b/crates/proof-of-sql/src/base/database/column_operation_error.rs index 7be9d2fcc..cfef44bb5 100644 --- a/crates/proof-of-sql/src/base/database/column_operation_error.rs +++ b/crates/proof-of-sql/src/base/database/column_operation_error.rs @@ -1,7 +1,6 @@ use crate::base::{database::ColumnType, math::decimal::DecimalError}; use alloc::string::String; use core::result::Result; -use proof_of_sql_parser::intermediate_ast::{BinaryOperator, UnaryOperator}; use snafu::Snafu; /// Errors from operations on columns. @@ -19,8 +18,8 @@ pub enum ColumnOperationError { /// Incorrect `ColumnType` in binary operations #[snafu(display("{operator:?}(lhs: {left_type:?}, rhs: {right_type:?}) is not supported"))] BinaryOperationInvalidColumnType { - /// `BinaryOperator` that caused the error - operator: BinaryOperator, + /// Binary operator that caused the error + operator: String, /// `ColumnType` of left operand left_type: ColumnType, /// `ColumnType` of right operand @@ -30,8 +29,8 @@ pub enum ColumnOperationError { /// Incorrect `ColumnType` in unary operations #[snafu(display("{operator:?}(operand: {operand_type:?}) is not supported"))] UnaryOperationInvalidColumnType { - /// `UnaryOperator` that caused the error - operator: UnaryOperator, + /// Unary operator that caused the error + operator: String, /// `ColumnType` of the operand operand_type: ColumnType, }, diff --git a/crates/proof-of-sql/src/base/database/column_type_operation.rs b/crates/proof-of-sql/src/base/database/column_type_operation.rs index 21300dfd5..2c496b95c 100644 --- a/crates/proof-of-sql/src/base/database/column_type_operation.rs +++ b/crates/proof-of-sql/src/base/database/column_type_operation.rs @@ -19,11 +19,11 @@ use proof_of_sql_parser::intermediate_ast::BinaryOperator; pub fn try_add_subtract_column_types( lhs: ColumnType, rhs: ColumnType, - operator: BinaryOperator, + _operator: BinaryOperator, ) -> ColumnOperationResult { if !lhs.is_numeric() || !rhs.is_numeric() { return Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator, + operator: "+/-".to_string(), left_type: lhs, right_type: rhs, }); @@ -77,7 +77,7 @@ pub fn try_multiply_column_types( ) -> ColumnOperationResult { if !lhs.is_numeric() || !rhs.is_numeric() { return Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::Multiply, + operator: "*".to_string(), left_type: lhs, right_type: rhs, }); @@ -132,7 +132,7 @@ pub fn try_divide_column_types( || rhs == ColumnType::Scalar { return Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::Division, + operator: "/".to_string(), left_type: lhs, right_type: rhs, }); diff --git a/crates/proof-of-sql/src/base/database/owned_column_operation.rs b/crates/proof-of-sql/src/base/database/owned_column_operation.rs index 7b021356c..dcd512aef 100644 --- a/crates/proof-of-sql/src/base/database/owned_column_operation.rs +++ b/crates/proof-of-sql/src/base/database/owned_column_operation.rs @@ -17,7 +17,6 @@ use crate::base::{ scalar::Scalar, }; use core::ops::{Add, Div, Mul, Sub}; -use proof_of_sql_parser::intermediate_ast::{BinaryOperator, UnaryOperator}; impl OwnedColumn { /// Element-wise NOT operation for a column @@ -25,7 +24,7 @@ impl OwnedColumn { match self { Self::Boolean(values) => Ok(Self::Boolean(slice_not(values))), _ => Err(ColumnOperationError::UnaryOperationInvalidColumnType { - operator: UnaryOperator::Not, + operator: "NOT".to_string(), operand_type: self.column_type(), }), } @@ -42,7 +41,7 @@ impl OwnedColumn { match (self, rhs) { (Self::Boolean(lhs), Self::Boolean(rhs)) => Ok(Self::Boolean(slice_and(lhs, rhs))), _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::And, + operator: "AND".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }), @@ -60,7 +59,7 @@ impl OwnedColumn { match (self, rhs) { (Self::Boolean(lhs), Self::Boolean(rhs)) => Ok(Self::Boolean(slice_or(lhs, rhs))), _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::Or, + operator: "OR".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }), @@ -242,7 +241,7 @@ impl OwnedColumn { todo!("Implement equality check for TimeStampTZ") } _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::Equal, + operator: "=".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }), @@ -423,7 +422,7 @@ impl OwnedColumn { todo!("Implement inequality check for TimeStampTZ") } _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::LessThanOrEqual, + operator: "<=".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }), @@ -604,7 +603,7 @@ impl OwnedColumn { todo!("Implement inequality check for TimeStampTZ") } _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::GreaterThanOrEqual, + operator: ">=".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }), @@ -798,7 +797,7 @@ impl Add for OwnedColumn { Ok(Self::Decimal75(new_precision, new_scale, new_values)) } _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::Add, + operator: "+".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }), @@ -996,7 +995,7 @@ impl Sub for OwnedColumn { Ok(Self::Decimal75(new_precision, new_scale, new_values)) } _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::Subtract, + operator: "-".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }), @@ -1194,7 +1193,7 @@ impl Mul for OwnedColumn { Ok(Self::Decimal75(new_precision, new_scale, new_values)) } _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::Multiply, + operator: "*".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }), @@ -1392,7 +1391,7 @@ impl Div for OwnedColumn { Ok(Self::Decimal75(new_precision, new_scale, new_values)) } _ => Err(ColumnOperationError::BinaryOperationInvalidColumnType { - operator: BinaryOperator::Division, + operator: "/".to_string(), left_type: self.column_type(), right_type: rhs.column_type(), }),