Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#39316
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
mengxin9014 authored and ti-chi-bot committed Nov 24, 2022
1 parent 5ccc10b commit b847b49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,6 @@ func (b *builtinStrToDateDurationSig) vecEvalDuration(input *chunk.Chunk, result
result.MergeNulls(bufStrings, bufFormats)
d64s := result.GoDurations()
sc := b.ctx.GetSessionVars().StmtCtx
hasNoZeroDateMode := b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
Expand All @@ -1190,6 +1189,7 @@ func (b *builtinStrToDateDurationSig) vecEvalDuration(input *chunk.Chunk, result
result.SetNull(i, true)
continue
}
<<<<<<< HEAD
if hasNoZeroDateMode && (t.Year() == 0 || t.Month() == 0 || t.Day() == 0) {
if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil {
return err
Expand All @@ -1198,6 +1198,9 @@ func (b *builtinStrToDateDurationSig) vecEvalDuration(input *chunk.Chunk, result
continue
}
t.SetFsp(int8(b.tp.Decimal))
=======
t.SetFsp(b.tp.GetDecimal())
>>>>>>> 7930c2ce7b (expression: fix that str_to_date returns different result on no zero date sql mode. (#39316))
dur, err := t.ConvertToDuration()
if err != nil {
return err
Expand Down
13 changes: 13 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10599,3 +10599,16 @@ func (s *testIntegrationSuite) TestIssue33397(c *C) {
tk.MustExec("set @@tidb_enable_vectorized_expression = true;")
tk.MustQuery("select compress(a) from t").Check(testkit.Rows("", ""))
}

func TestIssue39146(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("CREATE TABLE `sun` ( `dest` varchar(10) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;")
tk.MustExec("insert into sun values('20231020');")
tk.MustExec("set @@sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';")
tk.MustExec("set @@tidb_enable_vectorized_expression = on;")
tk.MustQuery(`select str_to_date(substr(dest,1,6),'%H%i%s') from sun;`).Check(testkit.Rows("20:23:10"))
tk.MustExec("set @@tidb_enable_vectorized_expression = off;")
tk.MustQuery(`select str_to_date(substr(dest,1,6),'%H%i%s') from sun;`).Check(testkit.Rows("20:23:10"))
}

0 comments on commit b847b49

Please sign in to comment.