Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix count (quick) #812

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions quesma/queryparser/query_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"quesma/quesma/config"
"quesma/schema"
"quesma/util"
"strings"
)

type JsonMap = map[string]interface{}
Expand Down Expand Up @@ -178,44 +177,19 @@ func (cw *ClickhouseQueryTranslator) makeTotalCount(queries []*model.Query, resu
if len(results[queryIdx]) == 0 {
continue
}
totalCount = 0
for rowIdx, row := range results[queryIdx] {
// sum over all rows
if len(row.Cols) == 0 {
continue
}

// if group by key exists + it's the same as last, we have already counted it and need to continue
newKey := true
if rowIdx != 0 { // for first row we always have a new key
for colIdx, cell := range row.Cols {
// find first group by key
if strings.HasSuffix(cell.ColName, "__key_0") {
if row.Cols[colIdx].Value == results[queryIdx][rowIdx-1].Cols[colIdx].Value {
newKey = false
}
break
}
}
}
if !newKey {
continue
}

// find the count column
for _, cell := range row.Cols {
// FIXME THIS is hardcoded for now, as we don't have a way to get the name of the column
if cell.ColName == "metric____quesma_total_count_col_0" {
switch v := cell.Value.(type) {
case uint64:
totalCount += int(v)
case int:
totalCount += v
case int64:
totalCount += int(v)
default:
logger.ErrorWithCtx(cw.Ctx).Msgf("Unknown type of count %v %t", v, v)
}
firstRow := results[queryIdx][0]
nablaone marked this conversation as resolved.
Show resolved Hide resolved
for _, cell := range firstRow.Cols {
// FIXME THIS is hardcoded for now, as we don't have a way to get the name of the column
if cell.ColName == "metric____quesma_total_count_col_0" {
switch v := cell.Value.(type) {
case uint64:
totalCount = int(v)
case int:
totalCount = v
case int64:
totalCount = int(v)
default:
logger.ErrorWithCtx(cw.Ctx).Msgf("Unknown type of count %v %t", v, v)
}
}
}
Expand Down
Loading