Skip to content

Commit

Permalink
Removing ProcessHistogramQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelewski committed May 7, 2024
1 parent 2de9dbd commit f7a5876
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 50 deletions.
8 changes: 0 additions & 8 deletions quesma/clickhouse/quesma_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 0 additions & 42 deletions quesma/clickhouse/quesma_communicator_test.go
Original file line number Diff line number Diff line change
@@ -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, `)`, `\)`)
Expand Down

0 comments on commit f7a5876

Please sign in to comment.