Skip to content

Commit

Permalink
expression: Fix the bug that castStringAsReal has different behaivor …
Browse files Browse the repository at this point in the history
…between tiflash and tikv/tidb. (#3681) (#3757)

ref #3447, close #3475
  • Loading branch information
ti-chi-bot authored Jun 17, 2022
1 parent 3b3e86c commit c1a9569
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions dbms/src/Functions/FunctionsTiDBConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,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<Float64>::infinity())
{
Expand Down
12 changes: 9 additions & 3 deletions tests/fullstack-test/expr/cast_string_as_real.test
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion tests/fullstack-test/expr/issue_3447.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ mysql> select /*+ read_from_storage(tiflash[t]) */ * from test.t where a;
| 0.1 |
| -0.1 |
| -1 |
| 0x01 |
+------+

0 comments on commit c1a9569

Please sign in to comment.