如何使用bigtable Go客户端支持分页?
I store time series data in bigtable with a rowKey of userId#timestamp. Given query parameters of (userId, startTime, endTime) how can I support pagination i.e return 'limit' records starting from 'offset' ?
note that userId#startTime rowKey may not exist in bigtable but there will some datapoints before and after startTime/EndTime. Bigtable Go client seems to support ReadRows with a prefixRange argument. I could use a prefixRange of userId and 'seek' to the startTime as I iterate using ReadRows but this seems very inefficient if starTime/endTime is way in the past. is there a better way ??
我将时间序列数据存储在具有userId#timestamp的rowKey的bigtable中。 给定(userId,startTime,endTime)的查询参数,我如何支持分页,即从'offset'开始返回'limit'记录? p>
请注意,在大表中可能不存在userId#startTime rowKey,但在startTime / EndTime之前和之后会有一些数据点。 Bigtable Go客户端似乎支持带prefixRange参数的ReadRows。 当我使用ReadRows进行迭代时,我可以使用userId的prefixRange和'seek'到startTime,但是如果starTime / endTime过去,这似乎效率很低。 有更好的方法吗? p> div>
You can start a ReadRows operation from userId#startTime
to userId#endTime
with a NewRange and set a limit on the number of rows returned with a LimitRows read option.
err = tbl.ReadRows(ctx, NewRange("<userId>#<startTime>", "<userId>#<endTime>"), func(r Row) bool {
fmt.Println("Got a row")
return true
}, LimitRows(100))