-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for DateTime values in metrics aggregations (#29)
`max`, `min`, and `percentiles` aggregations need separate handling for `DateTime` fields, the response is slightly different. Added that + 3 tests, one for each. Before: `percentiles` didn't work at all, `min/max` - a bit. <img width="1714" alt="Screenshot 2024-05-07 at 20 05 01" src="https://github.com/QuesmaOrg/quesma/assets/5407146/c6f67faf-2684-4234-92a5-150f8d68a4b3"> <img width="1728" alt="Screenshot 2024-05-07 at 20 04 23" src="https://github.com/QuesmaOrg/quesma/assets/5407146/a55d8449-4f9b-48a0-821d-b72de4507336"> After: <img width="1728" alt="Screenshot 2024-05-07 at 20 35 11" src="https://github.com/QuesmaOrg/quesma/assets/5407146/f2183e74-926e-48d5-914f-a1ebfc24e107"> <img width="1714" alt="Screenshot 2024-05-07 at 20 01 34" src="https://github.com/QuesmaOrg/quesma/assets/5407146/73805381-310b-4481-8097-d672c290e9b6"> <img width="1720" alt="Screenshot 2024-05-07 at 20 01 45" src="https://github.com/QuesmaOrg/quesma/assets/5407146/99f3669d-936c-4926-99f3-71bbba308a7b">
- Loading branch information
Showing
15 changed files
with
797 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package metrics_aggregations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math" | ||
"mitmproxy/quesma/clickhouse" | ||
"mitmproxy/quesma/util" | ||
"strconv" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func equalFloats(a, b float64) bool { | ||
if math.IsNaN(a) && math.IsNaN(b) { | ||
return true | ||
} | ||
return math.Abs(a-b) < 1e-9 | ||
} | ||
|
||
func equalStrings(a, b *string) bool { | ||
if a == nil && b == nil { | ||
return true | ||
} | ||
if a == nil || b == nil { | ||
return false | ||
} | ||
return *a == *b | ||
} | ||
|
||
func Test_processResult(t *testing.T) { | ||
a := time.Now() | ||
fmt.Println(a.Format(time.RFC3339)) | ||
quantile := NewQuantile(context.Background(), false, clickhouse.DateTime) | ||
colName := "not-important" | ||
wantedStr := "2024-05-02T21:58:16.297Z" | ||
tests := []struct { | ||
percentileReturnedByClickhouse any | ||
wantedPercentile float64 | ||
wantedPercentileAsString *string | ||
}{ | ||
{nil, math.NaN(), nil}, | ||
{"", math.NaN(), nil}, | ||
{"0", math.NaN(), nil}, | ||
{0, math.NaN(), nil}, | ||
{0.0, math.NaN(), nil}, | ||
{[]string{"1.0"}, math.NaN(), nil}, | ||
{[]string{"1.0", "5"}, math.NaN(), nil}, | ||
{[]any{"1.0", "5"}, math.NaN(), nil}, | ||
{[]any{"1.0", "5"}, math.NaN(), nil}, | ||
{[]int{1}, math.NaN(), nil}, | ||
{[]int{}, math.NaN(), nil}, | ||
{[]float64{}, math.NaN(), nil}, | ||
{[]float64{1.0}, 1.0, nil}, | ||
{[]float64{1.0, 2.0}, 1.0, nil}, | ||
{[]any{float64(1.0), 5}, 1.0, nil}, | ||
{[]any{5, float64(1.0)}, math.NaN(), nil}, | ||
{[]time.Time{util.ParseTime("2024-05-02T21:58:16.297Z"), util.ParseTime("5")}, 1714687096297.0, &wantedStr}, | ||
{[]time.Time{util.ParseTime("2024-05-02T21:58:16.297Z")}, 1714687096297.0, &wantedStr}, | ||
{[]any{util.ParseTime("2024-05-02T21:58:16.297Z"), 5, 10, 5.2}, 1714687096297.0, &wantedStr}, | ||
{[]any{util.ParseTime("2024-05-02T21:58:16.297Z")}, 1714687096297.0, &wantedStr}, | ||
} | ||
for i, tt := range tests { | ||
t.Run("testing processResult"+strconv.Itoa(i), func(t *testing.T) { | ||
percentile, percentileAsString, _ := quantile.processResult(colName, tt.percentileReturnedByClickhouse) | ||
if !equalFloats(percentile, tt.wantedPercentile) { | ||
t.Errorf("got %v, wanted %v", percentile, tt.wantedPercentile) | ||
} | ||
if !equalStrings(percentileAsString, tt.wantedPercentileAsString) { | ||
t.Errorf("got %v, wanted %v", percentileAsString, tt.wantedPercentileAsString) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.