@@ -762,6 +762,11 @@ func (s *testEvaluatorSuite) TestTime(c *C) {
762
762
c .Assert (err , IsNil )
763
763
}
764
764
765
+ func resetStmtContext (ctx sessionctx.Context ) {
766
+ ctx .GetSessionVars ().StmtCtx .NowTs = time.Time {}
767
+ ctx .GetSessionVars ().StmtCtx .SysTs = time.Time {}
768
+ }
769
+
765
770
func (s * testEvaluatorSuite ) TestNowAndUTCTimestamp (c * C ) {
766
771
defer testleak .AfterTest (c )()
767
772
@@ -778,6 +783,7 @@ func (s *testEvaluatorSuite) TestNowAndUTCTimestamp(c *C) {
778
783
{funcs [ast .Now ], func () time.Time { return time .Now () }},
779
784
{funcs [ast .UTCTimestamp ], func () time.Time { return time .Now ().UTC () }},
780
785
} {
786
+ resetStmtContext (s .ctx )
781
787
f , err := x .fc .getFunction (s .ctx , s .datumsToConstants (nil ))
782
788
c .Assert (err , IsNil )
783
789
v , err := evalBuiltinFunc (f , chunk.Row {})
@@ -789,6 +795,7 @@ func (s *testEvaluatorSuite) TestNowAndUTCTimestamp(c *C) {
789
795
c .Assert (strings .Contains (t .String (), "." ), IsFalse )
790
796
c .Assert (ts .Sub (gotime (t , ts .Location ())), LessEqual , time .Second )
791
797
798
+ resetStmtContext (s .ctx )
792
799
f , err = x .fc .getFunction (s .ctx , s .datumsToConstants (types .MakeDatums (6 )))
793
800
c .Assert (err , IsNil )
794
801
v , err = evalBuiltinFunc (f , chunk.Row {})
@@ -798,11 +805,13 @@ func (s *testEvaluatorSuite) TestNowAndUTCTimestamp(c *C) {
798
805
c .Assert (strings .Contains (t .String (), "." ), IsTrue )
799
806
c .Assert (ts .Sub (gotime (t , ts .Location ())), LessEqual , time .Millisecond )
800
807
808
+ resetStmtContext (s .ctx )
801
809
f , err = x .fc .getFunction (s .ctx , s .datumsToConstants (types .MakeDatums (8 )))
802
810
c .Assert (err , IsNil )
803
811
_ , err = evalBuiltinFunc (f , chunk.Row {})
804
812
c .Assert (err , NotNil )
805
813
814
+ resetStmtContext (s .ctx )
806
815
f , err = x .fc .getFunction (s .ctx , s .datumsToConstants (types .MakeDatums (- 2 )))
807
816
c .Assert (err , IsNil )
808
817
_ , err = evalBuiltinFunc (f , chunk.Row {})
@@ -813,6 +822,7 @@ func (s *testEvaluatorSuite) TestNowAndUTCTimestamp(c *C) {
813
822
variable .SetSessionSystemVar (s .ctx .GetSessionVars (), "time_zone" , types .NewDatum ("+00:00" ))
814
823
variable .SetSessionSystemVar (s .ctx .GetSessionVars (), "timestamp" , types .NewDatum (1234 ))
815
824
fc := funcs [ast .Now ]
825
+ resetStmtContext (s .ctx )
816
826
f , err := fc .getFunction (s .ctx , s .datumsToConstants (nil ))
817
827
c .Assert (err , IsNil )
818
828
v , err := evalBuiltinFunc (f , chunk.Row {})
@@ -877,6 +887,7 @@ func (s *testEvaluatorSuite) TestAddTimeSig(c *C) {
877
887
878
888
// This is a test for issue 7334
879
889
du := newDateArighmeticalUtil ()
890
+ resetStmtContext (s .ctx )
880
891
now , _ , err := evalNowWithFsp (s .ctx , 0 )
881
892
c .Assert (err , IsNil )
882
893
res , _ , err := du .add (s .ctx , now , "1" , "MICROSECOND" )
@@ -1203,6 +1214,7 @@ func (s *testEvaluatorSuite) TestUTCTime(c *C) {
1203
1214
}{{0 , 8 }, {3 , 12 }, {6 , 15 }, {- 1 , 0 }, {7 , 0 }}
1204
1215
1205
1216
for _ , test := range tests {
1217
+ resetStmtContext (s .ctx )
1206
1218
f , err := fc .getFunction (s .ctx , s .datumsToConstants (types .MakeDatums (test .param )))
1207
1219
c .Assert (err , IsNil )
1208
1220
v , err := evalBuiltinFunc (f , chunk.Row {})
@@ -1229,6 +1241,7 @@ func (s *testEvaluatorSuite) TestUTCDate(c *C) {
1229
1241
defer testleak .AfterTest (c )()
1230
1242
last := time .Now ().UTC ()
1231
1243
fc := funcs [ast .UTCDate ]
1244
+ resetStmtContext (mock .NewContext ())
1232
1245
f , err := fc .getFunction (mock .NewContext (), s .datumsToConstants (nil ))
1233
1246
c .Assert (err , IsNil )
1234
1247
v , err := evalBuiltinFunc (f , chunk.Row {})
@@ -1500,6 +1513,7 @@ func (s *testEvaluatorSuite) TestTimestampDiff(c *C) {
1500
1513
types .NewStringDatum (test .t1 ),
1501
1514
types .NewStringDatum (test .t2 ),
1502
1515
}
1516
+ resetStmtContext (s .ctx )
1503
1517
f , err := fc .getFunction (s .ctx , s .datumsToConstants (args ))
1504
1518
c .Assert (err , IsNil )
1505
1519
d , err := evalBuiltinFunc (f , chunk.Row {})
@@ -1509,6 +1523,7 @@ func (s *testEvaluatorSuite) TestTimestampDiff(c *C) {
1509
1523
sc := s .ctx .GetSessionVars ().StmtCtx
1510
1524
sc .IgnoreTruncate = true
1511
1525
sc .IgnoreZeroInDate = true
1526
+ resetStmtContext (s .ctx )
1512
1527
f , err := fc .getFunction (s .ctx , s .datumsToConstants ([]types.Datum {types .NewStringDatum ("DAY" ),
1513
1528
types .NewStringDatum ("2017-01-00" ),
1514
1529
types .NewStringDatum ("2017-01-01" )}))
@@ -1517,6 +1532,7 @@ func (s *testEvaluatorSuite) TestTimestampDiff(c *C) {
1517
1532
c .Assert (err , IsNil )
1518
1533
c .Assert (d .Kind (), Equals , types .KindNull )
1519
1534
1535
+ resetStmtContext (s .ctx )
1520
1536
f , err = fc .getFunction (s .ctx , s .datumsToConstants ([]types.Datum {types .NewStringDatum ("DAY" ),
1521
1537
{}, types .NewStringDatum ("2017-01-01" )}))
1522
1538
c .Assert (err , IsNil )
@@ -1528,6 +1544,7 @@ func (s *testEvaluatorSuite) TestTimestampDiff(c *C) {
1528
1544
func (s * testEvaluatorSuite ) TestUnixTimestamp (c * C ) {
1529
1545
// Test UNIX_TIMESTAMP().
1530
1546
fc := funcs [ast .UnixTimestamp ]
1547
+ resetStmtContext (s .ctx )
1531
1548
f , err := fc .getFunction (s .ctx , nil )
1532
1549
c .Assert (err , IsNil )
1533
1550
d , err := evalBuiltinFunc (f , chunk.Row {})
@@ -1537,12 +1554,14 @@ func (s *testEvaluatorSuite) TestUnixTimestamp(c *C) {
1537
1554
1538
1555
// https://github.com/pingcap/tidb/issues/2496
1539
1556
// Test UNIX_TIMESTAMP(NOW()).
1557
+ resetStmtContext (s .ctx )
1540
1558
now , isNull , err := evalNowWithFsp (s .ctx , 0 )
1541
1559
c .Assert (err , IsNil )
1542
1560
c .Assert (isNull , IsFalse )
1543
1561
n := types.Datum {}
1544
1562
n .SetMysqlTime (now )
1545
1563
args := []types.Datum {n }
1564
+ resetStmtContext (s .ctx )
1546
1565
f , err = fc .getFunction (s .ctx , s .datumsToConstants (args ))
1547
1566
c .Assert (err , IsNil )
1548
1567
d , err = evalBuiltinFunc (f , chunk.Row {})
@@ -1554,6 +1573,7 @@ func (s *testEvaluatorSuite) TestUnixTimestamp(c *C) {
1554
1573
// https://github.com/pingcap/tidb/issues/2852
1555
1574
// Test UNIX_TIMESTAMP(NULL).
1556
1575
args = []types.Datum {types .NewDatum (nil )}
1576
+ resetStmtContext (s .ctx )
1557
1577
f , err = fc .getFunction (s .ctx , s .datumsToConstants (args ))
1558
1578
c .Assert (err , IsNil )
1559
1579
d , err = evalBuiltinFunc (f , chunk.Row {})
@@ -1598,6 +1618,7 @@ func (s *testEvaluatorSuite) TestUnixTimestamp(c *C) {
1598
1618
fmt .Printf ("Begin Test %v\n " , test )
1599
1619
expr := s .datumsToConstants ([]types.Datum {test .input })
1600
1620
expr [0 ].GetType ().Decimal = test .inputDecimal
1621
+ resetStmtContext (s .ctx )
1601
1622
f , err := fc .getFunction (s .ctx , expr )
1602
1623
c .Assert (err , IsNil , Commentf ("%+v" , test ))
1603
1624
d , err := evalBuiltinFunc (f , chunk.Row {})
@@ -1681,6 +1702,7 @@ func (s *testEvaluatorSuite) TestTimestamp(c *C) {
1681
1702
}
1682
1703
fc := funcs [ast .Timestamp ]
1683
1704
for _ , test := range tests {
1705
+ resetStmtContext (s .ctx )
1684
1706
f , err := fc .getFunction (s .ctx , s .datumsToConstants (test .t ))
1685
1707
c .Assert (err , IsNil )
1686
1708
d , err := evalBuiltinFunc (f , chunk.Row {})
@@ -1690,6 +1712,7 @@ func (s *testEvaluatorSuite) TestTimestamp(c *C) {
1690
1712
}
1691
1713
1692
1714
nilDatum := types .NewDatum (nil )
1715
+ resetStmtContext (s .ctx )
1693
1716
f , err := fc .getFunction (s .ctx , s .datumsToConstants ([]types.Datum {nilDatum }))
1694
1717
c .Assert (err , IsNil )
1695
1718
d , err := evalBuiltinFunc (f , chunk.Row {})
@@ -2357,6 +2380,7 @@ func (s *testEvaluatorSuite) TestWithTimeZone(c *C) {
2357
2380
2358
2381
for _ , t := range tests {
2359
2382
now := time .Now ().In (sv .TimeZone )
2383
+ resetStmtContext (s .ctx )
2360
2384
f , err := funcs [t .method ].getFunction (s .ctx , s .datumsToConstants (t .Input ))
2361
2385
c .Assert (err , IsNil )
2362
2386
d , err := evalBuiltinFunc (f , chunk.Row {})
0 commit comments