( ctx context.Context, attrKey string, f *AttrFilter, )
| 232 | } |
| 233 | |
| 234 | func (h *AttrHandler) selectAttrValues( |
| 235 | ctx context.Context, attrKey string, f *AttrFilter, |
| 236 | ) (any, bool, error) { |
| 237 | const limit = 1000 |
| 238 | |
| 239 | if len(f.Metric) == 1 { |
| 240 | switch f.Metric[0] { |
| 241 | case uptraceTracingSpans, uptraceTracingEvents, uptraceTracingLogs: |
| 242 | typeFilter, err := newTypeFilter(ctx, f.ProjectID, &f.TimeFilter, f.Metric[0]) |
| 243 | if err != nil { |
| 244 | return nil, false, err |
| 245 | } |
| 246 | |
| 247 | spanFilter := newSpanFilter(typeFilter, "") |
| 248 | return tracing.SelectAttrValues(ctx, h.CH, spanFilter, attrKey) |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | tableName := DatapointTableForWhere(&f.TimeFilter) |
| 253 | items := make([]AttrValueItem, 0) |
| 254 | |
| 255 | if err := h.CH.NewSelect(). |
| 256 | ColumnExpr("? AS value", chAttrExpr(attrKey)). |
| 257 | ColumnExpr("count(DISTINCT metric) AS count"). |
| 258 | TableExpr("? AS d", ch.Name(tableName)). |
| 259 | Where("d.project_id = ?", f.ProjectID). |
| 260 | Where("d.time >= ?", f.TimeGTE). |
| 261 | Where("d.time < ?", f.TimeLT). |
| 262 | Apply(func(q *ch.SelectQuery) *ch.SelectQuery { |
| 263 | if len(f.Metric) > 0 { |
| 264 | q = q.Where("d.metric IN ?", ch.In(f.Metric)) |
| 265 | } |
| 266 | if !isMandatoryAttr(attrKey) { |
| 267 | q = q.Where("has(d.string_keys, ?)", attrKey) |
| 268 | } |
| 269 | |
| 270 | for _, attrKey := range f.AttrKey { |
| 271 | if isMandatoryAttr(attrKey) { |
| 272 | continue |
| 273 | } |
| 274 | q = q.Where("has(d.string_keys, ?)", attrKey) |
| 275 | } |
| 276 | if len(f.Instrument) > 0 { |
| 277 | q = q.Where("d.instrument IN ?", ch.In(f.Instrument)) |
| 278 | } |
| 279 | if len(f.OtelLibraryName) > 0 { |
| 280 | q = q.Where("d.otel_library_name IN ?", ch.In(f.OtelLibraryName)) |
| 281 | } |
| 282 | |
| 283 | if f.SearchInput != "" { |
| 284 | q = q.Where("? like ?", chAttrExpr(attrKey), "%"+f.SearchInput+"%") |
| 285 | } |
| 286 | |
| 287 | return q |
| 288 | }). |
| 289 | GroupExpr("value"). |
| 290 | OrderExpr("value ASC"). |
| 291 | Limit(limit). |
no test coverage detected