Skip to content

Instantly share code, notes, and snippets.

@kavirajk
Created October 14, 2025 10:27
Show Gist options
  • Save kavirajk/0125d22231303d860b3e1ad4064683e5 to your computer and use it in GitHub Desktop.
Save kavirajk/0125d22231303d860b3e1ad4064683e5 to your computer and use it in GitHub Desktop.
default_http_compression_test.go
package code
import (
"context"
"testing"
"time"
"github.com/ClickHouse/clickhouse-go/v2"
"github.com/stretchr/testify/require"
)
func TestDefaultHTTPCompress(t *testing.T) {
ctx := context.Background()
conn := clickhouse.OpenDB(&clickhouse.Options{
MaxOpenConns: 8,
Addr: []string{"localhost:8123"},
Protocol: clickhouse.HTTP,
// Debug: true,
Compression: &clickhouse.Compression{
Method: clickhouse.CompressionGZIP,
},
})
require.NoError(t, conn.Ping())
_, err := conn.Exec(`DROP TABLE IF EXISTS example`)
require.NoError(t, err)
const ddl = `
CREATE TABLE example (
Col1 UInt64
, Col2 String
, Col3 Array(UInt8)
, Col4 DateTime
) ENGINE = Memory
`
_, err = conn.Exec(ddl)
require.NoError(t, err)
for i := 0; i < 100; i++ {
_, err := conn.Exec(`INSERT INTO example VALUES (?, ?, ?, now())`, i, "Golang", []uint8{1, 2, 4})
require.NoError(t, err)
}
row := conn.QueryRow(`SELECT * FROM example WHERE Col1=99`)
var (
col1 uint64
col2 string
col3 []uint8
col4 time.Time
)
err = row.Scan(&col1, &col2, &col3, &col4)
require.NoError(t, err)
conn2, err := clickhouse.Open(&clickhouse.Options{
MaxOpenConns: 8,
Addr: []string{"localhost:8123"},
Protocol: clickhouse.HTTP,
// Debug: true,
})
if err != nil {
panic(err)
}
require.NoError(t, conn2.Ping(ctx))
row2 := conn2.QueryRow(ctx, `SELECT * FROM example WHERE Col1=99`)
err = row2.Scan(&col1, &col2, &col3, &col4)
require.NoError(t, err)
}
@kavirajk
Copy link
Author

$ go test . -run TestDefault -v
=== RUN   TestDefaultHTTPCompress
[http query] compression gzip
[http query] compression gzip
[http query] compression gzip
[http query] compression none
[http query] compression none
[http query] compression none
--- PASS: TestDefaultHTTPCompress (0.08s)
PASS
ok  	play-go	0.084s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment