Skip to content

Commit

Permalink
expression: resize the result for IfXXSig (#37417) (#37428)
Browse files Browse the repository at this point in the history
close #37414
  • Loading branch information
ti-srebot authored Sep 19, 2022
1 parent 1a9510b commit ea628db
Show file tree
Hide file tree
Showing 3 changed files with 25 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 @@ -229,6 +229,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 @@ -344,6 +345,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
13 changes: 13 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9896,6 +9896,19 @@ func (s *testIntegrationSuite) TestRedundantColumnResolve(c *C) {
tk.MustQuery("select t1.a, t2.a from t1 natural join t2").Check(testkit.Rows("1 1"))
}

func (s *testIntegrationSuite) TestIssue37414(c *C) {
defer s.cleanEnv(c)

tk := testkit.NewTestKit(c, s.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 (s *testIntegrationSuite) TestControlFunctionWithEnumOrSet(c *C) {
defer s.cleanEnv(c)

Expand Down

0 comments on commit ea628db

Please sign in to comment.