Skip to content

Commit

Permalink
fix bug of union type converting (pingcap#2471)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfei1991 authored and zimulala committed Jan 16, 2017
1 parent 5bb751e commit ba8b6a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 9 additions & 11 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,18 +1045,16 @@ func (e *UnionExec) fetchData(idx int) {
}
return
}
if idx != 0 {
// TODO: Add cast function in plan building phase.
for j := range row.Data {
col := e.schema.Columns[j]
val, err := row.Data[j].ConvertTo(e.ctx.GetSessionVars().StmtCtx, col.RetType)
if err != nil {
e.finished.Store(true)
e.errCh <- err
return
}
row.Data[j] = val
// TODO: Add cast function in plan building phase.
for j := range row.Data {
col := e.schema.Columns[j]
val, err := row.Data[j].ConvertTo(e.ctx.GetSessionVars().StmtCtx, col.RetType)
if err != nil {
e.finished.Store(true)
e.errCh <- err
return
}
row.Data[j] = val
}
rows = append(rows, row)
}
Expand Down
6 changes: 6 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ func (s *testSuite) TestUnion(c *C) {
tk.MustExec("insert into t (c1, c2) values (2, 3)")
r = tk.MustQuery("select * from t where t.c1 = 1 union select * from t where t.id = 1")
r.Check(testkit.Rows("1 1 1", "2 1 2"))

tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE t (f1 DATE)")
tk.MustExec("INSERT INTO t VALUES ('1978-11-26')")
r = tk.MustQuery("SELECT f1+0 FROM t UNION SELECT f1+0 FROM t")
r.Check(testkit.Rows("19781126"))
}

func (s *testSuite) TestIn(c *C) {
Expand Down

0 comments on commit ba8b6a9

Please sign in to comment.