diff --git a/dbms/src/Functions/FunctionsTiDBConversion.h b/dbms/src/Functions/FunctionsTiDBConversion.h index 954cc2e8d49..4d26e534164 100644 --- a/dbms/src/Functions/FunctionsTiDBConversion.h +++ b/dbms/src/Functions/FunctionsTiDBConversion.h @@ -664,6 +664,8 @@ struct TiDBConvertToFloat context.getDAGContext()->handleTruncateError("Truncated incorrect DOUBLE value"); return 0.0; } + if (float_string.size < trim_string.size()) + trim_string[float_string.size] = '\0'; Float64 f = strtod(float_string.data, nullptr); if (f == std::numeric_limits::infinity()) { diff --git a/tests/fullstack-test/expr/cast_string_as_real.test b/tests/fullstack-test/expr/cast_string_as_real.test index ab8f2852589..c81cfa2a604 100644 --- a/tests/fullstack-test/expr/cast_string_as_real.test +++ b/tests/fullstack-test/expr/cast_string_as_real.test @@ -1,29 +1,35 @@ mysql> drop table if exists test.t mysql> create table test.t(a char(30)) mysql> alter table test.t set tiflash replica 1 -mysql> insert into test.t values ('1.23'),('123'),('-123.99'),('+123.123-'),(0),(0.0),(NULL),('1.11.00'),('11xx'),('11.xx'),('xx.11'),('1e649'),('-1e649'),('9.9999999999999999'),('9.999999999999999') +mysql> insert into test.t values ('1.23'),('123'),('-123.99'),('+123.123-'),(0),(0.0),(NULL),('1.11.00'),('11xx'),('11.xx'),('xx.11'),('1e649'),('-1e649'),('9.9999999999999999'),('9.999999999999999'); +mysql> insert into test.t values ('0x01'),('-0x01'),('1x01'),('-1x01.2'),('0x01.2'),('x1'); func> wait_table test t -mysql> set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, b from (select a, cast(a as double) as b from test.t) t group by a, b order by a +mysql> set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, cast(a as double) b from test.t order by a; +--------------------+-------------------------+ | a | b | +--------------------+-------------------------+ | NULL | NULL | | +123.123- | 123.123 | +| -0x01 | -0 | | -123.99 | -123.99 | | -1e649 | -1.7976931348623157e308 | +| -1x01.2 | -1 | | 0 | 0 | | 0.0 | 0 | +| 0x01 | 0 | +| 0x01.2 | 0 | | 1.11.00 | 1.11 | | 1.23 | 1.23 | | 11.xx | 11 | | 11xx | 11 | | 123 | 123 | | 1e649 | 1.7976931348623157e308 | +| 1x01 | 1 | | 9.999999999999999 | 9.999999999999998 | | 9.9999999999999999 | 10 | +| x1 | 0 | | xx.11 | 0 | +--------------------+-------------------------+ -mysql> drop table if exists test.t diff --git a/tests/fullstack-test/expr/issue_3447.test b/tests/fullstack-test/expr/issue_3447.test index 53d4bbfb544..e0321e8c60e 100644 --- a/tests/fullstack-test/expr/issue_3447.test +++ b/tests/fullstack-test/expr/issue_3447.test @@ -11,5 +11,4 @@ mysql> select /*+ read_from_storage(tiflash[t]) */ * from test.t where a; | 0.1 | | -0.1 | | -1 | -| 0x01 | +------+