-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
tidb_query: fix CAST as decimal inconsistency between TiKV and TiDB #5468
Conversation
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
…iff_part_5 Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
…iff_part_5 Signed-off-by: H-ZeX <hzx20112012@gmail.com>
if let Error::Eval(_, d) = r.err().unwrap() { | ||
assert_eq!(d, ERR_M_BIGGER_THAN_D, "{}", log); | ||
} else { | ||
panic!("unreachable path, {}", log); |
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.
Should we use unreachable!()
instead?
panic!("unreachable path, {}", log); | ||
} | ||
} | ||
_ => panic!("unreachable path, {}", log), |
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
@@ -1907,6 +1908,7 @@ impl ToString for Decimal { | |||
impl Display for Decimal { | |||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { | |||
let mut dec = self.clone(); | |||
// TODO: why there is rounding here? |
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.
Please fix this TODO note, make it more declarative.
@@ -779,6 +924,25 @@ mod tests { | |||
EvalContext::new(cfg) | |||
} | |||
|
|||
fn make_ctx_4( |
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.
Could we apply a builder pattern here? Create a configuration structure to describe such flags.
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.
Different test need different flag, so if will create a config, it should had all flag as option. Then it will same as EvalContext.
This is test, and rust has no overload (if use trait, it is too troublesome). So it need to seperate these functions will _x
if truncate_as_warning { | ||
flag |= Flag::TRUNCATE_AS_WARNING; | ||
} | ||
for i in flags { |
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.
flag |= flags.fold(Flag::new(), |acc, x| acc | x)
looks better?
#[derive(Clone, Copy, Debug)] | ||
#[allow(clippy::enum_variant_names)] | ||
enum Cond { | ||
TargetIntPartLenLessThanOriginIntPartLen, |
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.
Could we shorten these names?
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.
If shorten it, then I need to add doc for it. I think add doc is not a good idea.
There is many long function name in TiKV.
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
let res = if in_union(extra.implicit_args) && val.is_negative() { | ||
Decimal::zero() | ||
} else { | ||
// FIXME: here TiDB may has bug, fix this after fix TiDB's |
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.
Same as above
@@ -434,8 +434,9 @@ fn do_sub<'a>(mut lhs: &'a Decimal, mut rhs: &'a Decimal) -> Res<Decimal> { | |||
res | |||
} | |||
|
|||
// TODO: add check for prec and frac_cnt |
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.
Prefer to remove this comment and add an assert(prec > frac_cnt)
(this TODO is meaningless because it's easy to fix it).
// because uint's upper bound is smaller than signed decimal's upper bound | ||
// so we can merge cast uint as signed/unsigned decimal in this function |
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.
I think to move the two lines comments to above L641 is appropriate.
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
f8a6c0e
to
498dcae
Compare
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
/// If `prec` > `frac_cnt`, panic. | ||
/// The panic is because of `debug_assert`. | ||
|
||
// TODO: what if prec-frac_cnt==0 |
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.
It's OK if the int_cnt
is zero.
create table td (a decimal(2,2));
insert into td values ('.99');
@@ -435,7 +435,16 @@ fn do_sub<'a>(mut lhs: &'a Decimal, mut rhs: &'a Decimal) -> Res<Decimal> { | |||
} | |||
|
|||
/// Get the max possible decimal with giving precision and fraction digit count. | |||
fn max_decimal(prec: u8, frac_cnt: u8) -> Decimal { | |||
/// The `prec` should <= `frac_cnt`. |
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 `prec` should <= `frac_cnt`. | |
/// The `prec` should >= `frac_cnt`. |
@@ -465,6 +474,12 @@ fn max_decimal(prec: u8, frac_cnt: u8) -> Decimal { | |||
|
|||
/// `max_or_min_dec`(`NewMaxOrMinDec` in tidb) returns the max or min | |||
/// value decimal for given precision and fraction. | |||
/// The `prec` should <= `frac_cnt`. |
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
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
/// | ||
/// # Panics | ||
/// | ||
/// If `prec` > `frac_cnt`, panic. |
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
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
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.
LGTM
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.
LGTM
/merge |
Your auto merge job has been accepted, waiting for 5635 |
/run-all-tests |
@H-ZeX merge failed. |
/test |
…ikv#5468) Signed-off-by: H-ZeX <hzx20112012@gmail.com>
…ikv#5468) Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX hzx20112012@gmail.com
What have you changed?
compare tidb and tikv's impl of
cast
and fix what they are inconsistent.What is the type of the changes?
How is the PR tested?
unit test
Does this PR affect documentation (docs) or should it be mentioned in the release notes?
No.
Does this PR affect
tidb-ansible
?No.