Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
trzysiek committed May 8, 2024
1 parent 7c9a8e1 commit f9ae67d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
8 changes: 3 additions & 5 deletions quesma/model/metrics_aggregations/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metrics_aggregations

import (
"context"
"fmt"
"mitmproxy/quesma/clickhouse"
"mitmproxy/quesma/logger"
"mitmproxy/quesma/model"
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
16 changes: 7 additions & 9 deletions quesma/queryparser/aggregation_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit f9ae67d

Please sign in to comment.