Skip to content

Commit cad3e77

Browse files
authored
[Feature] support client_protocol_version (#553)
* feature: support client_protocol_version * feature: support client_protocol_version
1 parent a9364c8 commit cad3e77

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

cache/key.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ type Key struct {
2020
// AcceptEncoding must contain 'Accept-Encoding' request header value.
2121
AcceptEncoding string
2222

23+
// ClientProtocolVersion must contain `client_protocol_version` query arg.
24+
ClientProtocolVersion string
25+
2326
// DefaultFormat must contain `default_format` query arg.
2427
DefaultFormat string
2528

@@ -62,6 +65,7 @@ func NewKey(query []byte, originParams url.Values, acceptEncoding string, userPa
6265
return &Key{
6366
Query: query,
6467
AcceptEncoding: acceptEncoding,
68+
ClientProtocolVersion: originParams.Get("client_protocol_version"),
6569
DefaultFormat: originParams.Get("default_format"),
6670
Database: originParams.Get("database"),
6771
Compress: originParams.Get("compress"),
@@ -83,8 +87,8 @@ func (k *Key) filePath(dir string) string {
8387

8488
// String returns string representation of the key.
8589
func (k *Key) String() string {
86-
s := fmt.Sprintf("V%d; Query=%q; AcceptEncoding=%q; DefaultFormat=%q; Database=%q; Compress=%q; EnableHTTPCompression=%q; Namespace=%q; MaxResultRows=%q; Extremes=%q; ResultOverflowMode=%q; UserParams=%d; QueryParams=%d; UserCredentialHash=%d",
87-
k.Version, k.Query, k.AcceptEncoding, k.DefaultFormat, k.Database, k.Compress, k.EnableHTTPCompression, k.Namespace,
90+
s := fmt.Sprintf("V%d; Query=%q; AcceptEncoding=%q; ClientProtocolVersion=%q; DefaultFormat=%q; Database=%q; Compress=%q; EnableHTTPCompression=%q; Namespace=%q; MaxResultRows=%q; Extremes=%q; ResultOverflowMode=%q; UserParams=%d; QueryParams=%d; UserCredentialHash=%d",
91+
k.Version, k.Query, k.AcceptEncoding, k.ClientProtocolVersion, k.DefaultFormat, k.Database, k.Compress, k.EnableHTTPCompression, k.Namespace,
8892
k.MaxResultRows, k.Extremes, k.ResultOverflowMode, k.UserParamsHash, k.QueryParamsHash, k.UserCredentialHash)
8993
h := sha256.Sum256([]byte(s))
9094

cache/key_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ func TestKeyString(t *testing.T) {
1515
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
1616
Version: 2,
1717
},
18-
expected: "f11e8438adeeb325881c9a4da01925b3",
18+
expected: "4e3e71f4d94f34b6c8cab4888486a116",
1919
},
2020
{
2121
key: &Key{
2222
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
2323
AcceptEncoding: "gzip",
2424
Version: 2,
2525
},
26-
expected: "045cbb29a40a81c42378569cf0bc4078",
26+
expected: "ba19aeff43f8cd4440a28f883201f342",
2727
},
2828
{
2929
key: &Key{
@@ -32,7 +32,7 @@ func TestKeyString(t *testing.T) {
3232
DefaultFormat: "JSON",
3333
Version: 2,
3434
},
35-
expected: "186386850c49c60a49dbf7af89c671c9",
35+
expected: "341b43e5ce0ceafb3f49664d9b124618",
3636
},
3737
{
3838
key: &Key{
@@ -42,7 +42,7 @@ func TestKeyString(t *testing.T) {
4242
Database: "foobar",
4343
Version: 2,
4444
},
45-
expected: "68f3231d17cad0a3473e63f419e07580",
45+
expected: "bd864dd1d3dfec711f15830a0601a11e",
4646
},
4747
{
4848
key: &Key{
@@ -53,7 +53,7 @@ func TestKeyString(t *testing.T) {
5353
Namespace: "ns123",
5454
Version: 2,
5555
},
56-
expected: "8f5e765e69df7c24a58f13cdf752ad2f",
56+
expected: "04e932bafebeeb6b4c7c07288b37db3c",
5757
},
5858
{
5959
key: &Key{
@@ -65,23 +65,23 @@ func TestKeyString(t *testing.T) {
6565
Namespace: "ns123",
6666
Version: 2,
6767
},
68-
expected: "93a121f03f438ef7969540c78e943e2c",
68+
expected: "2cd1c2db405f570c2eb61fd4a02b8f05",
6969
},
7070
{
7171
key: &Key{
7272
Query: []byte("SELECT * FROM {table_name:Identifier} LIMIT 10"),
7373
QueryParamsHash: 3825709,
7474
Version: 3,
7575
},
76-
expected: "7edddc7d9db4bc4036dee36893f57cb1",
76+
expected: "b39b64fc48f705017a4734e824c4e62a",
7777
},
7878
{
7979
key: &Key{
8080
Query: []byte("SELECT * FROM {table_name:Identifier} LIMIT 10"),
8181
QueryParamsHash: 3825710,
8282
Version: 3,
8383
},
84-
expected: "68ba76fb53a6fa71ba8fe63dd34a2201",
84+
expected: "925e7c71544fc398a97d8e49426d61e3",
8585
},
8686
{
8787
key: &Key{
@@ -90,7 +90,18 @@ func TestKeyString(t *testing.T) {
9090
Version: 3,
9191
UserCredentialHash: 234324,
9292
},
93-
expected: "c5b58ecb4ff026e62ee846dc63c749d5",
93+
expected: "12b86ad023144c27676195e0ebce7f22",
94+
},
95+
{
96+
key: &Key{
97+
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
98+
AcceptEncoding: "gzip",
99+
ClientProtocolVersion: "54460",
100+
DefaultFormat: "JSON",
101+
Database: "foobar",
102+
Version: 5,
103+
},
104+
expected: "63faa92cb204a36ded33036ca4d429d5",
94105
},
95106
}
96107

scope.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ var allowedParams = []string{
363363
"query",
364364
"database",
365365
"default_format",
366+
"client_protocol_version",
366367
// if `compress=1`, CH will compress the data it sends you
367368
"compress",
368369
// if `decompress=1` , CH will decompress the same data that you pass in the POST method

0 commit comments

Comments
 (0)