Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill Labels attribute of a DataFrame Field. #391

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (r *Response) toFramesWithTimeStamp(query *Query, fetchTZ FetchTZFunc, hasL

if hasLabelFields {
framePrefix := r.generateFrameNameByLabels(row, metaTypes, labelFieldsMap)
frameLabels := r.generateFrameLabelsByLables(row, metaTypes, labelFieldsMap)

for fieldName, fieldValue := range row {
_, isLabel := labelFieldsMap[fieldName]
if fieldName != timestampFieldName && !isLabel {
Expand All @@ -96,6 +98,7 @@ func (r *Response) toFramesWithTimeStamp(query *Query, fetchTZ FetchTZFunc, hasL
frameName += ", " + fieldName
}
r.createFrameIfNotExistsAndAddPoint(query, framesMap, frameName, timeStampDataFieldMap, timestampFieldName, valueDataFieldMap, fieldName, metaTypes[fieldName], timestampValue, timeZonesMap, fieldValue)
valueDataFieldMap[frameName].Labels = frameLabels
}
}
} else {
Expand Down Expand Up @@ -185,6 +188,18 @@ func (r *Response) generateFrameNameByLabels(row map[string]interface{}, metaTyp
return frameName
}

func (r *Response) generateFrameLabelsByLables(row map[string]interface{}, metaTypes map[string]string, labelFieldsMap map[string]int) map[string]string {
Slach marked this conversation as resolved.
Show resolved Hide resolved
labels := map[string]string{}
for fieldName, fieldValue := range row {
if _, isLabel := labelFieldsMap[fieldName]; isLabel {
fieldType := metaTypes[fieldName]
labels[fieldName] = fmt.Sprintf("%v", ParseValue(fieldName, fieldType, nil, fieldValue, false))
}
}

return labels
}

func (r *Response) toFramesTable(query *Query, fetchTZ FetchTZFunc) (data.Frames, error) {
timeZonesMap, metaTypes := r.analyzeResponseMeta(fetchTZ)
framesMap := map[string]*data.Frame{}
Expand Down