visibility_store.go ×11

Frontier kind: Code frontier

unlabeled · c_93455477bbfa

5 tests · 4333 LOC · 188 files · introduces 0 tests · 134 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
22 ranges134 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
773 ranges4333 lines · 188 files · Browse complete extent
All tests (intent)
5 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.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

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

4 files ranked by introduced lines: 134 introduced LOC across 22 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/tests/visibility_persistence_suite.go 58 introduced LOC · 3 ranges

Open complete file

995 }
996
997 > func (s *VisibilityPersistenceSuite) TestCountGroupByWorkflowExecutions() { visibility_persistence_suite.go
998 > testNamespaceUUID := namespace.ID(uuid.NewString())
999 > closeTime := time.Now().UTC()
1000 > startTime := closeTime.Add(-5 * time.Second)
1001 >
1002 > var startRequests []*manager.RecordWorkflowExecutionStartedRequest
1003 > for range 5 {
1004 > startRequests = append(
1005 > startRequests,
1006 > s.createOpenWorkflowRecord(
1007 > testNamespaceUUID,
1008 > "visibility-workflow-test",
1009 > "visibility-workflow",
1010 > startTime,
1011 > startTime,
1012 > "test-queue",
1013 > ),
1014 > )
1015 > }
1016
1017 > runningStatusPayload, _ := sadefs.EncodeValue( visibility_persistence_suite.go
1018 > enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING.String(),
1019 > enumspb.INDEXED_VALUE_TYPE_KEYWORD,
1020 > )
1021 > resp, err := s.VisibilityMgr.CountWorkflowExecutions(
1022 > s.ctx,
1023 > &manager.CountWorkflowExecutionsRequest{
1024 > NamespaceID: testNamespaceUUID,
1025 > Query: "GROUP BY ExecutionStatus",
1026 > },
1027 > )
1028 > s.NoError(err)
1029 > s.Equal(int64(5), resp.Count)
1030 > s.Equal(
1031 > []*workflowservice.CountWorkflowExecutionsResponse_AggregationGroup{
1032 > {
1033 > GroupValues: []*commonpb.Payload{runningStatusPayload},
1034 > Count: int64(5),
1035 > },
1036 > },
1037 > resp.Groups,
1038 > )
1039 >
1040 > for i := range 2 {
1041 > s.createClosedWorkflowRecord(
1042 > startRequests[i],
1043 > closeTime,
1044 > enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
1045 > )
1046 > }
1047
1048 > resp, err = s.VisibilityMgr.CountWorkflowExecutions( visibility_persistence_suite.go
1049 > s.ctx,
1050 > &manager.CountWorkflowExecutionsRequest{
1051 > NamespaceID: testNamespaceUUID,
1052 > Query: "GROUP BY ExecutionStatus",
1053 > },
1054 > )
1055 > s.NoError(err)
1056 > s.Equal(int64(5), resp.Count)
1057 }
1058
go.temporal.io/server/common/persistence/visibility/store/sql/visibility_store.go 38 introduced LOC · 11 ranges

Open complete file

637
638 if len(selectFilter.GroupBy) > 0 {
639 > return s.countGroupByExecutions(ctx, selectFilter, nil) visibility_store.go
640 > }
641
642 count, err := s.sqlStore.DB.CountFromVisibility(ctx, *selectFilter)
653 fieldNames []string,
654 chasmMapper *chasm.VisibilitySearchAttributesMapper,
655 > ) ([]enumspb.IndexedValueType, error) { visibility_store.go
656 > saTypeMap, err := s.searchAttributesProvider.GetSearchAttributes(s.GetIndexName(), false)
657 > if err != nil {
658 return nil, serviceerror.NewUnavailablef(
659 "unable to read search attribute types: %v", err,
661 }
662
663 > combinedTypeMap := store.CombineTypeMaps(saTypeMap, chasmMapper) visibility_store.go
664 >
665 > groupByTypes := make([]enumspb.IndexedValueType, len(fieldNames))
666 > for i, fieldName := range fieldNames {
667 > tp, err := combinedTypeMap.GetType(fieldName)
668 > if err != nil {
669 return nil, err
670 }
671 > groupByTypes[i] = tp visibility_store.go
672 }
673
674 > return groupByTypes, nil visibility_store.go
675 }
676
682 groupBy := make([]string, 0, len(queryParams.GroupBy)+1)
683 for _, field := range queryParams.GroupBy {
684 > groupBy = append(groupBy, field.FieldName) visibility_store.go
685 > }
686
687 return &sqlplugin.VisibilitySelectFilter{
696 selectFilter *sqlplugin.VisibilitySelectFilter,
697 chasmMapper *chasm.VisibilitySearchAttributesMapper,
698 > ) (*store.InternalCountExecutionsResponse, error) { visibility_store.go
699 > rows, err := s.sqlStore.DB.CountGroupByFromVisibility(ctx, *selectFilter)
700 > if err != nil {
701 return nil, convertSQLError("CountExecutions operation failed.", err)
702 }
703
704 > groupByTypes, err := s.getGroupByFieldTypes(selectFilter.GroupBy, chasmMapper) visibility_store.go
705 > if err != nil {
706 return nil, err
707 }
708
709 > resp := &store.InternalCountExecutionsResponse{ visibility_store.go
710 > Count: 0,
711 > Groups: make([]store.InternalAggregationGroup, 0, len(rows)),
712 > }
713 > for _, row := range rows {
714 > groupValues := make([]*commonpb.Payload, len(row.GroupValues))
715 > for i, val := range row.GroupValues {
716 > groupValues[i], err = sadefs.EncodeValue(val, groupByTypes[i])
717 > if err != nil {
718 return nil, err
719 }
720 }
721 > resp.Groups = append( visibility_store.go
722 > resp.Groups,
723 > store.InternalAggregationGroup{
724 > GroupValues: groupValues,
725 > Count: row.Count,
726 > },
727 > )
728 > resp.Count += row.Count
729 }
730 > return resp, nil visibility_store.go
731 }
732
go.temporal.io/server/common/persistence/sql/sqlplugin/visibility.go 31 introduced LOC · 7 ranges

Open complete file

147 }
148
149 > func ParseCountGroupByRows(rows dbRowsIf, groupBy []string) ([]VisibilityCountRow, error) { visibility.go
150 > // Number of columns is number of group by fields plus the count column.
151 > rowValues := make([]any, len(groupBy)+1)
152 > for i := range rowValues {
153 > rowValues[i] = new(any)
154 > }
155
156 > var res []VisibilityCountRow visibility.go
157 > for rows.Next() {
158 > err := rows.Scan(rowValues...)
159 > if err != nil {
160 return nil, err
161 }
162 > groupValues := make([]any, len(groupBy)) visibility.go
163 > for i := range groupBy {
164 > groupValues[i], err = parseCountGroupByGroupValue(groupBy[i], *(rowValues[i].(*any)))
165 > if err != nil {
166 return nil, err
167 }
168 }
169 > var countTyped int64 visibility.go
170 > countValue := reflect.ValueOf(*(rowValues[len(rowValues)-1].(*any)))
171 > if countValue.CanInt() {
172 > countTyped = countValue.Int()
173 > } else if countValue.CanUint() {
174 countTyped = int64(countValue.Uint())
175 } else {
183 )
184 }
185 > res = append(res, VisibilityCountRow{ visibility.go
186 > GroupValues: groupValues,
187 > Count: countTyped,
188 > })
189 }
190 > return res, nil visibility.go
191 }
192
193 > func parseCountGroupByGroupValue(fieldName string, value any) (any, error) { visibility.go
194 > switch fieldName {
195 > case sadefs.ExecutionStatus:
196 > v := reflect.ValueOf(value)
197 > if v.CanInt() {
198 > return enumspb.WorkflowExecutionStatus(v.Int()).String(), nil
199 > }
200 if v.CanUint() {
201 return enumspb.WorkflowExecutionStatus(v.Uint()).String(), nil
go.temporal.io/server/common/persistence/visibility/visibility_manager_impl.go 7 introduced LOC · 1 range

Open complete file

359
360 if len(internal.Groups) > 0 {
361 > response.Groups = make([]*workflowservice.CountWorkflowExecutionsResponse_AggregationGroup, 0, len(internal.Groups)) visibility_manager_impl.go
362 > for _, group := range internal.Groups {
363 > response.Groups = append(response.Groups, &workflowservice.CountWorkflowExecutionsResponse_AggregationGroup{
364 > GroupValues: group.GroupValues,
365 > Count: group.Count,
366 > })
367 > }
368 }
369