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

Added the separated big_decimal_ext #196

Closed
Closed
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["crates/proof-of-sql", "crates/proof-of-sql-parser"]
members = ["crates/proof-of-sql", "crates/proof-of-sql-parser","crates/proof-of-sql-utils"]

[workspace.package]
edition = "2021"
Expand Down
1 change: 1 addition & 0 deletions crates/proof-of-sql-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ chrono = { workspace = true, features = ["serde"] }
lalrpop-util = { workspace = true, features = ["lexer", "unicode"] }
serde = { workspace = true, features = ["serde_derive", "alloc"] }
snafu = { workspace = true }
proof_of_sql_utils = { path = "../proof-of-sql-utils" }

[build-dependencies]
lalrpop = { workspace = true }
Expand Down
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,14 +4,15 @@
* 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 core::{
fmt,
fmt::{Display, Formatter},
hash::Hash,
};
use serde::{Deserialize, Serialize};
use bigdecimal::BigDecimal;

/// Representation of a SetExpression, a collection of rows, each having one or more columns.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -333,7 +334,7 @@ pub enum Literal {
/// String Literal
VarChar(String),
/// Decimal Literal
Decimal(IntermediateDecimal),
Decimal(BigDecimal),
/// Timestamp Literal
Timestamp(PoSQLTimestamp),
}
Expand Down Expand Up @@ -383,8 +384,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
9 changes: 4 additions & 5 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 Down Expand Up @@ -139,7 +138,7 @@ fn we_can_parse_a_query_with_constants() {
col_res(lit(true), "boolean"),
col_res(lit("proof"), "varchar"),
col_res(
lit(IntermediateDecimal::try_from("-2.34").unwrap()),
lit(BigDecimal::try_from("-2.34").unwrap()),
"decimal",
),
],
Expand Down Expand Up @@ -217,7 +216,7 @@ fn we_can_parse_a_query_with_a_column_equals_a_decimal() {
tab(None, "sxt_tab"),
equal(
col("a"),
lit(IntermediateDecimal::try_from("-0.32").unwrap()),
lit(BigDecimal::try_from("-0.32").unwrap()),
),
vec![],
),
Expand Down Expand Up @@ -425,7 +424,7 @@ fn we_can_parse_a_query_with_one_logical_and_filter_expression_with_both_left_an
assert_eq!(ast, expected_ast);
}

#[test]
#[test]
fn we_can_parse_a_query_with_one_logical_or_filter_expression() {
let ast = "select a from sxt_tab where (b = 3) or (c = -2.34);"
.parse::<SelectStatement>()
Expand All @@ -438,7 +437,7 @@ fn we_can_parse_a_query_with_one_logical_or_filter_expression() {
equal(col("b"), lit(3)),
equal(
col("c"),
lit(IntermediateDecimal::try_from("-2.34").unwrap()),
lit(BigDecimal::try_from("-2.34").unwrap()),
),
),
vec![],
Expand Down
257 changes: 0 additions & 257 deletions crates/proof-of-sql-parser/src/intermediate_decimal.rs

This file was deleted.

5 changes: 2 additions & 3 deletions crates/proof-of-sql-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#![no_std]
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]
extern crate lalrpop_util;
Expand Down
8 changes: 5 additions & 3 deletions crates/proof-of-sql-parser/src/sql.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ 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 proof_of_sql_utils::big_decimal_ext::BigDecimalExt;
use bigdecimal::BigDecimal;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec;
Expand Down Expand Up @@ -356,8 +358,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> =>? BigDecimal::try_from(lit).map_err(|e| User {error: "decimal out of range"}),
};

Int128NumericLiteral: i128 = {
Expand Down
Loading
Loading