MCPcopy Create free account
hub / github.com/temporalio/temporal / ParseCountGroupByRows

Function ParseCountGroupByRows

common/persistence/sql/sqlplugin/visibility.go:149–191  ·  view source on GitHub ↗
(rows dbRowsIf, groupBy []string)

Source from the content-addressed store, hash-verified

147}
148
149func ParseCountGroupByRows(rows dbRowsIf, groupBy []string) ([]VisibilityCountRow, error) {
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
157 for rows.Next() {
158 err := rows.Scan(rowValues...)
159 if err != nil {
160 return nil, err
161 }
162 groupValues := make([]any, len(groupBy))
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
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 {
176 // This should never happen.
177 return nil, serviceerror.NewInternal(
178 fmt.Sprintf(
179 "Unable to parse count value from DB (got: %v of type: %T, expected type: integer)",
180 countValue,
181 countValue,
182 ),
183 )
184 }
185 res = append(res, VisibilityCountRow{
186 GroupValues: groupValues,
187 Count: countTyped,
188 })
189 }
190 return res, nil
191}
192
193func parseCountGroupByGroupValue(fieldName string, value any) (any, error) {
194 switch fieldName {

Calls 4

IntMethod · 0.80
NextMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected