Skip to content

Commit

Permalink
Fix the bug that results of where <string> is wrong because it will…
Browse files Browse the repository at this point in the history
… be converted to int type. (#3463) (#3480)

close #3447
  • Loading branch information
ti-chi-bot authored Jun 17, 2022
1 parent 8f8929d commit 3b3e86c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,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())
Expand All @@ -878,9 +878,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);

Expand Down
15 changes: 15 additions & 0 deletions tests/fullstack-test/expr/issue_3447.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 |
| 0x01 |
+------+

0 comments on commit 3b3e86c

Please sign in to comment.