From f7a587678e790af42286a561c29e4a57de362d7d Mon Sep 17 00:00:00 2001 From: Przemek Delewski Date: Tue, 7 May 2024 21:34:44 +0200 Subject: [PATCH] Removing ProcessHistogramQuery --- quesma/clickhouse/quesma_communicator.go | 8 ---- quesma/clickhouse/quesma_communicator_test.go | 42 ------------------- 2 files changed, 50 deletions(-) diff --git a/quesma/clickhouse/quesma_communicator.go b/quesma/clickhouse/quesma_communicator.go index 8943aa3f1..283b07f14 100644 --- a/quesma/clickhouse/quesma_communicator.go +++ b/quesma/clickhouse/quesma_communicator.go @@ -72,14 +72,6 @@ func makeBuckets(ctx context.Context, result []model.QueryResultRow, bucket time return result } -func (lm *LogManager) ProcessHistogramQuery(ctx context.Context, table *Table, query *model.Query, bucket time.Duration) ([]model.QueryResultRow, error) { - result, err := executeQuery(ctx, lm, table.Name, query.String(), []string{"key", "doc_count"}, []interface{}{int64(0), uint64(0)}) - if err != nil { - return nil, err - } - return makeBuckets(ctx, result, bucket), nil -} - // TODO add support for autocomplete for attributes, if we'll find it needed func (lm *LogManager) ProcessFacetsQuery(ctx context.Context, table *Table, query *model.Query) ([]model.QueryResultRow, error) { colNames, err := table.extractColumns(query, false) diff --git a/quesma/clickhouse/quesma_communicator_test.go b/quesma/clickhouse/quesma_communicator_test.go index 0f630a1b9..962ba40ba 100644 --- a/quesma/clickhouse/quesma_communicator_test.go +++ b/quesma/clickhouse/quesma_communicator_test.go @@ -1,51 +1,9 @@ package clickhouse import ( - "context" - "github.com/DATA-DOG/go-sqlmock" - "github.com/stretchr/testify/assert" - "mitmproxy/quesma/model" "strings" - "testing" - "time" ) -// TestProcessHistogramQuery tests if ProcessHistogramQuery returns correct results regardless of DateTime type. -func TestProcessHistogramQuery(t *testing.T) { - const timestampDividedBy30sec = 1000 - const timestampMsec = timestampDividedBy30sec * 30 * 1000 - const expectedTimestampString = "1970-01-01T08:20:00.000" - query := model.Query{ - NonSchemaFields: []string{ - "toInt64(toUnixTimestamp64Milli(`timestamp64`)/30000)", - "toInt64(toUnixTimestamp(`timestamp`)/30.0)", - "toInt64(toUnixTimestamp64Milli(`@timestamp`)/30000)", - }, - } - db, mock, _ := sqlmock.New() - defer db.Close() - lm := NewLogManagerWithConnection(db, nil) - - mock.ExpectQuery("SELECT " + escapeBrackets(strings.Join(query.NonSchemaFields, ", "))). - WillReturnRows(sqlmock.NewRows([]string{"key", "doc_count"}). - AddRow(timestampDividedBy30sec, 0). - AddRow(timestampDividedBy30sec, 10). - AddRow(timestampDividedBy30sec, 20)) - dbQueryCtx, cancel := context.WithCancel(context.Background()) - // TODO this will be used to cancel goroutine that is executing the query - _ = cancel - rows, err := lm.ProcessHistogramQuery(dbQueryCtx, &Table{Name: "foo"}, &query, 30*time.Second) - assert.NoError(t, err) - for i, row := range rows { - assert.Equal(t, int64(timestampMsec), row.Cols[model.ResultColKeyIndex].Value) - assert.Equal(t, int64(10*i), row.Cols[model.ResultColDocCountIndex].Value) - assert.Equal(t, expectedTimestampString, row.Cols[model.ResultColKeyAsStringIndex].Value) - } - if err = mock.ExpectationsWereMet(); err != nil { - t.Fatal("there were unfulfilled expections:", err) - } -} - func escapeBrackets(s string) string { s = strings.ReplaceAll(s, `(`, `\(`) s = strings.ReplaceAll(s, `)`, `\)`)