@@ -18,6 +18,7 @@ import (
1818 "math"
1919 "math/rand"
2020 "testing"
21+ "time"
2122
2223 "github.com/pingcap/tidb/pkg/parser/ast"
2324 "github.com/pingcap/tidb/pkg/parser/mysql"
@@ -569,6 +570,33 @@ func TestVectorizedBuiltinTimeFunc(t *testing.T) {
569570 testVectorizedBuiltinFunc (t , vecBuiltinTimeCases )
570571}
571572
573+ func TestVectorizedTimeFormatEmptyFormatReturnsNull (t * testing.T ) {
574+ ctx := createContext (t )
575+
576+ durationType := types .NewFieldType (mysql .TypeDuration )
577+ durationType .SetDecimal (types .DefaultFsp )
578+ formatType := types .NewFieldType (mysql .TypeString )
579+
580+ col0 := & Column {RetType : durationType , Index : 0 }
581+ col1 := & Column {RetType : formatType , Index : 1 }
582+ f , err := funcs [ast .TimeFormat ].getFunction (ctx , []Expression {col0 , col1 })
583+ require .NoError (t , err )
584+ require .True (t , f .vectorized () && f .isChildrenVectorized ())
585+
586+ input := chunk .NewChunkWithCapacity ([]* types.FieldType {durationType , formatType }, 2 )
587+ input .AppendDuration (0 , types.Duration {Duration : 12 * time .Hour + 34 * time .Minute + 56 * time .Second , Fsp : types .DefaultFsp })
588+ input .AppendString (1 , "" )
589+ input .AppendDuration (0 , types.Duration {Duration : time .Hour + 2 * time .Minute + 3 * time .Second , Fsp : types .DefaultFsp })
590+ input .AppendString (1 , "%H:%i:%s" )
591+
592+ result := chunk .NewColumn (formatType , 2 )
593+ require .NoError (t , vecEvalType (ctx , f , types .ETString , input , result ))
594+ require .Equal (t , 2 , result .Rows ())
595+ require .True (t , result .IsNull (0 ))
596+ require .False (t , result .IsNull (1 ))
597+ require .Equal (t , "01:02:03" , result .GetString (1 ))
598+ }
599+
572600func BenchmarkVectorizedBuiltinTimeEvalOneVec (b * testing.B ) {
573601 benchmarkVectorizedEvalOneVec (b , vecBuiltinTimeCases )
574602}
0 commit comments