Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: proof_of_sql_parser::intermediate_ast::UnaryOp with sqlparser::ast::UnaryOp in the proof-of-sql crate #363

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Scalar> OwnedTable<S> {
/// Evaluate an expression on the table.
Expand All @@ -20,7 +21,7 @@ impl<S: Scalar> OwnedTable<S> {
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"),
}),
Expand Down Expand Up @@ -74,6 +75,10 @@ impl<S: Scalar> OwnedTable<S> {
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."),
}),
}
}

Expand Down
9 changes: 7 additions & 2 deletions crates/proof-of-sql/src/sql/parse/dyn_proof_expr_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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:?}"),
}),
}
}

Expand Down
7 changes: 7 additions & 0 deletions crates/proof-of-sql/src/sql/parse/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> for ConversionError {
Expand Down
12 changes: 8 additions & 4 deletions crates/proof-of-sql/src/sql/parse/query_context_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -192,6 +192,10 @@ impl<'a> QueryContextBuilder<'a> {
}
Ok(ColumnType::Boolean)
}
// Handle unsupported operators
_ => Err(ConversionError::UnsupportedOperation {
message: format!("{op:?}"),
}),
}
}

Expand Down
Loading