From 772cba1d01cfb3ce3140e5f099103b915169276d Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Tue, 20 Aug 2024 20:47:21 -0400 Subject: [PATCH] api: test_details with correct querying for cross-variant --- pkg/api/componentreadiness/test_details.go | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkg/api/componentreadiness/test_details.go b/pkg/api/componentreadiness/test_details.go index 9f8152247..1698ed5fb 100644 --- a/pkg/api/componentreadiness/test_details.go +++ b/pkg/api/componentreadiness/test_details.go @@ -139,9 +139,34 @@ func (c *componentReportGenerator) getTestDetailsQuery(allJobVariants crtype.Job for group, variant := range c.RequestedVariants { queryString += fmt.Sprintf(` AND jv_%s.variant_value = '%s'`, api.CleanseSqlName(group), api.CleanseSqlName(variant)) } + if isSample { + queryString += filterByCrossCompareVariants(c.VariantCrossCompare, c.CompareVariants, &commonParams) + } else { + queryString += filterByCrossCompareVariants(c.VariantCrossCompare, c.IncludeVariants, &commonParams) + } return queryString, groupString, commonParams } +// filterByCrossCompareVariants adds the where clause for any variants being cross-compared (which are not included in RequiredVariants). +// As a side effect, it also appends any necessary parameters for the clause. +func filterByCrossCompareVariants(crossCompare []string, variantGroups map[string][]string, params *[]bigquery2.QueryParameter) (whereClause string) { + if len(variantGroups) == 0 { + return // avoid possible nil pointer dereference + } + for _, group := range crossCompare { + if variants := variantGroups[group]; len(variants) > 0 { + group = api.CleanseSqlName(group) + paramName := "CrossVariants" + group + whereClause += fmt.Sprintf(` AND jv_%s.variant_value IN UNNEST(@%s)`, group, paramName) + *params = append(*params, bigquery2.QueryParameter{ + Name: paramName, + Value: variants, + }) + } + } + return +} + type baseJobRunTestStatusGenerator struct { commonQuery string groupByQuery string