From cf99b7ddc1bf7dc1391b7c2dd8c90f5716c7aff8 Mon Sep 17 00:00:00 2001 From: Zhi Qi <30543181+LittleFall@users.noreply.github.com> Date: Tue, 28 Dec 2021 11:03:49 +0800 Subject: [PATCH] This is an automated cherry-pick of #3681 Signed-off-by: ti-chi-bot --- dbms/src/Functions/FunctionsTiDBConversion.h | 2 ++ tests/fullstack-test/expr/cast_string_as_real.test | 12 +++++++++--- tests/fullstack-test/expr/issue_3447.test | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/fullstack-test/expr/issue_3447.test diff --git a/dbms/src/Functions/FunctionsTiDBConversion.h b/dbms/src/Functions/FunctionsTiDBConversion.h index 6c6d60a55a7..bea08254e4a 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 new file mode 100644 index 00000000000..e0321e8c60e --- /dev/null +++ b/tests/fullstack-test/expr/issue_3447.test @@ -0,0 +1,14 @@ +mysql> drop table if exists test.t; +mysql> create table test.t(a char(5)); +mysql> alter table test.t set tiflash replica 1; +mysql> insert into test.t values ('0.1'), ('-0.1'), ('0.0'), ('-1'), ('a0.1'), ('0x01'); + +func> wait_table test t +mysql> select /*+ read_from_storage(tiflash[t]) */ * from test.t where a; ++------+ +| a | ++------+ +| 0.1 | +| -0.1 | +| -1 | ++------+