Skip to content

Commit 2c95ee3

Browse files
committed
feat(catalog): substitute min/max values for named queries
Replace "min"/"max" string placeholders in named queries with actual numeric minimum/maximum values from filter options. Signed-off-by: Paul Boyd <[email protected]>
1 parent 4b991e7 commit 2c95ee3

File tree

2 files changed

+411
-5
lines changed

2 files changed

+411
-5
lines changed

catalog/internal/catalog/db_catalog.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (d *dbCatalogImpl) GetFilterOptions(ctx context.Context) (*apimodels.Filter
252252
Value: filter.Value,
253253
}
254254
}
255+
d.applyMinMax(apiFieldFilters, options)
255256
apiNamedQueries[queryName] = apiFieldFilters
256257
}
257258

@@ -266,6 +267,37 @@ func (d *dbCatalogImpl) GetFilterOptions(ctx context.Context) (*apimodels.Filter
266267
}, nil
267268
}
268269

270+
func (d *dbCatalogImpl) applyMinMax(query map[string]apimodels.FieldFilter, options map[string]apimodels.FilterOption) {
271+
// Find queries where the value is min or max and replace it with the
272+
// actual min or max from the filter options.
273+
for key, filter := range query {
274+
// Find string values that are either min or max
275+
value, ok := filter.Value.(string)
276+
if !ok || (value != "min" && value != "max") {
277+
continue
278+
}
279+
280+
option, ok := options[key]
281+
if !ok || option.Range == nil {
282+
// Skip fields without a corresponding option or options without a range.
283+
continue
284+
}
285+
286+
switch value {
287+
case "min":
288+
if option.Range.Min != nil {
289+
filter.Value = *option.Range.Min
290+
}
291+
case "max":
292+
if option.Range.Max != nil {
293+
filter.Value = *option.Range.Max
294+
}
295+
}
296+
297+
query[key] = filter
298+
}
299+
}
300+
269301
func (d *dbCatalogImpl) GetPerformanceArtifacts(ctx context.Context, modelName string, sourceID string, params ListPerformanceArtifactsParams) (apimodels.CatalogArtifactList, error) {
270302
// Get the model to validate it exists and get its ID
271303
modelsList, err := d.catalogModelRepository.List(dbmodels.CatalogModelListOptions{

0 commit comments

Comments
 (0)