From eb77d5fff7589e86940c07a76d61581901e0068d Mon Sep 17 00:00:00 2001 From: Zhi Qi Date: Wed, 17 Nov 2021 14:35:10 +0800 Subject: [PATCH 1/3] fix --- dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp b/dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp index a4f46ef813b..397ebe9e3c3 100644 --- a/dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp +++ b/dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp @@ -609,7 +609,7 @@ String DAGExpressionAnalyzer::convertToUInt8(ExpressionActionsPtr & actions, con // the basic rule is: // 1. if the column is only null, just return it is fine // 2. if the column is numeric, compare it with 0 - // 3. if the column is string, convert it to numeric column, and compare with 0 + // 3. if the column is string, convert it to float-point column, and compare with 0 // 4. if the column is date/datetime, compare it with zeroDate // 5. if the column is other type, throw exception if (actions->getSampleBlock().getByName(column_name).type->onlyNull()) @@ -629,9 +629,10 @@ String DAGExpressionAnalyzer::convertToUInt8(ExpressionActionsPtr & actions, con /// use tidb_cast to make it compatible with TiDB tipb::FieldType field_type; // TODO: Use TypeDouble as return type, to be compatible with TiDB - field_type.set_tp(TiDB::TypeLongLong); + field_type.set_tp(TiDB::TypeDouble); + field_type.set_flen(-1); tipb::Expr type_expr; - constructStringLiteralTiExpr(type_expr, "Nullable(Int64)"); + constructStringLiteralTiExpr(type_expr, "Nullable(Double)"); auto type_expr_name = getActions(type_expr, actions); String num_col_name = buildCastFunctionInternal(this, {column_name, type_expr_name}, false, field_type, actions); From fcd8bd4512bf10b78893fd1fe6d54037d05fabef Mon Sep 17 00:00:00 2001 From: Zhi Qi Date: Wed, 17 Nov 2021 15:18:22 +0800 Subject: [PATCH 2/3] add test --- tests/fullstack-test/expr/issue_3447.test | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/fullstack-test/expr/issue_3447.test diff --git a/tests/fullstack-test/expr/issue_3447.test b/tests/fullstack-test/expr/issue_3447.test new file mode 100644 index 00000000000..d5eb4dd0b5b --- /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 | ++------+ \ No newline at end of file From dff2f8278e90a12264de7620bc96d67b40a16139 Mon Sep 17 00:00:00 2001 From: Zhi Qi Date: Wed, 17 Nov 2021 15:41:52 +0800 Subject: [PATCH 3/3] add --- tests/fullstack-test/expr/issue_3447.test | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/fullstack-test/expr/issue_3447.test b/tests/fullstack-test/expr/issue_3447.test index d5eb4dd0b5b..53d4bbfb544 100644 --- a/tests/fullstack-test/expr/issue_3447.test +++ b/tests/fullstack-test/expr/issue_3447.test @@ -8,7 +8,8 @@ mysql> select /*+ read_from_storage(tiflash[t]) */ * from test.t where a; +------+ | a | +------+ -| 0.1 | -| -0.1 | +| 0.1 | +| -0.1 | | -1 | -+------+ \ No newline at end of file +| 0x01 | ++------+