Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DateTime64 range to actual supported range per ClickHouse documentation #1148

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
}
Loading