Skip to content

Commit

Permalink
expression: resize the result for IfXXSig (pingcap#37417) (pingcap#37431
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Sep 19, 2022
1 parent fb6714c commit dee851d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions expression/builtin_control_vec_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions expression/generator/control_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ var builtinIfNullVec = template.Must(template.New("builtinIfNullVec").Parse(`
func (b *builtinIfNull{{ .TypeName }}Sig) fallbackEval{{ .TypeName }}(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
{{- if .Fixed }}
result.Resize{{ .TypeNameInColumn }}(n, false)
x := result.{{ .TypeNameInColumn }}s()
for i := 0; i < n; i++ {
res, isNull, err := b.eval{{ .TypeName }}(input.GetRow(i))
Expand Down Expand Up @@ -345,6 +346,7 @@ var builtinIfVec = template.Must(template.New("builtinIfVec").Parse(`
func (b *builtinIf{{ .TypeName }}Sig) fallbackEval{{ .TypeName }}(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
{{- if .Fixed }}
result.Resize{{ .TypeNameInColumn }}(n, false)
x := result.{{ .TypeNameInColumn }}s()
for i := 0; i < n; i++ {
res, isNull, err := b.eval{{ .TypeName }}(input.GetRow(i))
Expand Down
14 changes: 14 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6281,6 +6281,20 @@ func TestRedundantColumnResolve(t *testing.T) {
tk.MustQuery("select t1.a, t2.a from t1 natural join t2").Check(testkit.Rows("1 1"))
}

func TestIssue37414(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists foo")
tk.MustExec("drop table if exists bar")
tk.MustExec("create table foo(a decimal(65,0));")
tk.MustExec("create table bar(a decimal(65,0), b decimal(65,0));")
tk.MustExec("insert into bar values(0,0),(1,1),(2,2);")
tk.MustExec("insert into foo select if(b>0, if(a/b>1, 1, 2), null) from bar;")
}

func TestControlFunctionWithEnumOrSet(t *testing.T) {
// issue 23114
store, clean := testkit.CreateMockStore(t)
Expand Down

0 comments on commit dee851d

Please sign in to comment.