visibility_store.go ×17

Frontier kind: Joint frontier

unlabeled · c_5ac37b5af286

4 tests · 2313 LOC · 96 files · introduces 1 test · 92 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges92 lines · 2 files
Tests
1 test

Contains — complete concept membership

All code (extent)
396 ranges2313 lines · 96 files · Browse complete extent
All tests (intent)
4 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

1 test introduced at this concept.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 92 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/visibility/store/elasticsearch/visibility_store.go 81 introduced LOC · 17 ranges

Open complete file

502 queryParams *esQueryParams,
503 chasmMapper *chasm.VisibilitySearchAttributesMapper,
504 > ) (*store.InternalCountExecutionsResponse, error) { visibility_store.go
505 > groupByFields := queryParams.GroupBy
506 >
507 > // Elasticsearch aggregation is nested. so need to loop backwards to build it.
508 > // Example: when grouping by (field1, field2), the object looks like
509 > // {
510 > // "aggs": {
511 > // "field1": {
512 > // "terms": {
513 > // "field": "field1"
514 > // },
515 > // "aggs": {
516 > // "field2": {
517 > // "terms": {
518 > // "field": "field2"
519 > // }
520 > // }
521 > // }
522 > // }
523 > // }
524 > // }
525 > termsAgg := elastic.NewTermsAggregation().Field(groupByFields[len(groupByFields)-1])
526 > for i := len(groupByFields) - 2; i >= 0; i-- {
527 termsAgg = elastic.NewTermsAggregation().
528 Field(groupByFields[i]).
529 SubAggregation(groupByFields[i+1], termsAgg)
530 }
531 > esResponse, err := s.esClient.CountGroupBy( visibility_store.go
532 > ctx,
533 > s.index,
534 > queryParams.Query,
535 > groupByFields[0],
536 > termsAgg,
537 > )
538 > if err != nil {
539 return nil, ConvertElasticsearchClientError("CountWorkflowExecutions failed", err, s.logger)
540 }
541 > return s.parseCountGroupByResponse(esResponse, groupByFields, chasmMapper) visibility_store.go
542 }
543
1152 groupByFields []string,
1153 chasmMapper *chasm.VisibilitySearchAttributesMapper,
1154 > ) (*store.InternalCountExecutionsResponse, error) { visibility_store.go
1155 > response := &store.InternalCountExecutionsResponse{}
1156 > saTypeMap, err := s.searchAttributesProvider.GetSearchAttributes(s.index, false)
1157 > if err != nil {
1158 return nil, serviceerror.NewUnavailablef(
1159 "unable to read search attribute types: %v", err,
1161 }
1162
1163 > combinedTypeMap := store.CombineTypeMaps(saTypeMap, chasmMapper) visibility_store.go
1164 >
1165 > groupByTypes := make([]enumspb.IndexedValueType, len(groupByFields))
1166 > for i, saName := range groupByFields {
1167 > tp, err := combinedTypeMap.GetType(saName)
1168 > if err != nil {
1169 return nil, err
1170 }
1171 > groupByTypes[i] = tp visibility_store.go
1172 }
1173
1174 > parseJsonNumber := func(val any) (int64, error) { visibility_store.go
1175 > numberVal, isNumber := val.(json.Number)
1176 > if !isNumber {
1177 return 0, fmt.Errorf("%w: expected json.Number, got %T", errUnexpectedJSONFieldType, val)
1178 }
1179 > return numberVal.Int64() visibility_store.go
1180 }
1181
1182 > var parseInternal func(map[string]any, []*commonpb.Payload) error visibility_store.go
1183 > parseInternal = func(aggs map[string]any, bucketValues []*commonpb.Payload) error {
1184 > if len(bucketValues) == len(groupByFields) {
1185 > cnt, err := parseJsonNumber(aggs["doc_count"])
1186 > if err != nil {
1187 return fmt.Errorf("unable to parse 'doc_count' field: %w", err)
1188 }
1189 > groupValues := make([]*commonpb.Payload, len(groupByFields)) visibility_store.go
1190 > copy(groupValues, bucketValues)
1191 > response.Groups = append(
1192 > response.Groups,
1193 > store.InternalAggregationGroup{
1194 > GroupValues: groupValues,
1195 > Count: cnt,
1196 > },
1197 > )
1198 > response.Count += cnt
1199 > return nil
1200 }
1201
1202 > index := len(bucketValues) visibility_store.go
1203 > fieldName := groupByFields[index]
1204 > buckets := aggs[fieldName].(map[string]any)["buckets"].([]any)
1205 > for i := range buckets {
1206 > bucket := buckets[i].(map[string]any)
1207 > value, err := finishParseJSONValue(bucket["key"], groupByTypes[index])
1208 > if err != nil {
1209 return fmt.Errorf("unable to parse value %v: %w", bucket["key"], err)
1210 }
1211 > payload, err := sadefs.EncodeValue(value, groupByTypes[index]) visibility_store.go
1212 > if err != nil {
1213 return fmt.Errorf("unable to encode value %v: %w", value, err)
1214 }
1215 > err = parseInternal(bucket, append(bucketValues, payload)) visibility_store.go
1216 > if err != nil {
1217 return err
1218 }
1219 }
1220 > return nil visibility_store.go
1221 }
1222
1223 > var bucketsJson map[string]any visibility_store.go
1224 > dec := json.NewDecoder(bytes.NewReader(searchResult.Aggregations[groupByFields[0]]))
1225 > dec.UseNumber()
1226 > if err := dec.Decode(&bucketsJson); err != nil {
1227 return nil, serviceerror.NewInternalf("unable to unmarshal json response: %v", err)
1228 }
1229 > if err := parseInternal(map[string]any{groupByFields[0]: bucketsJson}, nil); err != nil { visibility_store.go
1230 return nil, err
1231 }
1232 > return response, nil visibility_store.go
1233 }
1234
go.temporal.io/server/common/persistence/visibility/store/elasticsearch/client/client_mock.go 11 introduced LOC · 2 ranges

Open complete file

74
75 // CountGroupBy mocks base method.
76 > func (m *MockClient) CountGroupBy(ctx context.Context, index string, query elastic.Query, aggName string, agg elastic.Aggregation) (*elastic.SearchResult, error) { client_mock.go
77 > m.ctrl.T.Helper()
78 > ret := m.ctrl.Call(m, "CountGroupBy", ctx, index, query, aggName, agg)
79 > ret0, _ := ret[0].(*elastic.SearchResult)
80 > ret1, _ := ret[1].(error)
81 > return ret0, ret1
82 > }
83
84 // CountGroupBy indicates an expected call of CountGroupBy.
85 > func (mr *MockClientMockRecorder) CountGroupBy(ctx, index, query, aggName, agg any) *gomock.Call { client_mock.go
86 > mr.mock.ctrl.T.Helper()
87 > return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CountGroupBy", reflect.TypeOf((*MockClient)(nil).CountGroupBy), ctx, index, query, aggName, agg)
88 > }
89
90 // CreateIndex mocks base method.