From f9ae67d1dd4473fccaa71228187176ed869f05e6 Mon Sep 17 00:00:00 2001 From: Krzysztof Kiewicz Date: Tue, 7 May 2024 19:47:45 +0200 Subject: [PATCH] Cleanup --- quesma/model/metrics_aggregations/common.go | 8 +++----- quesma/queryparser/aggregation_parser_test.go | 16 +++++++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/quesma/model/metrics_aggregations/common.go b/quesma/model/metrics_aggregations/common.go index fc75f979c..049cb32ad 100644 --- a/quesma/model/metrics_aggregations/common.go +++ b/quesma/model/metrics_aggregations/common.go @@ -2,7 +2,6 @@ package metrics_aggregations import ( "context" - "fmt" "mitmproxy/quesma/clickhouse" "mitmproxy/quesma/logger" "mitmproxy/quesma/model" @@ -19,11 +18,10 @@ func metricsTranslateSqlResponseToJson(ctx context.Context, rows []model.QueryRe }} } -// same as metricsTranslateSqlResponseToJson for all types except DateTimeType -// with DateTimes, we need to return 2 values, instead of 1. +// metricsTranslateSqlResponseToJsonWithFieldTypeCheck is the same as metricsTranslateSqlResponseToJson for all types except DateTimes. +// With DateTimes, we need to return 2 values, instead of 1, that's the difference. func metricsTranslateSqlResponseToJsonWithFieldTypeCheck( ctx context.Context, rows []model.QueryResultRow, level int, fieldType clickhouse.DateTimeType) []model.JsonMap { - fmt.Println(fieldType) if fieldType == clickhouse.Invalid { // if it's not a date, we do just a normal response return metricsTranslateSqlResponseToJson(ctx, rows, level) @@ -32,7 +30,7 @@ func metricsTranslateSqlResponseToJsonWithFieldTypeCheck( var value, valueAsString any = nil, nil if resultRowsAreFine(ctx, rows) { valueAsAny := rows[0].Cols[len(rows[0].Cols)-1].Value - if valueAsTime, isString := valueAsAny.(time.Time); isString { + if valueAsTime, ok := valueAsAny.(time.Time); ok { value = valueAsTime.UnixMilli() valueAsString = valueAsTime.Format(time.RFC3339Nano) } else { diff --git a/quesma/queryparser/aggregation_parser_test.go b/quesma/queryparser/aggregation_parser_test.go index c102df921..e6ca256ff 100644 --- a/quesma/queryparser/aggregation_parser_test.go +++ b/quesma/queryparser/aggregation_parser_test.go @@ -3,8 +3,6 @@ package queryparser import ( "cmp" "context" - "fmt" - "github.com/k0kubun/pp" "github.com/stretchr/testify/assert" "mitmproxy/quesma/clickhouse" "mitmproxy/quesma/concurrent" @@ -581,10 +579,10 @@ func Test2AggregationParserExternalTestcases(t *testing.T) { // Let's leave those commented debugs for now, they'll be useful in next PRs for j, aggregation := range aggregations { - fmt.Println("--- Aggregation "+strconv.Itoa(j)+":", aggregation) - fmt.Println() - fmt.Println("--- SQL string ", aggregation.String()) - fmt.Println() + // fmt.Println("--- Aggregation "+strconv.Itoa(j)+":", aggregation) + // fmt.Println() + // fmt.Println("--- SQL string ", aggregation.String()) + // fmt.Println() // fmt.Println("--- Group by: ", aggregation.GroupByFields) if test.ExpectedSQLs[j] != "TODO" { util.AssertSqlEqual(t, test.ExpectedSQLs[j], aggregation.String()) @@ -597,7 +595,7 @@ func Test2AggregationParserExternalTestcases(t *testing.T) { } actualAggregationsPart := cw.MakeAggregationPartOfResponse(aggregations, test.ExpectedResults) - pp.Println("ACTUAL", actualAggregationsPart) + // pp.Println("ACTUAL", actualAggregationsPart) fullResponse, err := cw.MakeResponseAggregationMarshalled(aggregations, test.ExpectedResults) assert.NoError(t, err) @@ -613,8 +611,8 @@ func Test2AggregationParserExternalTestcases(t *testing.T) { // probability and seed are present in random_sampler aggregation. I'd assume they are not needed, thus let's not care about it for now. acceptableDifference := []string{"doc_count_error_upper_bound", "sum_other_doc_count", "probability", "seed", "bg_count", "doc_count"} - pp.Println("ACTUAL", actualMinusExpected) - pp.Print("EXPECTED", expectedMinusActual) + // pp.Println("ACTUAL", actualMinusExpected) + // pp.Print("EXPECTED", expectedMinusActual) assert.True(t, util.AlmostEmpty(actualMinusExpected, acceptableDifference)) assert.True(t, util.AlmostEmpty(expectedMinusActual, acceptableDifference)) assert.Contains(t, string(fullResponse), `"value":`+strconv.FormatUint(test.ExpectedResults[0][0].Cols[0].Value.(uint64), 10)) // checks if hits nr is OK