Skip to content
Snippets Groups Projects
Commit c20e98c3 authored by Dmitry Travyan's avatar Dmitry Travyan :bus:
Browse files

fix: review comments

parent 9515c371
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -4,10 +4,13 @@ use super::*;
fn test_bucket_id_by_str() {
assert_eq!(str_to_bucket_id("100тесты", 30000), 17339);
assert_eq!(str_to_bucket_id(
"4TEST5501605647472000000100000000d9\
2beee8-749f-4539-aa15-3d2941dbb0f1x32https://google.com", 30000),
13815
assert_eq!(
str_to_bucket_id(
"4TEST5501605647472000000100000000d9\
2beee8-749f-4539-aa15-3d2941dbb0f1x32https://google.com",
30000
),
13815
);
assert_eq!(str_to_bucket_id("1123", 30000), 360);
......
use std::fmt;
use std::str::FromStr;
use decimal::d128;
use serde::de::Visitor;
......@@ -139,6 +140,29 @@ impl<'de> Deserialize<'de> for Value {
impl Eq for Value {}
impl From<Value> for IrValue {
fn from(value: Value) -> Self {
match value {
Value::Boolean(v) => IrValue::Boolean(v),
// Here is absolutely stupid solution!
// d128 supports floating point values, and f64 conversion cannot cause errors.
// But in crate d128 there is no implementation of `From<f64>`, and the development
// of the crate is dead.
// We have only one way to convert f64 to d128 is a `FromStr` trait, which is also
// not implemented idiomatically. Realization despite the signature with a potential
// error, but always returns a value. For this reason, this trait does not implement
// a Error, since we can be sure that all checks were passed when f64 was received.
Value::Number(v) => IrValue::Number(
d128::from_str(&v.to_string()).expect("Invalid decimal float literal"),
),
Value::Integer(v) => IrValue::Number(d128::from(v)),
Value::String(v) => IrValue::String(v),
Value::Unsigned(v) => IrValue::Number(d128::from(v)),
Value::Null(_) => IrValue::Null,
}
}
}
type BoxExecuteTuple = Vec<Value>;
#[derive(LuaRead, Debug, PartialEq, Eq, Clone)]
......
......@@ -51,29 +51,6 @@ pub enum Value {
String(String),
}
impl From<crate::executor::result::Value> for Value {
fn from(value: crate::executor::result::Value) -> Self {
match value {
crate::executor::result::Value::Boolean(v) => Value::Boolean(v),
// Here is absolutely stupid solution!
// d128 supports floating point values, and f64 conversion cannot cause errors.
// But in crate d128 there is no implementation of `From<f64>`, and the development
// of the crate is dead.
// We have only one way to convert f64 to d128 is a `FromStr` trait, which is also
// not implemented idiomatically. Realization despite the signature with a potential
// error, but always returns a value. For this reason, this trait does not implement
// a Error, since we can be sure that all checks were passed when f64 was received.
crate::executor::result::Value::Number(v) => Value::Number(
d128::from_str(&v.to_string()).expect("Invalid decimal float literal"),
),
crate::executor::result::Value::Integer(v) => Value::Number(d128::from(v)),
crate::executor::result::Value::String(v) => Value::String(v),
crate::executor::result::Value::Unsigned(v) => Value::Number(d128::from(v)),
crate::executor::result::Value::Null(_) => Value::Null,
}
}
}
impl Eq for Value {}
impl fmt::Display for Value {
......
use decimal::d128;
use crate::{
executor::engine::{mock::EngineMock, Engine},
executor::engine::{cartridge::hash::str_to_bucket_id, mock::EngineMock, Engine},
ir::value::Value as IrValue,
parser::extargs::BucketCalcArgsDict,
};
......@@ -26,7 +26,10 @@ fn bucket_calc_args() {
acc
});
assert_eq!(engine.determine_bucket_id(&filtered_args), 2377);
assert_eq!(
engine.determine_bucket_id(&filtered_args),
str_to_bucket_id("100.0", 10000)
);
let args = BucketCalcArgsDict {
space: "hash_testing".into(),
......@@ -55,5 +58,8 @@ fn bucket_calc_args() {
acc.push_str(s.as_str());
acc
});
assert_eq!(engine.determine_bucket_id(&filtered_args), 7704);
assert_eq!(
engine.determine_bucket_id(&filtered_args),
str_to_bucket_id("93312fff100af", 10000)
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment