Skip to content

Commit 8f9592e

Browse files
hagen1778valyala
authored andcommitted
allow to pass max_results_row, extremes and result_overflow_mode params
1 parent 6dfcbf9 commit 8f9592e

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

cache/cache.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,24 @@ type Key struct {
8080
// Namespace is an optional cache namespace.
8181
Namespace string
8282

83+
// MaxResultRows must contain `max_result_rows` query arg
84+
MaxResultRows string
85+
86+
// Extremes must contain `extremes` query arg
87+
Extremes string
88+
89+
// ResultOverflowMode must contain `result_overflow_mode` query arg
90+
ResultOverflowMode string
91+
8392
// UserParamsHash must contain hashed value of users params
8493
UserParamsHash uint32
8594
}
8695

8796
// String returns string representation of the key.
8897
func (k *Key) String() string {
89-
s := fmt.Sprintf("V%d; Query=%q; AcceptEncoding=%q; DefaultFormat=%q; Database=%q; Compress=%q; EnableHTTPCompression=%q; Namespace=%q; UserParams=%d",
90-
cacheVersion, k.Query, k.AcceptEncoding, k.DefaultFormat, k.Database, k.Compress, k.EnableHTTPCompression, k.Namespace, k.UserParamsHash)
98+
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",
99+
cacheVersion, k.Query, k.AcceptEncoding, k.DefaultFormat, k.Database, k.Compress, k.EnableHTTPCompression, k.Namespace,
100+
k.MaxResultRows, k.Extremes, k.ResultOverflowMode, k.UserParamsHash)
91101
h := sha256.Sum256([]byte(s))
92102

93103
// The first 16 bytes of the hash should be enough

cache/cache_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ func TestKeyString(t *testing.T) {
4848
key: &Key{
4949
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
5050
},
51-
expected: "b84443ea3b7651f8eed84ad70cc17d55",
51+
expected: "bebe3382e36ffdeea479b45d827b208a",
5252
},
5353
{
5454
key: &Key{
5555
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
5656
AcceptEncoding: "gzip",
5757
},
58-
expected: "baece3cc15d1aa1516e2729409ece703",
58+
expected: "498c1af30fb94280fd7c7225c0c8fb39",
5959
},
6060
{
6161
key: &Key{
6262
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
6363
AcceptEncoding: "gzip",
6464
DefaultFormat: "JSON",
6565
},
66-
expected: "c238bde938f93419e93b5b7b0341f1ef",
66+
expected: "720292aa0647cc5e53e0b6e6033eef34",
6767
},
6868
{
6969
key: &Key{
@@ -72,7 +72,7 @@ func TestKeyString(t *testing.T) {
7272
DefaultFormat: "JSON",
7373
Database: "foobar",
7474
},
75-
expected: "e55de3951f08688a34e589caaeed437f",
75+
expected: "5c6a70736d71e570faca739c4557780c",
7676
},
7777
{
7878
key: &Key{
@@ -82,7 +82,7 @@ func TestKeyString(t *testing.T) {
8282
Database: "foobar",
8383
Namespace: "ns123",
8484
},
85-
expected: "a8676b65119982a1fa135005e0583a07",
85+
expected: "08b4baf6825e53bbd18136a88abda4f8",
8686
},
8787
{
8888
key: &Key{
@@ -93,7 +93,7 @@ func TestKeyString(t *testing.T) {
9393
Compress: "1",
9494
Namespace: "ns123",
9595
},
96-
expected: "9a2ad211524d5c8983d43784fd59677d",
96+
expected: "0e043f23ccd1b9039b33623b3b7c114a",
9797
},
9898
}
9999

@@ -103,7 +103,7 @@ func TestKeyString(t *testing.T) {
103103
t.Fatalf("invalid key string format: %q", s)
104104
}
105105
if s != tc.expected {
106-
t.Fatalf("unexpected key string: %q; expecting: %q", s, tc.expected)
106+
t.Errorf("unexpected key string: %q; expecting: %q", s, tc.expected)
107107
}
108108
}
109109
}

proxy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ func (rp *reverseProxy) serveFromCache(s *scope, srw *statResponseWriter, req *h
264264
Compress: origParams.Get("compress"),
265265
EnableHTTPCompression: origParams.Get("enable_http_compression"),
266266
Namespace: origParams.Get("cache_namespace"),
267+
Extremes: origParams.Get("extremes"),
268+
MaxResultRows: origParams.Get("max_result_rows"),
269+
ResultOverflowMode: origParams.Get("result_overflow_mode"),
267270
UserParamsHash: paramsHash,
268271
}
269272

scope.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ var allowedParams = []string{
299299
"decompress",
300300
// compress the result if the client over HTTP said that it understands data compressed by gzip or deflate.
301301
"enable_http_compression",
302+
// limit on the number of rows in the result
303+
"max_result_rows",
304+
// whether to count extreme values
305+
"extremes",
306+
// what to do if the volume of the result exceeds one of the limits
307+
"result_overflow_mode",
302308
}
303309

304310
// This regexp must match params needed to describe a way to use external data

0 commit comments

Comments
 (0)