Skip to content

Commit

Permalink
Fix size parsing (#961)
Browse files Browse the repository at this point in the history
#949 fixed size parsing for
aggregations, but it can as well appear in top-level query part.
  • Loading branch information
mieciu authored Nov 7, 2024
1 parent 30be815 commit 3835d60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
16 changes: 6 additions & 10 deletions quesma/queryparser/query_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func NewEmptyHighlighter() model.Highlighter {
}
}

const (
defaultQueryResultSize = 10
defaultTrackTotalHits = 10000
)

func (cw *ClickhouseQueryTranslator) ParseQuery(body types.JSON) (*model.ExecutionPlan, error) {

simpleQuery, hitsInfo, highlighter, err := cw.parseQueryInternal(body)
Expand Down Expand Up @@ -148,17 +153,8 @@ func (cw *ClickhouseQueryTranslator) parseQueryInternal(body types.JSON) (*model
if sortPart, ok := queryAsMap["sort"]; ok {
parsedQuery.OrderBy = cw.parseSortFields(sortPart)
}
const defaultSize = 10
size := defaultSize
if sizeRaw, ok := queryAsMap["size"]; ok {
if sizeFloat, ok := sizeRaw.(float64); ok {
size = int(sizeFloat)
} else {
logger.WarnWithCtx(cw.Ctx).Msgf("unknown size format, size value: %v type: %T. Using default (%d)", sizeRaw, sizeRaw, defaultSize)
}
}
size := cw.parseSize(queryAsMap, defaultQueryResultSize)

const defaultTrackTotalHits = 10000
trackTotalHits := defaultTrackTotalHits
if trackTotalHitsRaw, ok := queryAsMap["track_total_hits"]; ok {
switch trackTotalHitsTyped := trackTotalHitsRaw.(type) {
Expand Down
24 changes: 17 additions & 7 deletions quesma/quesma/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,11 @@ func (c *QuesmaConfiguration) optimizersConfigAsString(s string, cfg map[string]
func (c *QuesmaConfiguration) OptimizersConfigAsString() string {

var lines []string

lines = append(lines, "\n")

for indexName, indexConfig := range c.IndexConfig {
if len(indexConfig.Optimizers) > 0 {
lines = append(lines, c.optimizersConfigAsString(indexName, indexConfig.Optimizers))
}
}

lines = append(lines, "\n")
return strings.Join(lines, "\n")
}

Expand Down Expand Up @@ -253,8 +248,16 @@ Quesma Configuration:
Log Level: %v
Public TCP Port: %d
Ingest Statistics: %t,
Quesma Telemetry URL: %s
Optimizers: %s`,
Quesma Telemetry URL: %s,
Optimizers: %s,
DisableAuth: %t,
AutodiscoveryEnabled: %t,
EnableIngest: %t,
CreateCommonTable: %t,
UseCommonTableForWildcard: %t,
DefaultIngestTarget: %v,
DefaultQueryTarget: %v,
`,
c.TransparentProxy,
elasticUrl,
elasticsearchExtra,
Expand All @@ -268,6 +271,13 @@ Quesma Configuration:
c.IngestStatistics,
quesmaInternalTelemetryUrl,
c.OptimizersConfigAsString(),
c.DisableAuth,
c.AutodiscoveryEnabled,
c.EnableIngest,
c.CreateCommonTable,
c.UseCommonTableForWildcard,
c.DefaultIngestTarget,
c.DefaultQueryTarget,
)
}

Expand Down
2 changes: 1 addition & 1 deletion quesma/testdata/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var TestsAsyncSearch = []AsyncSearchTestCase{
}
},
"runtime_mappings": {},
"size": 0,
"size": "0",
"track_total_hits": false
}`,
`{
Expand Down

0 comments on commit 3835d60

Please sign in to comment.