Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaflik committed Mar 28, 2024
2 parents 1766034 + a5edb3d commit 5eadbcd
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-tests-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
shell: bash
strategy:
fail-fast: true
max-parallel: 1
matrix:
go:
- "1.22"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run-tests-head.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 1
matrix:
go:
- "1.20"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 1
matrix:
go:
- "1.22"
Expand Down
6 changes: 6 additions & 0 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ func bindNamed(tz *time.Location, query string, args ...any) (_ string, err erro
func formatTime(tz *time.Location, scale TimeUnit, value time.Time) (string, error) {
switch value.Location().String() {
case "Local", "":
// It's required to pass timestamp as string due to decimal overflow for higher precision,
// but zero-value string "toDateTime('0')" will be not parsed by ClickHouse.
if value.Unix() == 0 {
return "toDateTime(0)", nil
}

switch scale {
case Seconds:
return fmt.Sprintf("toDateTime('%d')", value.Unix()), nil
Expand Down
8 changes: 8 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,35 @@ func TestFormatScaledTime(t *testing.T) {
require.Equal(t, "toDateTime('2022-01-12 15:00:00')", val)
val, _ = format(t1.Location(), Seconds, t1.In(time.Now().Location()))
require.Equal(t, "toDateTime('1641999600')", val)
val, _ = format(t1.Location(), Seconds, time.Unix(0, 0))
require.Equal(t, "toDateTime(0)", val)
val, _ = format(tz, Seconds, t1)
require.Equal(t, "toDateTime('2022-01-12 15:00:00', 'UTC')", val)
// milliseconds
val, _ = format(t1.Location(), MilliSeconds, t1)
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123', 3)", val)
val, _ = format(t1.Location(), MilliSeconds, t1.In(time.Now().Location()))
require.Equal(t, "toDateTime64('1641999600123', 3)", val)
val, _ = format(t1.Location(), MilliSeconds, time.Unix(0, 0))
require.Equal(t, "toDateTime(0)", val)
val, _ = format(tz, MilliSeconds, t1)
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123', 3, 'UTC')", val)
// microseconds
val, _ = format(t1.Location(), MicroSeconds, t1)
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123456', 6)", val)
val, _ = format(t1.Location(), MicroSeconds, t1.In(time.Now().Location()))
require.Equal(t, "toDateTime64('1641999600123456', 6)", val)
val, _ = format(t1.Location(), MicroSeconds, time.Unix(0, 0))
require.Equal(t, "toDateTime(0)", val)
val, _ = format(tz, MicroSeconds, t1)
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123456', 6, 'UTC')", val)
// nanoseconds
val, _ = format(t1.Location(), NanoSeconds, t1)
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123456789', 9)", val)
val, _ = format(t1.Location(), NanoSeconds, t1.In(time.Now().Location()))
require.Equal(t, "toDateTime64('1641999600123456789', 9)", val)
val, _ = format(t1.Location(), NanoSeconds, time.Unix(0, 0))
require.Equal(t, "toDateTime(0)", val)
val, _ = format(tz, NanoSeconds, t1)
require.Equal(t, "toDateTime64('2022-01-12 15:00:00.123456789', 9, 'UTC')", val)
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/ClickHouse/ch-go v0.61.5
github.com/ClickHouse/clickhouse-go v1.5.4
github.com/andybalholm/brotli v1.1.0
github.com/docker/docker v25.0.3+incompatible
github.com/docker/docker v26.0.0+incompatible
github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -47,6 +47,7 @@ require (
github.com/klauspost/compress v1.17.7 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v26.0.0+incompatible h1:Ng2qi+gdKADUa/VM+6b6YaY2nlZhk/lVJiKR/2bMudU=
github.com/docker/docker v26.0.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down Expand Up @@ -95,6 +95,8 @@ github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3v
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615 h1:/mD+ABZyXD39BzJI2XyRJlqdZG11gXFo0SSynL+OFeU=
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615/go.mod h1:Ad7oeElCZqA1Ufj0U9/liOF4BtVepxRcTvr2ey7zTvM=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc=
Expand Down
27 changes: 27 additions & 0 deletions tests/issues/1016_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package issues

import (
"context"
"testing"
"time"

clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
"github.com/stretchr/testify/require"
)

func Test1016(t *testing.T) {
testEnv, err := clickhouse_tests.GetTestEnvironment("issues")
require.NoError(t, err)
conn, err := clickhouse_tests.TestClientWithDefaultSettings(testEnv)
require.NoError(t, err)

rows, err := conn.Query(context.Background(), "SELECT ?;", time.Unix(0, 0).UTC())
require.NoError(t, err)
defer rows.Close()

require.True(t, rows.Next())
var v time.Time
err = rows.Scan(&v)
require.NoError(t, err)
require.Equal(t, time.Unix(0, 0).UTC(), v)
}

0 comments on commit 5eadbcd

Please sign in to comment.