From c31e07c58b4f19163ea57782a8e787b60d7161c8 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Mon, 1 Jul 2024 22:10:27 +0800 Subject: [PATCH] expression: fail `ColumnSubstituteImpl` if creating function returns error (#53716) (#54191) close pingcap/tidb#53580, close pingcap/tidb#53582, close pingcap/tidb#53594, close pingcap/tidb#53603 --- pkg/expression/util.go | 6 +++++- tests/integrationtest/r/planner/core/integration.result | 7 +++++++ tests/integrationtest/t/planner/core/integration.test | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pkg/expression/util.go b/pkg/expression/util.go index 5d0ee104e7c77..6c1956b93643d 100644 --- a/pkg/expression/util.go +++ b/pkg/expression/util.go @@ -519,7 +519,11 @@ func ColumnSubstituteImpl(expr Expression, schema *Schema, newExprs []Expression } } if substituted { - return true, hasFail, NewFunctionInternal(v.GetCtx(), v.FuncName.L, v.RetType, refExprArr.Result()...) + newFunc, err := NewFunction(v.GetCtx(), v.FuncName.L, v.RetType, refExprArr.Result()...) + if err != nil { + return true, true, v + } + return true, hasFail, newFunc } } return false, false, expr diff --git a/tests/integrationtest/r/planner/core/integration.result b/tests/integrationtest/r/planner/core/integration.result index e6de4d1a482f7..a65e4eb85b198 100644 --- a/tests/integrationtest/r/planner/core/integration.result +++ b/tests/integrationtest/r/planner/core/integration.result @@ -3952,3 +3952,10 @@ p o v a 3 5 5 3 3 9 9 9 set @@tidb_enable_pipelined_window_function=DEFAULT; +drop table if exists t; +create table t (col TEXT); +select 1 from (select t.col as c0, 46578369 as c1 from t) as t where +case when ( +t.c0 in (t.c0, cast((cast(1 as unsigned) - cast(t.c1 as signed)) as char)) +) then 1 else 2 end; +1 diff --git a/tests/integrationtest/t/planner/core/integration.test b/tests/integrationtest/t/planner/core/integration.test index 488f881339a4a..ad7ec0cd4a34b 100644 --- a/tests/integrationtest/t/planner/core/integration.test +++ b/tests/integrationtest/t/planner/core/integration.test @@ -2071,4 +2071,10 @@ set @@tidb_enable_pipelined_window_function=0; select *, first_value(v) over (partition by p order by o range between 3.1 preceding and 2.9 following) as a from planner__core__integration.first_range; set @@tidb_enable_pipelined_window_function=DEFAULT; - +# TestIssue53580 +drop table if exists t; +create table t (col TEXT); +select 1 from (select t.col as c0, 46578369 as c1 from t) as t where + case when ( + t.c0 in (t.c0, cast((cast(1 as unsigned) - cast(t.c1 as signed)) as char)) + ) then 1 else 2 end;