diff --git a/crates/proof-of-sql/src/base/database/expression_evaluation.rs b/crates/proof-of-sql/src/base/database/expression_evaluation.rs index 9b4da0b90..5400fa805 100644 --- a/crates/proof-of-sql/src/base/database/expression_evaluation.rs +++ b/crates/proof-of-sql/src/base/database/expression_evaluation.rs @@ -9,9 +9,10 @@ use crate::base::{ }; use alloc::{format, string::ToString, vec}; use proof_of_sql_parser::{ - intermediate_ast::{BinaryOperator, Expression, Literal, UnaryOperator}, + intermediate_ast::{BinaryOperator, Expression, Literal}, Identifier, }; +use sqlparser::ast::UnaryOperator; impl OwnedTable { /// Evaluate an expression on the table. @@ -20,7 +21,7 @@ impl OwnedTable { Expression::Column(identifier) => self.evaluate_column(identifier), Expression::Literal(lit) => self.evaluate_literal(lit), Expression::Binary { op, left, right } => self.evaluate_binary_expr(*op, left, right), - Expression::Unary { op, expr } => self.evaluate_unary_expr(*op, expr), + Expression::Unary { op, expr } => self.evaluate_unary_expr((*op).into(), expr), _ => Err(ExpressionEvaluationError::Unsupported { expression: format!("Expression {expr:?} is not supported yet"), }), @@ -74,6 +75,10 @@ impl OwnedTable { let column = self.evaluate(expr)?; match op { UnaryOperator::Not => Ok(column.element_wise_not()?), + // Handle unsupported unary operators + _ => Err(ExpressionEvaluationError::Unsupported { + expression: format!("Unary operator '{op}' is not supported."), + }), } } diff --git a/crates/proof-of-sql/src/sql/parse/dyn_proof_expr_builder.rs b/crates/proof-of-sql/src/sql/parse/dyn_proof_expr_builder.rs index 50550f8c2..a50a271d0 100644 --- a/crates/proof-of-sql/src/sql/parse/dyn_proof_expr_builder.rs +++ b/crates/proof-of-sql/src/sql/parse/dyn_proof_expr_builder.rs @@ -19,10 +19,11 @@ use crate::{ }; use alloc::{borrow::ToOwned, boxed::Box, format, string::ToString}; use proof_of_sql_parser::{ - intermediate_ast::{AggregationOperator, BinaryOperator, Expression, Literal, UnaryOperator}, + intermediate_ast::{AggregationOperator, BinaryOperator, Expression, Literal}, posql_time::{PoSQLTimeUnit, PoSQLTimestampError}, Identifier, }; +use sqlparser::ast::UnaryOperator; /// Builder that enables building a `proofs::sql::proof_exprs::DynProofExpr` from /// a `proof_of_sql_parser::intermediate_ast::Expression`. @@ -60,7 +61,7 @@ impl DynProofExprBuilder<'_> { Expression::Column(identifier) => self.visit_column(*identifier), Expression::Literal(lit) => self.visit_literal(lit), Expression::Binary { op, left, right } => self.visit_binary_expr(*op, left, right), - Expression::Unary { op, expr } => self.visit_unary_expr(*op, expr), + Expression::Unary { op, expr } => self.visit_unary_expr((*op).into(), expr), Expression::Aggregation { op, expr } => self.visit_aggregate_expr(*op, expr), _ => Err(ConversionError::Unprovable { error: format!("Expression {expr:?} is not supported yet"), @@ -136,6 +137,10 @@ impl DynProofExprBuilder<'_> { let expr = self.visit_expr(expr); match op { UnaryOperator::Not => DynProofExpr::try_new_not(expr?), + // Handle unsupported operators + _ => Err(ConversionError::UnsupportedOperation { + message: format!("{op:?}"), + }), } } diff --git a/crates/proof-of-sql/src/sql/parse/error.rs b/crates/proof-of-sql/src/sql/parse/error.rs index c608093dc..908749c2d 100644 --- a/crates/proof-of-sql/src/sql/parse/error.rs +++ b/crates/proof-of-sql/src/sql/parse/error.rs @@ -139,6 +139,13 @@ pub enum ConversionError { /// The underlying error error: String, }, + + #[snafu(display("Unsupported operator: {message}"))] + /// Unsupported operation + UnsupportedOperation { + /// The operator that is unsupported + message: String, + }, } impl From for ConversionError { diff --git a/crates/proof-of-sql/src/sql/parse/query_context_builder.rs b/crates/proof-of-sql/src/sql/parse/query_context_builder.rs index dda1f6101..8e9bd3309 100644 --- a/crates/proof-of-sql/src/sql/parse/query_context_builder.rs +++ b/crates/proof-of-sql/src/sql/parse/query_context_builder.rs @@ -9,15 +9,15 @@ use crate::base::{ BigDecimalExt, }, }; -use alloc::{boxed::Box, string::ToString, vec::Vec}; +use alloc::{boxed::Box, format, string::ToString, vec::Vec}; use proof_of_sql_parser::{ intermediate_ast::{ AggregationOperator, AliasedResultExpr, BinaryOperator, Expression, Literal, OrderBy, - SelectResultExpr, Slice, TableExpression, UnaryOperator, + SelectResultExpr, Slice, TableExpression, }, Identifier, ResourceId, }; - +use sqlparser::ast::UnaryOperator; pub struct QueryContextBuilder<'a> { context: QueryContext, schema_accessor: &'a dyn SchemaAccessor, @@ -137,7 +137,7 @@ impl<'a> QueryContextBuilder<'a> { Expression::Wildcard => Ok(ColumnType::BigInt), // Since COUNT(*) = COUNT(1) Expression::Literal(literal) => self.visit_literal(literal), Expression::Column(_) => self.visit_column_expr(expr), - Expression::Unary { op, expr } => self.visit_unary_expr(*op, expr), + Expression::Unary { op, expr } => self.visit_unary_expr((*op).into(), expr), Expression::Binary { op, left, right } => self.visit_binary_expr(*op, left, right), Expression::Aggregation { op, expr } => self.visit_agg_expr(*op, expr), } @@ -192,6 +192,10 @@ impl<'a> QueryContextBuilder<'a> { } Ok(ColumnType::Boolean) } + // Handle unsupported operators + _ => Err(ConversionError::UnsupportedOperation { + message: format!("{op:?}"), + }), } }