Skip to content

Commit a66d435

Browse files
Merge branch 'main' into feat/issues/1443
2 parents 7621351 + c7926b2 commit a66d435

32 files changed

+1661
-134
lines changed

clickhouse_rows_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package clickhouse
22

33
import (
4+
"github.com/ClickHouse/clickhouse-go/v2/lib/column"
45
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
56
"github.com/stretchr/testify/assert"
67
"strconv"
@@ -10,9 +11,9 @@ import (
1011
func TestReadWithEmptyBlock(t *testing.T) {
1112
blockInitFunc := func() *proto.Block {
1213
retVal := &proto.Block{
13-
Packet: 0,
14-
Columns: nil,
15-
Timezone: nil,
14+
Packet: 0,
15+
Columns: nil,
16+
ServerContext: &column.ServerContext{},
1617
}
1718
retVal.AddColumn("col1", ("Int64"))
1819
retVal.AddColumn("col2", ("String"))

conn.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"crypto/tls"
2323
"errors"
2424
"fmt"
25+
"github.com/ClickHouse/clickhouse-go/v2/lib/column"
2526
"io"
2627
"log"
2728
"net"
@@ -356,6 +357,16 @@ func (c *connect) sendData(block *proto.Block, name string) error {
356357
return nil
357358
}
358359

360+
func serverVersionToContext(v ServerVersion) column.ServerContext {
361+
return column.ServerContext{
362+
Revision: v.Revision,
363+
VersionMajor: v.Version.Major,
364+
VersionMinor: v.Version.Minor,
365+
VersionPatch: v.Version.Patch,
366+
Timezone: v.Timezone,
367+
}
368+
}
369+
359370
func (c *connect) readData(ctx context.Context, packet byte, compressible bool) (*proto.Block, error) {
360371
if c.isClosed() {
361372
err := errors.New("attempted reading on closed connection")
@@ -385,7 +396,9 @@ func (c *connect) readData(ctx context.Context, packet byte, compressible bool)
385396
location = userLocation
386397
}
387398

388-
block := proto.Block{Timezone: location}
399+
serverContext := serverVersionToContext(c.server)
400+
serverContext.Timezone = location
401+
block := proto.Block{ServerContext: &serverContext}
389402
if err := block.Decode(c.reader, c.revision); err != nil {
390403
c.debugf("[read data] decode error: %v", err)
391404
return nil, err

conn_batch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (b *batch) Columns() []column.Interface {
321321
}
322322

323323
func (b *batch) closeQuery() error {
324-
if err := b.conn.sendData(&proto.Block{}, ""); err != nil {
324+
if err := b.conn.sendData(proto.NewBlock(), ""); err != nil {
325325
return err
326326
}
327327

conn_http.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@ func (h *httpConnect) readData(reader *chproto.Reader, timezone *time.Location)
429429
location = timezone
430430
}
431431

432-
block := proto.Block{Timezone: location}
432+
serverContext := serverVersionToContext(h.handshake)
433+
serverContext.Timezone = location
434+
block := proto.Block{ServerContext: &serverContext}
433435
if h.compression == CompressionLZ4 || h.compression == CompressionZSTD {
434436
reader.EnableCompression()
435437
defer reader.DisableCompression()

conn_http_batch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ func newBlock(h *httpConnect, release nativeTransportRelease, ctx context.Contex
107107
}
108108

109109
var block proto.Block
110+
serverContext := serverVersionToContext(h.handshake)
111+
block.ServerContext = &serverContext
110112
for _, col := range columns {
111113
if err := block.AddColumn(col.Name, column.Type(col.Type)); err != nil {
112114
return "", nil, err

conn_http_query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (h *httpConnect) query(ctx context.Context, release nativeTransportRelease,
5555

5656
if res.ContentLength == 0 {
5757
discardAndClose(res.Body)
58-
block := &proto.Block{}
58+
block := proto.NewBlock()
5959
release(h, nil)
6060
return &rows{
6161
block: block,
@@ -122,7 +122,7 @@ func (h *httpConnect) query(ctx context.Context, release nativeTransportRelease,
122122
}()
123123

124124
if block == nil {
125-
block = &proto.Block{}
125+
block = proto.NewBlock()
126126
}
127127

128128
return &rows{

conn_send_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *connect) sendQuery(body string, o *QueryOptions) error {
4747
return err
4848
}
4949
}
50-
if err := c.sendData(&proto.Block{}, ""); err != nil {
50+
if err := c.sendData(proto.NewBlock(), ""); err != nil {
5151
return err
5252
}
5353
return c.flush()

ext/ext.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
func NewTable(name string, columns ...func(t *Table) error) (*Table, error) {
2828
table := &Table{
2929
name: name,
30-
block: &proto.Block{},
30+
block: proto.NewBlock(),
3131
}
3232
for _, column := range columns {
3333
if err := column(table); err != nil {

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/paulmach/orb v0.11.1
1515
github.com/shopspring/decimal v1.4.0
1616
github.com/stretchr/testify v1.10.0
17-
github.com/testcontainers/testcontainers-go v0.37.0
17+
github.com/testcontainers/testcontainers-go v0.38.0
1818
go.opentelemetry.io/otel/trace v1.37.0
1919
golang.org/x/net v0.42.0
2020
gopkg.in/yaml.v3 v3.0.1
@@ -35,7 +35,7 @@ require (
3535
github.com/davecgh/go-spew v1.1.1 // indirect
3636
github.com/distribution/reference v0.6.0 // indirect
3737
github.com/docker/go-connections v0.5.0 // indirect
38-
github.com/ebitengine/purego v0.8.2 // indirect
38+
github.com/ebitengine/purego v0.8.4 // indirect
3939
github.com/felixge/httpsnoop v1.0.4 // indirect
4040
github.com/go-faster/city v1.0.1 // indirect
4141
github.com/go-faster/errors v0.7.1 // indirect
@@ -50,7 +50,6 @@ require (
5050
github.com/moby/docker-image-spec v1.3.1 // indirect
5151
github.com/moby/go-archive v0.1.0 // indirect
5252
github.com/moby/patternmatcher v0.6.0 // indirect
53-
github.com/moby/sys/atomicwriter v0.1.0 // indirect
5453
github.com/moby/sys/sequential v0.6.0 // indirect
5554
github.com/moby/sys/user v0.4.0 // indirect
5655
github.com/moby/sys/userns v0.1.0 // indirect
@@ -64,7 +63,7 @@ require (
6463
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
6564
github.com/segmentio/asm v1.2.0 // indirect
6665
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
67-
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
66+
github.com/shirou/gopsutil/v4 v4.25.5 // indirect
6867
github.com/sirupsen/logrus v1.9.3 // indirect
6968
github.com/tklauser/go-sysconf v0.3.12 // indirect
7069
github.com/tklauser/numcpus v0.6.1 // indirect
@@ -76,5 +75,4 @@ require (
7675
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
7776
golang.org/x/crypto v0.40.0 // indirect
7877
golang.org/x/sys v0.34.0 // indirect
79-
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
8078
)

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
3636
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
3737
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
3838
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
39-
github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I=
40-
github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
39+
github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw=
40+
github.com/ebitengine/purego v0.8.4/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
4141
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
4242
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
4343
github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw=
@@ -128,8 +128,8 @@ github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr
128128
github.com/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
129129
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
130130
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
131-
github.com/shirou/gopsutil/v4 v4.25.1 h1:QSWkTc+fu9LTAWfkZwZ6j8MSUk4A2LV7rbH0ZqmLjXs=
132-
github.com/shirou/gopsutil/v4 v4.25.1/go.mod h1:RoUCUpndaJFtT+2zsZzzmhvbfGoDCJ7nFXKJf8GqJbI=
131+
github.com/shirou/gopsutil/v4 v4.25.5 h1:rtd9piuSMGeU8g1RMXjZs9y9luK5BwtnG7dZaQUJAsc=
132+
github.com/shirou/gopsutil/v4 v4.25.5/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c=
133133
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
134134
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
135135
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
@@ -143,8 +143,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
143143
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
144144
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
145145
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
146-
github.com/testcontainers/testcontainers-go v0.37.0 h1:L2Qc0vkTw2EHWQ08djon0D2uw7Z/PtHS/QzZZ5Ra/hg=
147-
github.com/testcontainers/testcontainers-go v0.37.0/go.mod h1:QPzbxZhQ6Bclip9igjLFj6z0hs01bU8lrl2dHQmgFGM=
146+
github.com/testcontainers/testcontainers-go v0.38.0 h1:d7uEapLcv2P8AvH8ahLqDMMxda2W9gQN1nRbHS28HBw=
147+
github.com/testcontainers/testcontainers-go v0.38.0/go.mod h1:C52c9MoHpWO+C4aqmgSU+hxlR5jlEayWtgYrb8Pzz1w=
148148
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
149149
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
150150
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
@@ -232,8 +232,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
232232
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
233233
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
234234
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
235-
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4=
236-
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE=
235+
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8=
236+
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo=
237237
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
238238
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
239239
google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw=

0 commit comments

Comments
 (0)