Skip to content

Commit

Permalink
Fix DateTime64 range to actual supported range per ClickHouse documen…
Browse files Browse the repository at this point in the history
…tation (#1148)

* fix datetime64 range to actual supported range per clickhouse docu

* fix datetime64 range to actual supported range per clickhouse docu

* datetime64 allowed min date test

---------

Co-authored-by: Philipp Schreiber <[email protected]>
  • Loading branch information
phil-schreiber and Philipp Schreiber authored Nov 29, 2023
1 parent 364719b commit a7b26f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/column/datetime64.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
)

var (
minDateTime64, _ = time.Parse("2006-01-02 15:04:05", "1925-01-01 00:00:00")
maxDateTime64, _ = time.Parse("2006-01-02 15:04:05", "2283-11-11 00:00:00")
minDateTime64, _ = time.Parse("2006-01-02 15:04:05", "1900-01-01 00:00:00")
maxDateTime64, _ = time.Parse("2006-01-02 15:04:05", "2262-04-11 23:47:16")
)

const (
Expand Down
8 changes: 7 additions & 1 deletion tests/std/datetime64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestStdDateTime64(t *testing.T) {
, Col6 Array(Nullable(DateTime64(3, 'Europe/Moscow')))
, Col7 DateTime64(0, 'Europe/London')
, Col8 Nullable(DateTime64(3, 'Europe/Moscow'))
, Col9 DateTime64(9)
) Engine MergeTree() ORDER BY tuple()
`
defer func() {
Expand All @@ -68,6 +69,8 @@ func TestStdDateTime64(t *testing.T) {
datetime2 = time.Now().Truncate(time.Nanosecond)
datetime3 = time.Now().Truncate(time.Second)
)
expectedMinDateTime, err := time.Parse("2006-01-02 15:04:05", "1900-01-01 00:00:00")
require.NoError(t, err)
_, err = batch.Exec(
datetime1,
datetime2,
Expand All @@ -77,6 +80,7 @@ func TestStdDateTime64(t *testing.T) {
[]*time.Time{&datetime3, nil, &datetime3},
sql.NullTime{Time: datetime3, Valid: true},
sql.NullTime{Time: time.Time{}, Valid: false},
expectedMinDateTime,
)
require.NoError(t, err)
require.NoError(t, scope.Commit())
Expand All @@ -89,8 +93,9 @@ func TestStdDateTime64(t *testing.T) {
col6 []*time.Time
col7 sql.NullTime
col8 sql.NullTime
col9 time.Time
)
require.NoError(t, conn.QueryRow("SELECT * FROM test_datetime64").Scan(&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8))
require.NoError(t, conn.QueryRow("SELECT * FROM test_datetime64").Scan(&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8, &col9))
assert.Equal(t, datetime1.In(time.UTC), col1)
assert.Equal(t, datetime2.UnixNano(), col2.UnixNano())
assert.Equal(t, datetime3.UnixNano(), col3.UnixNano())
Expand All @@ -107,6 +112,7 @@ func TestStdDateTime64(t *testing.T) {
assert.NotNil(t, col6[2])
require.Equal(t, sql.NullTime{Time: datetime3.In(col7.Time.Location()), Valid: true}, col7)
require.Equal(t, sql.NullTime{Time: time.Time{}, Valid: false}, col8)
require.Equal(t, time.Date(1900, 01, 01, 0, 0, 0, 0, time.UTC), col9)
})
}
}

0 comments on commit a7b26f0

Please sign in to comment.