From 8d07e838947d97c2a9f75ed396657a7470fc4db2 Mon Sep 17 00:00:00 2001 From: hagen1778 Date: Tue, 18 Sep 2018 18:22:46 +0300 Subject: [PATCH 1/2] allow to pass max_results_row, extremes and result_overflow_mode params --- cache/cache.go | 14 ++++++++++++-- cache/cache_test.go | 14 +++++++------- proxy.go | 3 +++ scope.go | 6 ++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 79ffec7b..d22a1b9e 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -80,14 +80,24 @@ type Key struct { // Namespace is an optional cache namespace. Namespace string + // MaxResultRows must contain `max_result_rows` query arg + MaxResultRows string + + // Extremes must contain `extremes` query arg + Extremes string + + // ResultOverflowMode must contain `result_overflow_mode` query arg + ResultOverflowMode string + // UserParamsHash must contain hashed value of users params UserParamsHash uint32 } // String returns string representation of the key. func (k *Key) String() string { - s := fmt.Sprintf("V%d; Query=%q; AcceptEncoding=%q; DefaultFormat=%q; Database=%q; Compress=%q; EnableHTTPCompression=%q; Namespace=%q; UserParams=%d", - cacheVersion, k.Query, k.AcceptEncoding, k.DefaultFormat, k.Database, k.Compress, k.EnableHTTPCompression, k.Namespace, k.UserParamsHash) + 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", + cacheVersion, k.Query, k.AcceptEncoding, k.DefaultFormat, k.Database, k.Compress, k.EnableHTTPCompression, k.Namespace, + k.MaxResultRows, k.Extremes, k.ResultOverflowMode, k.UserParamsHash) h := sha256.Sum256([]byte(s)) // The first 16 bytes of the hash should be enough diff --git a/cache/cache_test.go b/cache/cache_test.go index 75cb598d..b8df5727 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -48,14 +48,14 @@ func TestKeyString(t *testing.T) { key: &Key{ Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"), }, - expected: "b84443ea3b7651f8eed84ad70cc17d55", + expected: "bebe3382e36ffdeea479b45d827b208a", }, { key: &Key{ Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"), AcceptEncoding: "gzip", }, - expected: "baece3cc15d1aa1516e2729409ece703", + expected: "498c1af30fb94280fd7c7225c0c8fb39", }, { key: &Key{ @@ -63,7 +63,7 @@ func TestKeyString(t *testing.T) { AcceptEncoding: "gzip", DefaultFormat: "JSON", }, - expected: "c238bde938f93419e93b5b7b0341f1ef", + expected: "720292aa0647cc5e53e0b6e6033eef34", }, { key: &Key{ @@ -72,7 +72,7 @@ func TestKeyString(t *testing.T) { DefaultFormat: "JSON", Database: "foobar", }, - expected: "e55de3951f08688a34e589caaeed437f", + expected: "5c6a70736d71e570faca739c4557780c", }, { key: &Key{ @@ -82,7 +82,7 @@ func TestKeyString(t *testing.T) { Database: "foobar", Namespace: "ns123", }, - expected: "a8676b65119982a1fa135005e0583a07", + expected: "08b4baf6825e53bbd18136a88abda4f8", }, { key: &Key{ @@ -93,7 +93,7 @@ func TestKeyString(t *testing.T) { Compress: "1", Namespace: "ns123", }, - expected: "9a2ad211524d5c8983d43784fd59677d", + expected: "0e043f23ccd1b9039b33623b3b7c114a", }, } @@ -103,7 +103,7 @@ func TestKeyString(t *testing.T) { t.Fatalf("invalid key string format: %q", s) } if s != tc.expected { - t.Fatalf("unexpected key string: %q; expecting: %q", s, tc.expected) + t.Errorf("unexpected key string: %q; expecting: %q", s, tc.expected) } } } diff --git a/proxy.go b/proxy.go index 6d775fc3..9ce26dbf 100644 --- a/proxy.go +++ b/proxy.go @@ -264,6 +264,9 @@ func (rp *reverseProxy) serveFromCache(s *scope, srw *statResponseWriter, req *h Compress: origParams.Get("compress"), EnableHTTPCompression: origParams.Get("enable_http_compression"), Namespace: origParams.Get("cache_namespace"), + Extremes: origParams.Get("extremes"), + MaxResultRows: origParams.Get("max_result_rows"), + ResultOverflowMode: origParams.Get("result_overflow_mode"), UserParamsHash: paramsHash, } diff --git a/scope.go b/scope.go index 6936e40f..434f40b5 100644 --- a/scope.go +++ b/scope.go @@ -299,6 +299,12 @@ var allowedParams = []string{ "decompress", // compress the result if the client over HTTP said that it understands data compressed by gzip or deflate. "enable_http_compression", + // limit on the number of rows in the result + "max_result_rows", + // whether to count extreme values + "extremes", + // what to do if the volume of the result exceeds one of the limits + "result_overflow_mode", } // This regexp must match params needed to describe a way to use external data From 29b379d78271f4eccb41e12329ee4661cf2b9412 Mon Sep 17 00:00:00 2001 From: hagen1778 Date: Tue, 18 Sep 2018 23:34:03 +0300 Subject: [PATCH 2/2] fix debug typo --- cache/cache_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache/cache_test.go b/cache/cache_test.go index b8df5727..23ec986e 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -103,7 +103,7 @@ func TestKeyString(t *testing.T) { t.Fatalf("invalid key string format: %q", s) } if s != tc.expected { - t.Errorf("unexpected key string: %q; expecting: %q", s, tc.expected) + t.Fatalf("unexpected key string: %q; expecting: %q", s, tc.expected) } } }