Skip to content

Commit

Permalink
cherry-pick manually
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 committed Mar 24, 2020
1 parent f5eb88d commit 4e38f92
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
13 changes: 13 additions & 0 deletions expression/builtin_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,19 @@ func (b *builtinValuesIntSig) evalInt(_ chunk.Row) (int64, bool, error) {
if row.IsNull(b.offset) {
return 0, true, nil
}
// For BinaryLiteral, see issue #15310
val := row.GetRaw(b.offset)
if len(val) > 8 {
return 0, true, errors.New("Session current insert values is too long")
}
if len(val) < 8 {
var binary types.BinaryLiteral = val
v, err := binary.ToInt(b.ctx.GetSessionVars().StmtCtx)
if err != nil {
return 0, true, errors.Trace(err)
}
return int64(v), false, nil
}
return row.GetInt64(b.offset), false, nil
}
return 0, true, errors.Errorf("Session current insert values len %d and column's offset %v don't match", row.Len(), b.offset)
Expand Down
19 changes: 17 additions & 2 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4035,9 +4035,9 @@ from
(select * from t1) a
left join
(select bussid,date(from_unixtime(ct)) date8 from t2) b
on
on
a.period_id = b.bussid
where
where
datediff(b.date8, date(from_unixtime(a.starttime))) >= 0`
tk.MustQuery(q)
}
Expand Down Expand Up @@ -4500,3 +4500,18 @@ func (s *testIntegrationSuite) TestIssue11309And11319(c *C) {
tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_HOUR)`).Check(testkit.Rows("2007-03-31 00:08:28"))
tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 YEAR_MONTH)`).Check(testkit.Rows("2009-05-28 22:08:28"))
}

func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) {
// See issue #15310
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("create table testValuesBinary(id int primary key auto_increment, a bit(1));")
tk.MustExec("insert into testValuesBinary values(1,1);")
err := tk.ExecToErr("insert into testValuesBinary values(1,1) on duplicate key update id = values(id),a = values(a);")
c.Assert(err, IsNil)
tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("0"))
err = tk.ExecToErr("insert into testValuesBinary values(1,0) on duplicate key update id = values(id),a = values(a);")
c.Assert(err, IsNil)
tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("1"))
tk.MustExec("drop table testValuesBinary;")
}
13 changes: 13 additions & 0 deletions util/chunk/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ func (r Row) GetDatum(colIdx int, tp *types.FieldType) types.Datum {
return d
}

// GetRaw returns the underlying raw bytes with the colIdx.
func (r Row) GetRaw(colIdx int) []byte {
var data []byte
c := r.c.columns[colIdx]
if c.isFixed() {
elemLen := len(c.elemBuf)
data = c.data[r.idx*elemLen : r.idx*elemLen+elemLen]
} else {
data = c.data[c.offsets[r.idx]:c.offsets[r.idx+1]]
}
return data
}

// IsNull returns if the datum in the chunk.Row is null.
func (r Row) IsNull(colIdx int) bool {
return r.c.columns[colIdx].isNull(r.idx)
Expand Down

0 comments on commit 4e38f92

Please sign in to comment.