Skip to content

Commit 8a2ead9

Browse files
committed
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
2 parents 9f11af5 + 45c4c4c commit 8a2ead9

File tree

10 files changed

+72
-12
lines changed

10 files changed

+72
-12
lines changed

enginetest/queries/queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ var QueryTests = []QueryTest{
799799
{
800800
// Assert that SYSDATE() returns different times on each call in a query (unlike NOW())
801801
// Using the maximum precision for fractional seconds, lets us see a difference.
802-
Query: "select now() = sysdate(), sleep(0.1), now(6) < sysdate(6);",
802+
Query: "select now() = sysdate(), sleep(0.5), now(6) < sysdate(6);",
803803
Expected: []sql.Row{{true, 0, true}},
804804
},
805805
{

enginetest/queries/script_queries.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5128,6 +5128,34 @@ CREATE TABLE tab3 (
51285128
},
51295129
},
51305130
},
5131+
{
5132+
Dialect: "mysql",
5133+
Name: "UNIX_TIMESTAMP function preserves trailing 0s",
5134+
SetUpScript: []string{
5135+
"SET time_zone = '+07:00';",
5136+
},
5137+
Assertions: []ScriptTestAssertion{
5138+
{
5139+
Query: "select unix_timestamp('2001-02-03 12:34:56.10');",
5140+
Expected: []sql.Row{
5141+
{"981178496.10"},
5142+
},
5143+
},
5144+
{
5145+
Query: "select unix_timestamp('2001-02-03 12:34:56.000000');",
5146+
Expected: []sql.Row{
5147+
{"981178496.000000"},
5148+
},
5149+
},
5150+
{
5151+
Query: "select unix_timestamp('2001-02-03 12:34:56.1234567');",
5152+
Expected: []sql.Row{
5153+
{"981178496.123457"},
5154+
},
5155+
},
5156+
},
5157+
},
5158+
51315159
{
51325160
Name: "Querying existing view that references non-existing table",
51335161
SetUpScript: []string{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250319212010-451ea8d003fa
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250320231804-0e77d549294c
9+
github.com/dolthub/vitess v0.0.0-20250325024605-8131be3ca6d3
1010
github.com/go-kit/kit v0.10.0
1111
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1212
github.com/gocraft/dbr/v2 v2.7.2

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ github.com/dolthub/vitess v0.0.0-20250304211657-920ca9ec2b9a h1:HIH9g4z+yXr4DIFy
6868
github.com/dolthub/vitess v0.0.0-20250304211657-920ca9ec2b9a/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
6969
github.com/dolthub/vitess v0.0.0-20250320231804-0e77d549294c h1:Dv2DfEGb8WRBi8I5KF5Sy39TuZi/FI692mpobKWcv4g=
7070
github.com/dolthub/vitess v0.0.0-20250320231804-0e77d549294c/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
71+
github.com/dolthub/vitess v0.0.0-20250324212634-ee57ba96134a h1:cWE14qNrcxzsVfGOJ8HKPg9Q1MLWKA8ON7SYRqJmWCs=
72+
github.com/dolthub/vitess v0.0.0-20250324212634-ee57ba96134a/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
73+
github.com/dolthub/vitess v0.0.0-20250325024605-8131be3ca6d3 h1:euU+adNAYw46Zcp1HnoaSDWhqjfaL8s/1SPU+i16gYM=
74+
github.com/dolthub/vitess v0.0.0-20250325024605-8131be3ca6d3/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
7175
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
7276
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
7377
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=

server/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ func newServerFromHandler(cfg Config, e *sqle.Engine, sm *SessionManager, handle
158158
ConnReadTimeout: cfg.ConnReadTimeout,
159159
ConnWriteTimeout: cfg.ConnWriteTimeout,
160160
MaxConns: cfg.MaxConnections,
161+
MaxWaitConns: cfg.MaxWaitConnections,
162+
MaxWaitConnsTimeout: cfg.MaxWaitConnectionsTimeout,
161163
ConnReadBufferSize: mysql.DefaultConnBufferSize,
162164
AllowClearTextWithoutTLS: cfg.AllowClearTextWithoutTLS,
163165
}

server/server_config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ type Config struct {
5757
ConnWriteTimeout time.Duration
5858
// MaxConnections is the maximum number of simultaneous connections that the server will allow.
5959
MaxConnections uint64
60+
// MaxWaitConnections is the maximum number of simultaneous connections that the server will allow to block waiting
61+
// for a connection before new connections result in immediate rejection.
62+
MaxWaitConnections uint32
63+
// MaxWaitConnectionsTimeout is the maximum amount of time that a connection will block waiting for a connection
64+
MaxWaitConnectionsTimeout time.Duration
6065
// TLSConfig is the configuration for TLS on this server. If |nil|, TLS is not supported.
6166
TLSConfig *tls.Config
6267
// RequestSecureTransport will require incoming connections to be TLS. Requires non-|nil| TLSConfig.

sql/expression/function/date.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,26 @@ func NewUnixTimestamp(args ...sql.Expression) (sql.Expression, error) {
476476
if err != nil || date == nil {
477477
return &UnixTimestamp{Date: arg}, nil
478478
}
479+
// special case: text types with fractional seconds preserve scale
480+
// e.g. '2000-01-02 12:34:56.000' -> scale 3
481+
if types.IsText(arg.Type()) {
482+
dateStr := date.(string)
483+
idx := strings.Index(dateStr, ".")
484+
if idx != -1 {
485+
dateStr = strings.TrimSpace(dateStr[idx:])
486+
scale := uint8(len(dateStr) - 1)
487+
if scale > 0 {
488+
if scale > 6 {
489+
scale = 6
490+
}
491+
typ, tErr := types.CreateDecimalType(19, scale)
492+
if tErr != nil {
493+
return nil, tErr
494+
}
495+
return &UnixTimestamp{Date: arg, typ: typ}, nil
496+
}
497+
}
498+
}
479499
date, _, err = types.DatetimeMaxPrecision.Convert(date)
480500
if err != nil {
481501
return &UnixTimestamp{Date: arg}, nil

sql/expression/function/time_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package function
1616

1717
import (
1818
"fmt"
19+
"math"
1920
"testing"
2021
"time"
2122

@@ -377,7 +378,7 @@ func TestTime_Microsecond(t *testing.T) {
377378
{"null date", sql.NewRow(nil), nil, false},
378379
{"invalid type", sql.NewRow([]byte{0, 1, 2}), nil, true},
379380
{"date as string", sql.NewRow(stringDate), uint64(0), false},
380-
{"date as time", sql.NewRow(currTime), uint64(currTime.Nanosecond()) / uint64(time.Microsecond), false},
381+
{"date as time", sql.NewRow(currTime), uint64(math.Round(float64(currTime.Nanosecond()) / float64(time.Microsecond))), false},
381382
}
382383

383384
for _, tt := range testCases {

sql/types/datetime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ func ConvertToTime(ctx context.Context, v interface{}, t datetimeType) (time.Tim
203203
return zeroTime, nil
204204
}
205205

206-
// Truncate the date to the precision of this type
206+
// Round the date to the precision of this type
207207
truncationDuration := time.Second
208208
truncationDuration /= time.Duration(precisionConversion[t.precision])
209-
res = res.Truncate(truncationDuration)
209+
res = res.Round(truncationDuration)
210210

211211
switch t.baseType {
212212
case sqltypes.Date:

sql/types/datetime_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestDatetimeCompare(t *testing.T) {
5757
{DatetimeMaxPrecision, "2010-06-03 06:03:11.123456111", "2010-06-03 06:03:11.123456333", 0},
5858
{MustCreateDatetimeType(sqltypes.Datetime, 3), "2010-06-03 06:03:11.123", "2010-06-03 06:03:11", 1},
5959
{MustCreateDatetimeType(sqltypes.Datetime, 3), "2010-06-03 06:03:11", "2010-06-03 06:03:11.123", -1},
60-
{MustCreateDatetimeType(sqltypes.Datetime, 3), "2010-06-03 06:03:11.123456", "2010-06-03 06:03:11.123789", 0},
60+
{MustCreateDatetimeType(sqltypes.Datetime, 3), "2010-06-03 06:03:11.123456", "2010-06-03 06:03:11.123789", -1},
6161
{Timestamp, time.Date(2012, 12, 12, 12, 12, 12, 12, time.UTC),
6262
time.Date(2012, 12, 12, 12, 24, 24, 24, time.UTC), -1},
6363
{Timestamp, time.Date(2012, 12, 12, 12, 12, 12, 12, time.UTC),
@@ -219,9 +219,9 @@ func TestDatetimeConvert(t *testing.T) {
219219
time.Date(2012, 12, 12, 12, 12, 12, 0, time.UTC), false},
220220
{Datetime, "2010-06-03 12:12:12.123456", time.Date(2010, 6, 3, 12, 12, 12, 0, time.UTC), false},
221221
{Datetime, "2010-06-03T12:12:12.123456Z", time.Date(2010, 6, 3, 12, 12, 12, 0, time.UTC), false},
222-
{Datetime, "2010-06-03 12:34:56.7", time.Date(2010, 6, 3, 12, 34, 56, 0, time.UTC), false},
223-
{Datetime, "2010-06-03 12:34:56.78", time.Date(2010, 6, 3, 12, 34, 56, 0, time.UTC), false},
224-
{Datetime, "2010-06-03 12:34:56.789", time.Date(2010, 6, 3, 12, 34, 56, 0, time.UTC), false},
222+
{Datetime, "2010-06-03 12:34:56.7", time.Date(2010, 6, 3, 12, 34, 57, 0, time.UTC), false},
223+
{Datetime, "2010-06-03 12:34:56.78", time.Date(2010, 6, 3, 12, 34, 57, 0, time.UTC), false},
224+
{Datetime, "2010-06-03 12:34:56.789", time.Date(2010, 6, 3, 12, 34, 57, 0, time.UTC), false},
225225

226226
{TimestampMaxPrecision, nil, nil, false},
227227
{TimestampMaxPrecision, time.Date(2012, 12, 12, 12, 12, 12, 12, time.UTC),
@@ -258,9 +258,9 @@ func TestDatetimeConvert(t *testing.T) {
258258
time.Date(2012, 12, 12, 12, 12, 12, 0, time.UTC), false},
259259
{Timestamp, "2010-06-03 12:12:12.123456", time.Date(2010, 6, 3, 12, 12, 12, 0, time.UTC), false},
260260
{Timestamp, "2010-06-03T12:12:12.123456Z", time.Date(2010, 6, 3, 12, 12, 12, 0, time.UTC), false},
261-
{Timestamp, "2010-06-03 12:34:56.7", time.Date(2010, 6, 3, 12, 34, 56, 0, time.UTC), false},
262-
{Timestamp, "2010-06-03 12:34:56.78", time.Date(2010, 6, 3, 12, 34, 56, 0, time.UTC), false},
263-
{Timestamp, "2010-06-03 12:34:56.789", time.Date(2010, 6, 3, 12, 34, 56, 0, time.UTC), false},
261+
{Timestamp, "2010-06-03 12:34:56.7", time.Date(2010, 6, 3, 12, 34, 57, 0, time.UTC), false},
262+
{Timestamp, "2010-06-03 12:34:56.78", time.Date(2010, 6, 3, 12, 34, 57, 0, time.UTC), false},
263+
{Timestamp, "2010-06-03 12:34:56.789", time.Date(2010, 6, 3, 12, 34, 57, 0, time.UTC), false},
264264

265265
{Date, "0000-01-01 00:00:00", time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC), false},
266266
{Date, "0500-01-01 00:00:00", time.Date(500, 1, 1, 0, 0, 0, 0, time.UTC), false},

0 commit comments

Comments
 (0)