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!: remove IntermediateDecimal in favor of BigDecimal #283

Merged
merged 10 commits into from
Oct 21, 2024
Merged
9 changes: 5 additions & 4 deletions crates/proof-of-sql-parser/src/intermediate_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* https://docs.rs/vervolg/latest/vervolg/ast/enum.Statement.html
***/

use crate::{intermediate_decimal::IntermediateDecimal, posql_time::PoSQLTimestamp, Identifier};
use crate::{posql_time::PoSQLTimestamp, Identifier};
use alloc::{boxed::Box, string::String, vec::Vec};
use bigdecimal::BigDecimal;
use core::{
fmt,
fmt::{Display, Formatter},
Expand Down Expand Up @@ -345,7 +346,7 @@ pub enum Literal {
/// String Literal
VarChar(String),
/// Decimal Literal
Decimal(IntermediateDecimal),
Decimal(BigDecimal),
/// Timestamp Literal
Timestamp(PoSQLTimestamp),
}
Expand Down Expand Up @@ -395,8 +396,8 @@ macro_rules! impl_string_to_literal {
impl_string_to_literal!(&str);
impl_string_to_literal!(String);

impl From<IntermediateDecimal> for Literal {
fn from(val: IntermediateDecimal) -> Self {
impl From<BigDecimal> for Literal {
fn from(val: BigDecimal) -> Self {
Literal::Decimal(val)
}
}
Expand Down
17 changes: 4 additions & 13 deletions crates/proof-of-sql-parser/src/intermediate_ast_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
intermediate_ast::OrderByDirection::{Asc, Desc},
intermediate_decimal::IntermediateDecimal,
sql::*,
utility::*,
SelectStatement,
Expand All @@ -10,6 +9,7 @@ use alloc::{
string::{String, ToString},
vec,
};
use bigdecimal::BigDecimal;

// Sting parser tests
#[test]
Expand Down Expand Up @@ -143,10 +143,7 @@ fn we_can_parse_a_query_with_constants() {
col_res(lit(3), "bigint"),
col_res(lit(true), "boolean"),
col_res(lit("proof"), "varchar"),
col_res(
lit(IntermediateDecimal::try_from("-2.34").unwrap()),
"decimal",
),
col_res(lit("-2.34".parse::<BigDecimal>().unwrap()), "decimal"),
],
tab(None, "sxt_tab"),
vec![],
Expand Down Expand Up @@ -220,10 +217,7 @@ fn we_can_parse_a_query_with_a_column_equals_a_decimal() {
query(
cols_res(&["a"]),
tab(None, "sxt_tab"),
equal(
col("a"),
lit(IntermediateDecimal::try_from("-0.32").unwrap()),
),
equal(col("a"), lit("-0.32".parse::<BigDecimal>().unwrap())),
vec![],
),
vec![],
Expand Down Expand Up @@ -441,10 +435,7 @@ fn we_can_parse_a_query_with_one_logical_or_filter_expression() {
tab(None, "sxt_tab"),
or(
equal(col("b"), lit(3)),
equal(
col("c"),
lit(IntermediateDecimal::try_from("-2.34").unwrap()),
),
equal(col("c"), lit("-2.34".parse::<BigDecimal>().unwrap())),
),
vec![],
),
Expand Down
273 changes: 0 additions & 273 deletions crates/proof-of-sql-parser/src/intermediate_decimal.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/proof-of-sql-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#![cfg_attr(test, allow(clippy::missing_panics_doc))]
extern crate alloc;

/// Module for handling an intermediate decimal type received from the lexer.
pub mod intermediate_decimal;
/// Module for handling an intermediate timestamp type received from the lexer.
pub mod posql_time;
#[macro_use]
Expand Down
7 changes: 4 additions & 3 deletions crates/proof-of-sql-parser/src/sql.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use crate::intermediate_ast;
use crate::select_statement;
use crate::identifier;
use lalrpop_util::ParseError::User;
use crate::{intermediate_decimal::IntermediateDecimal, posql_time::PoSQLTimestamp};
use crate::posql_time::PoSQLTimestamp;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;
use bigdecimal::BigDecimal;

grammar;

Expand Down Expand Up @@ -356,8 +357,8 @@ Int128UnaryNumericLiteral: i128 = {
"-" <expr: Int128UnaryNumericLiteral> =>? expr.checked_neg().ok_or(User {error: "Integer overflow"}),
};

DecimalNumericLiteral: IntermediateDecimal = {
<lit:DECIMAL_LIT> =>? IntermediateDecimal::try_from(lit).map_err(|e| User {error: "decimal out of range"}),
DecimalNumericLiteral: BigDecimal = {
<lit:DECIMAL_LIT> =>? <>.parse::<BigDecimal>().map_err(|e| User {error: "decimal out of range"}),
};

Int128NumericLiteral: i128 = {
Expand Down
Loading
Loading