本文整理汇总了Golang中github.com/SoftwareDefinedBuildings/btrdb.Quasar.QueryNearestValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Quasar.QueryNearestValue方法的具体用法?Golang Quasar.QueryNearestValue怎么用?Golang Quasar.QueryNearestValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/SoftwareDefinedBuildings/btrdb.Quasar
的用法示例。
在下文中一共展示了Quasar.QueryNearestValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: request_get_NEAREST
func request_get_NEAREST(q *btrdb.Quasar, w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(&outstandingHttpReqs, 1)
defer func() {
atomic.AddInt32(&outstandingHttpReqs, -1)
}()
r.ParseForm()
ids := r.Form.Get(":uuid")
id := uuid.Parse(ids)
if id == nil {
doError(w, "malformed uuid")
return
}
t, ok, msg := parseInt(r.Form.Get("time"), -(16 << 56), (48 << 56))
if !ok {
doError(w, "bad time: "+msg)
return
}
bws := r.Form.Get("backwards")
bw := bws != ""
rec, _, err := q.QueryNearestValue(id, t, bw, btrdb.LatestGeneration)
if err != nil {
doError(w, "Bad query: "+err.Error())
return
}
w.Write([]byte(fmt.Sprintf("[%d, %f]", rec.Time, rec.Val)))
}
示例2: dispatchCommands
//.........这里部分代码省略.........
}
}
case REQUEST_QUERYVERSION:
//ul := req.
ul := req.QueryVersion().Uuids()
ull := ul.ToArray()
resp, rvseg := mkresp()
rvers := NewVersions(rvseg)
vlist := rvseg.NewUInt64List(len(ull))
ulist := rvseg.NewDataList(len(ull))
for i, v := range ull {
ver, err := q.QueryGeneration(uuid.UUID(v))
if err != nil {
resp.SetStatusCode(STATUSCODE_INTERNALERROR)
resp.SetFinal(true)
sendresp(rvseg)
return
}
//I'm not sure that the array that sits behind the uuid slice will stick around
//so I'm copying it.
uuid := make([]byte, 16)
copy(uuid, v)
vlist.Set(i, ver)
ulist.Set(i, uuid)
}
resp.SetStatusCode(STATUSCODE_OK)
rvers.SetUuids(ulist)
rvers.SetVersions(vlist)
resp.SetVersionList(rvers)
resp.SetFinal(true)
sendresp(rvseg)
case REQUEST_QUERYNEARESTVALUE:
resp, rvseg := mkresp()
t := req.QueryNearestValue().Time()
id := uuid.UUID(req.QueryNearestValue().Uuid())
ver := req.QueryNearestValue().Version()
if ver == 0 {
ver = btrdb.LatestGeneration
}
back := req.QueryNearestValue().Backward()
rv, gen, err := q.QueryNearestValue(id, t, back, ver)
switch err {
case nil:
resp.SetStatusCode(STATUSCODE_OK)
records := NewRecords(rvseg)
rl := NewRecordList(rvseg, 1)
rla := rl.ToArray()
rla[0].SetTime(rv.Time)
rla[0].SetValue(rv.Val)
records.SetVersion(gen)
records.SetValues(rl)
resp.SetRecords(records)
case qtree.ErrNoSuchPoint:
resp.SetStatusCode(STATUSCODE_NOSUCHPOINT)
default:
resp.SetStatusCode(STATUSCODE_INTERNALERROR)
}
resp.SetFinal(true)
sendresp(rvseg)
case REQUEST_QUERYCHANGEDRANGES:
resp, rvseg := mkresp()
id := uuid.UUID(req.QueryChangedRanges().Uuid())
sgen := req.QueryChangedRanges().FromGeneration()
egen := req.QueryChangedRanges().ToGeneration()
if egen == 0 {
egen = btrdb.LatestGeneration
示例3: request_post_BRACKET
func request_post_BRACKET(q *btrdb.Quasar, w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(&outstandingHttpReqs, 1)
defer func() {
atomic.AddInt32(&outstandingHttpReqs, -1)
}()
dec := json.NewDecoder(r.Body)
req := bracket_req{}
err := dec.Decode(&req)
if err != nil {
doError(w, "bad request")
return
}
if len(req.UUIDS) == 0 {
doError(w, "no uuids")
return
}
rv := bracket_resp{}
rv.Brackets = make([][]int64, len(req.UUIDS))
var min, max int64
var minset, maxset bool
for i, u := range req.UUIDS {
uid := uuid.Parse(u)
if uid == nil {
doError(w, "malformed uuid")
return
}
rec, _, err := q.QueryNearestValue(uid, btrdb.MinimumTime+1, false, btrdb.LatestGeneration)
if err == qtree.ErrNoSuchStream {
rv.Brackets[i] = make([]int64, 2)
rv.Brackets[i][0] = -1
rv.Brackets[i][1] = -1
continue
}
if err != nil {
doError(w, "Bad query: "+err.Error())
return
}
start := rec.Time
if !minset || start < min {
min = start
minset = true
}
rec, _, err = q.QueryNearestValue(uid, btrdb.MaximumTime-1, true, btrdb.LatestGeneration)
if err != nil {
doError(w, "Bad query: "+err.Error())
return
}
end := rec.Time
if !maxset || end > max {
max = end
maxset = true
}
rv.Brackets[i] = make([]int64, 2)
rv.Brackets[i][0] = start
rv.Brackets[i][1] = end
}
rv.Merged = make([]int64, 2)
if minset && maxset {
rv.Merged[0] = min
rv.Merged[1] = max
} else {
doError(w, "Bad query: none of those streams exist")
return
}
err = json.NewEncoder(w).Encode(rv)
if err != nil {
doError(w, "JSON error: "+err.Error())
return
}
return
}