Skip to content

Commit 5eadbcd

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 1766034 + a5edb3d commit 5eadbcd

File tree

8 files changed

+50
-3
lines changed

8 files changed

+50
-3
lines changed

.github/workflows/run-tests-cloud.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
shell: bash
1919
strategy:
2020
fail-fast: true
21+
max-parallel: 1
2122
matrix:
2223
go:
2324
- "1.22"

.github/workflows/run-tests-head.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
fail-fast: true
18+
max-parallel: 1
1819
matrix:
1920
go:
2021
- "1.20"

.github/workflows/run-tests.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
fail-fast: true
18+
max-parallel: 1
1819
matrix:
1920
go:
2021
- "1.22"

bind.go

+6
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ func bindNamed(tz *time.Location, query string, args ...any) (_ string, err erro
247247
func formatTime(tz *time.Location, scale TimeUnit, value time.Time) (string, error) {
248248
switch value.Location().String() {
249249
case "Local", "":
250+
// It's required to pass timestamp as string due to decimal overflow for higher precision,
251+
// but zero-value string "toDateTime('0')" will be not parsed by ClickHouse.
252+
if value.Unix() == 0 {
253+
return "toDateTime(0)", nil
254+
}
255+
250256
switch scale {
251257
case Seconds:
252258
return fmt.Sprintf("toDateTime('%d')", value.Unix()), nil

bind_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -268,27 +268,35 @@ func TestFormatScaledTime(t *testing.T) {
268268
require.Equal(t, "toDateTime('2022-01-12 15:00:00')", val)
269269
val, _ = format(t1.Location(), Seconds, t1.In(time.Now().Location()))
270270
require.Equal(t, "toDateTime('1641999600')", val)
271+
val, _ = format(t1.Location(), Seconds, time.Unix(0, 0))
272+
require.Equal(t, "toDateTime(0)", val)
271273
val, _ = format(tz, Seconds, t1)
272274
require.Equal(t, "toDateTime('2022-01-12 15:00:00', 'UTC')", val)
273275
// milliseconds
274276
val, _ = format(t1.Location(), MilliSeconds, t1)
275277
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123', 3)", val)
276278
val, _ = format(t1.Location(), MilliSeconds, t1.In(time.Now().Location()))
277279
require.Equal(t, "toDateTime64('1641999600123', 3)", val)
280+
val, _ = format(t1.Location(), MilliSeconds, time.Unix(0, 0))
281+
require.Equal(t, "toDateTime(0)", val)
278282
val, _ = format(tz, MilliSeconds, t1)
279283
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123', 3, 'UTC')", val)
280284
// microseconds
281285
val, _ = format(t1.Location(), MicroSeconds, t1)
282286
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123456', 6)", val)
283287
val, _ = format(t1.Location(), MicroSeconds, t1.In(time.Now().Location()))
284288
require.Equal(t, "toDateTime64('1641999600123456', 6)", val)
289+
val, _ = format(t1.Location(), MicroSeconds, time.Unix(0, 0))
290+
require.Equal(t, "toDateTime(0)", val)
285291
val, _ = format(tz, MicroSeconds, t1)
286292
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123456', 6, 'UTC')", val)
287293
// nanoseconds
288294
val, _ = format(t1.Location(), NanoSeconds, t1)
289295
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123456789', 9)", val)
290296
val, _ = format(t1.Location(), NanoSeconds, t1.In(time.Now().Location()))
291297
require.Equal(t, "toDateTime64('1641999600123456789', 9)", val)
298+
val, _ = format(t1.Location(), NanoSeconds, time.Unix(0, 0))
299+
require.Equal(t, "toDateTime(0)", val)
292300
val, _ = format(tz, NanoSeconds, t1)
293301
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123456789', 9, 'UTC')", val)
294302
}

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/ClickHouse/ch-go v0.61.5
77
github.com/ClickHouse/clickhouse-go v1.5.4
88
github.com/andybalholm/brotli v1.1.0
9-
github.com/docker/docker v25.0.3+incompatible
9+
github.com/docker/docker v26.0.0+incompatible
1010
github.com/docker/go-connections v0.5.0
1111
github.com/docker/go-units v0.5.0
1212
github.com/google/uuid v1.6.0
@@ -47,6 +47,7 @@ require (
4747
github.com/klauspost/compress v1.17.7 // indirect
4848
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
4949
github.com/magiconair/properties v1.8.7 // indirect
50+
github.com/moby/docker-image-spec v1.3.1 // indirect
5051
github.com/moby/patternmatcher v0.6.0 // indirect
5152
github.com/moby/sys/sequential v0.5.0 // indirect
5253
github.com/moby/sys/user v0.1.0 // indirect

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
3434
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3535
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
3636
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
37-
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
38-
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
37+
github.com/docker/docker v26.0.0+incompatible h1:Ng2qi+gdKADUa/VM+6b6YaY2nlZhk/lVJiKR/2bMudU=
38+
github.com/docker/docker v26.0.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
3939
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
4040
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
4141
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
@@ -95,6 +95,8 @@ github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3v
9595
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
9696
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615 h1:/mD+ABZyXD39BzJI2XyRJlqdZG11gXFo0SSynL+OFeU=
9797
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615/go.mod h1:Ad7oeElCZqA1Ufj0U9/liOF4BtVepxRcTvr2ey7zTvM=
98+
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
99+
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
98100
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
99101
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
100102
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc=

tests/issues/1016_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package issues
2+
3+
import (
4+
"context"
5+
"testing"
6+
"time"
7+
8+
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func Test1016(t *testing.T) {
13+
testEnv, err := clickhouse_tests.GetTestEnvironment("issues")
14+
require.NoError(t, err)
15+
conn, err := clickhouse_tests.TestClientWithDefaultSettings(testEnv)
16+
require.NoError(t, err)
17+
18+
rows, err := conn.Query(context.Background(), "SELECT ?;", time.Unix(0, 0).UTC())
19+
require.NoError(t, err)
20+
defer rows.Close()
21+
22+
require.True(t, rows.Next())
23+
var v time.Time
24+
err = rows.Scan(&v)
25+
require.NoError(t, err)
26+
require.Equal(t, time.Unix(0, 0).UTC(), v)
27+
}

0 commit comments

Comments
 (0)