Skip to content

Commit 510fda5

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents c88fb17 + e649f6f commit 510fda5

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

TYPES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The following table aims to capture the Golang types supported for each ClickHouse Column Type.
1+
The following table aims to capture the Golang types supported for each ClickHouse Column Type.
22

33
Whilst each ClickHouse type often has a logical Golang type, we aim to support implicit conversions where possible and provided no precision loss will be incurred - thus alleviating the need for users to ensure their data aligns perfectly with ClickHouse types.
44

@@ -56,7 +56,7 @@ All types can be read into a pointer or pointer to a pointer.
5656
| uint16 | | | | | | | X | | | | | | | | | | | | | | | | | | | | | | | |
5757
| uint8 | | | | | | X | | | | | | | | | | | | | | | | | | | | | | | | |
5858
| int | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
59-
| int64 | | | | | | | | | | | | | | | X | | | | | | | | | | | | | | | |
59+
| int64 | | | | | | | | | | | | | | | X | | | | | | | | x | x | | | | | | |
6060
| int32 | | | | | | | | | | | | | | X | | | | | | | | | | | | | | | | |
6161
| int16 | | | | | | | | | | | | | X | | | | | | | | | | | | | | | | | |
6262
| int8 | | | | | | | | | | | | X | | | | | | | | | | | | | | | | | | |

lib/column/datetime.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ func (col *DateTime) ScanRow(dest any, row int) error {
9595
case **time.Time:
9696
*d = new(time.Time)
9797
**d = col.row(row)
98+
case *int64:
99+
*d = col.row(row).Unix()
100+
case **int64:
101+
*d = new(int64)
102+
**d = col.row(row).Unix()
98103
case *sql.NullTime:
99104
return d.Scan(col.row(row))
100105
default:

lib/column/datetime64.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ func (col *DateTime64) ScanRow(dest any, row int) error {
119119
case **time.Time:
120120
*d = new(time.Time)
121121
**d = col.row(row)
122+
case *int64:
123+
*d = int64(proto.ToDateTime64(col.row(row), col.col.Precision))
124+
case **int64:
125+
*d = new(int64)
126+
**d = int64(proto.ToDateTime64(col.row(row), col.col.Precision))
122127
case *sql.NullTime:
123128
return d.Scan(col.row(row))
124129
default:

tests/array_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,10 @@ func TestInterfaceArray(t *testing.T) {
143143
rows, err := conn.Query(ctx, "SELECT * FROM test_array")
144144
require.NoError(t, err)
145145
for rows.Next() {
146-
var (
147-
col1 any
148-
)
146+
var col1 []string
149147
require.NoError(t, rows.Scan(&col1))
150-
assert.ObjectsAreEqual(col1Data, col1)
148+
require.Equal(t, col1Data, col1)
149+
151150
}
152151
require.NoError(t, rows.Close())
153152
require.NoError(t, rows.Err())

tests/datetime64_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func TestDateTime64(t *testing.T) {
5151
, Col8 DateTime64(6)
5252
, Col9 DateTime64(9)
5353
, Col10 DateTime64(9)
54+
, Col11 DateTime64(9)
55+
, Col12 DateTime64(6)
5456
) Engine MergeTree() ORDER BY tuple()
5557
`
5658
defer func() {
@@ -78,6 +80,8 @@ func TestDateTime64(t *testing.T) {
7880
datetime1.UTC().Format("2006-01-02 15:04:05.999 +00:00"),
7981
datetime1.UTC().Format("2006-01-02 15:04:05.999 +00:00"),
8082
datetimeStu,
83+
datetime2,
84+
datetime2,
8185
))
8286
require.NoError(t, batch.Send())
8387
var (
@@ -91,8 +95,11 @@ func TestDateTime64(t *testing.T) {
9195
col8 time.Time
9296
col9 time.Time
9397
col10 time.Time
98+
col11 int64
99+
col12 int64
94100
)
95-
require.NoError(t, conn.QueryRow(ctx, "SELECT * FROM test_datetime64").Scan(&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8, &col9, &col10))
101+
require.NoError(t, conn.QueryRow(ctx, "SELECT * FROM test_datetime64").Scan(&col1, &col2, &col3, &col4,
102+
&col5, &col6, &col7, &col8, &col9, &col10, &col11, &col12))
96103
assert.Equal(t, datetime1.In(time.UTC), col1)
97104
assert.Equal(t, datetime2.UnixNano(), col2.UnixNano())
98105
assert.Equal(t, datetime3.UnixNano(), col3.UnixNano())
@@ -110,6 +117,8 @@ func TestDateTime64(t *testing.T) {
110117
assert.Equal(t, datetime1.In(time.UTC), col8)
111118
assert.Equal(t, datetime1.In(time.UTC), col9)
112119
assert.Equal(t, datetime1.In(time.UTC), col10)
120+
assert.Equal(t, col11, datetime2.UnixNano())
121+
assert.Equal(t, col12, datetime2.UnixMicro())
113122
}
114123

115124
func TestDateTime64AsReference(t *testing.T) {

tests/datetime_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ func TestColumnarDateTime(t *testing.T) {
242242
, Col5 Array(DateTime)
243243
, Col6 Array(Nullable(DateTime))
244244
, Col7 DateTime
245+
, Col8 DateTime
245246
) Engine MergeTree() ORDER BY tuple()
246247
`
247248
defer func() {
@@ -297,6 +298,7 @@ func TestColumnarDateTime(t *testing.T) {
297298
require.NoError(t, batch.Column(5).Append(col5Data))
298299
require.NoError(t, batch.Column(6).Append(col6Data))
299300
require.NoError(t, batch.Column(7).Append(col7Data))
301+
require.NoError(t, batch.Column(8).Append(col1Data))
300302
}
301303
require.Equal(t, 1000, batch.Rows())
302304
require.NoError(t, batch.Send())
@@ -308,8 +310,9 @@ func TestColumnarDateTime(t *testing.T) {
308310
Col5 []time.Time
309311
Col6 []*time.Time
310312
Col7 time.Time
313+
Col8 int64
311314
}
312-
require.NoError(t, conn.QueryRow(ctx, "SELECT Col1, Col2, Col3, Col4, Col5, Col6, Col7 FROM test_datetime WHERE ID = $1", 11).ScanStruct(&result))
315+
require.NoError(t, conn.QueryRow(ctx, "SELECT Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8 FROM test_datetime WHERE ID = $1", 11).ScanStruct(&result))
313316
require.Nil(t, result.Col2)
314317
assert.Equal(t, datetime1.In(time.UTC), result.Col1)
315318
assert.Equal(t, []time.Time{datetime1.In(time.UTC), datetime2.In(time.UTC), datetime1.In(time.UTC)}, result.Col3)
@@ -319,6 +322,7 @@ func TestColumnarDateTime(t *testing.T) {
319322
assert.Equal(t, []time.Time{datetime2.In(time.UTC), datetime2.In(time.UTC), datetime2.In(time.UTC)}, result.Col5)
320323
assert.Equal(t, []*time.Time{nil, nil, nil}, result.Col6)
321324
assert.Equal(t, datetime1.In(time.UTC), result.Col7)
325+
assert.Equal(t, datetime1.Truncate(time.Second).Unix(), result.Col8)
322326
}
323327

324328
func TestDateTimeFlush(t *testing.T) {

0 commit comments

Comments
 (0)