tidb_query: bug fix for vectorized casting real as time
@@ -1020,6 +1020,13 @@ fn cast_real_as_time(
val: Option<&Real>,
) -> Result<Option<Time>> {
if let Some(val) = val {
+ if val.is_zero() {
+ Time::zero(
+ ctx,
+ extra.ret_field_type.get_decimal() as i8,
+ extra.ret_field_type.as_accessor().tp().try_into()?,
+ )
+ } else {
// Convert `val` to a string first and then parse it as a float string.
Time::parse(
ctx,
@@ -1029,6 +1036,7 @@ fn cast_real_as_time(
// Enable round
true,
)
+ }
.map(Some)
.or_else(|e| Ok(ctx.handle_invalid_time_error(e).map(|_| None)?))
} else {
@@ -2088,6 +2096,7 @@ mod tests {
("2019-09-16 10:11:12", 20190916101112.111, 0),
("2019-09-16 10:11:12", 20190916101112.123, 0),
("2019-09-16 10:11:13", 20190916101112.999, 0),
+ ("0000-00-00 00:00:00", 0.0, 0),
];
for (expected, input, fsp) in cases {
