-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
coprocessor: add a Convert trait and implement convert to decimal #5167
Conversation
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest LGTM
for (lhs, rhs, expected) in test_cases { | ||
let output = RpnFnScalarEvaluator::new() | ||
.push_param(lhs.map(|f| Decimal::from_f64(f).unwrap())) | ||
.push_param(rhs.map(|f| Decimal::from_f64(f).unwrap())) | ||
.push_param(lhs.map(|f| f64_to_decimal(&mut ctx, f).unwrap())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can rewrite these tests using string instead.. It would be better for a unit test to test less things other than itself.
let test_cases = vec![ | ||
(Decimal::from(std::i64::MIN), Decimal::from(-1)), | ||
( | ||
Decimal::from(std::i64::MAX), | ||
Decimal::from_f64(0.1).unwrap(), | ||
f64_to_decimal(&mut ctx, 0.1).unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
) -> Result<Option<Decimal>> { | ||
match val { | ||
None => Ok(None), | ||
Some(val) => { | ||
let dec = Decimal::from(*val); | ||
let dec: Decimal = val.convert(ctx)?; | ||
Ok(Some(produce_dec_with_specified_tp( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like produce_dec_with_specified_tp
should be placed inside the convert function, instead of cast_xxx_as_xxx
. Otherwise we are still leaking cast logic in the non-cast layer, right?
@@ -523,8 +530,8 @@ mod tests { | |||
TestCaseCmpOp::NullEQ => ScalarFuncSig::NullEQDecimal, | |||
}; | |||
let output = RpnFnScalarEvaluator::new() | |||
.push_param(arg0.map(|v| Decimal::from_f64(v.into_inner()).unwrap())) | |||
.push_param(arg1.map(|v| Decimal::from_f64(v.into_inner()).unwrap())) | |||
.push_param(arg0.map(|v| f64_to_decimal(&mut ctx, v.into_inner()).unwrap())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto. maybe from string is better for keeping unit tests pure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, we should refactor all test cases in this file if we use a string here (I think it's ok to keep float).
return Err(invalid_type!("{} can't be convert to decimal'", self)); | ||
} | ||
|
||
let s = format!("{}", self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this format (of f64) extract same as golang's format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes (if we do not use special format string, e.g: %E/%e)
impl ConvertTo<Decimal> for &[u8] { | ||
#[inline] | ||
fn convert(&self, ctx: &mut EvalContext) -> Result<Decimal> { | ||
let dec = match Decimal::from_bytes(self)? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this impl same as TiDB's, if we need to check carefully, I think add a TODO
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they have the same implementation.
The reset is fine |
Signed-off-by: Lonng <heng@lonng.org>
Signed-off-by: Lonng <heng@lonng.org>
/run-all-tests |
…kv#5167) Signed-off-by: Lonng <heng@lonng.org>
Signed-off-by: Lonng heng@lonng.org
What have you changed? (mandatory)
Implements
ConvertTo<Decimal>
for all evaluable types.What are the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
Existing unit tests.