本文整理汇总了Golang中github.com/influxdb/influxdb/protocol.Series.GetFieldIndex方法的典型用法代码示例。如果您正苦于以下问题:Golang Series.GetFieldIndex方法的具体用法?Golang Series.GetFieldIndex怎么用?Golang Series.GetFieldIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/influxdb/influxdb/protocol.Series
的用法示例。
在下文中一共展示了Series.GetFieldIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InterpolateValuesAndCommit
func (self *Coordinator) InterpolateValuesAndCommit(query string, db string, series *protocol.Series, targetName string, assignSequenceNumbers bool) error {
defer common.RecoverFunc(db, query, nil)
targetName = strings.Replace(targetName, ":series_name", *series.Name, -1)
type sequenceKey struct {
seriesName string
timestamp int64
}
sequenceMap := make(map[sequenceKey]int)
r, _ := regexp.Compile(`\[.*?\]`)
// get the fields that are used in the target name
fieldsInTargetName := r.FindAllString(targetName, -1)
fieldsIndeces := make([]int, 0, len(fieldsInTargetName))
for i, f := range fieldsInTargetName {
f = f[1 : len(f)-1]
fieldsIndeces = append(fieldsIndeces, series.GetFieldIndex(f))
fieldsInTargetName[i] = f
}
fields := make([]string, 0, len(series.Fields)-len(fieldsIndeces))
// remove the fields used in the target name from the series fields
nextfield:
for i, f := range series.Fields {
for _, fi := range fieldsIndeces {
if fi == i {
continue nextfield
}
}
fields = append(fields, f)
}
if r.MatchString(targetName) {
serieses := map[string]*protocol.Series{}
for _, point := range series.Points {
fieldIndex := 0
targetNameWithValues := r.ReplaceAllStringFunc(targetName, func(_ string) string {
value := point.GetFieldValueAsString(fieldsIndeces[fieldIndex])
fieldIndex++
return value
})
p := &protocol.Point{
Values: make([]*protocol.FieldValue, 0, len(point.Values)-len(fieldsIndeces)),
Timestamp: point.Timestamp,
SequenceNumber: point.SequenceNumber,
}
// remove the fields used in the target name from the series fields
nextvalue:
for i, v := range point.Values {
for _, fi := range fieldsIndeces {
if fi == i {
continue nextvalue
}
}
p.Values = append(p.Values, v)
}
if assignSequenceNumbers {
key := sequenceKey{targetNameWithValues, *p.Timestamp}
sequenceMap[key] += 1
sequenceNumber := uint64(sequenceMap[key])
p.SequenceNumber = &sequenceNumber
}
newSeries := serieses[targetNameWithValues]
if newSeries == nil {
newSeries = &protocol.Series{Name: &targetNameWithValues, Fields: fields, Points: []*protocol.Point{p}}
serieses[targetNameWithValues] = newSeries
continue
}
newSeries.Points = append(newSeries.Points, p)
}
seriesSlice := make([]*protocol.Series, 0, len(serieses))
for _, s := range serieses {
seriesSlice = append(seriesSlice, s)
}
if e := self.CommitSeriesData(db, seriesSlice, true); e != nil {
log.Error("Couldn't write data for continuous query: ", e)
}
} else {
newSeries := &protocol.Series{Name: &targetName, Fields: fields, Points: series.Points}
if assignSequenceNumbers {
for _, point := range newSeries.Points {
sequenceMap[sequenceKey{targetName, *point.Timestamp}] += 1
sequenceNumber := uint64(sequenceMap[sequenceKey{targetName, *point.Timestamp}])
point.SequenceNumber = &sequenceNumber
}
}
if e := self.CommitSeriesData(db, []*protocol.Series{newSeries}, true); e != nil {
log.Error("Couldn't write data for continuous query: ", e)
}
}
return nil
}