【问题标题】:how does one support pagination using bigtable Go client?如何使用 bigtable Go 客户端支持分页?
【发布时间】:2019-05-18 10:05:12
【问题描述】:

我将时间序列数据存储在 bigtable 中,rowKey 为 userId#timestamp。给定 (userId, startTime, endTime) 的查询参数,我如何支持分页,即从 'offset' 开始返回 'limit' 记录?

注意 userId#startTime rowKey 可能在 bigtable 中不存在,但在 startTime/EndTime 之前和之后会有一些数据点。 Bigtable Go 客户端似乎支持带有 prefixRange 参数的 ReadRows。当我使用 ReadRows 进行迭代时,我可以使用 userId 的 prefixRange 和“seek”到 startTime,但是如果 starTime/endTime 是过去的方式,这似乎非常低效。有没有更好的办法??

【问题讨论】:

  • 这篇文章可能有你要找的东西,看看,让我知道它适合你:stackoverflow.com/questions/49691823/…
  • 谢谢 maxim,但是 bigtable Go 客户端没有 Node 客户端那样的 readStream 接口。

标签: go pagination google-cloud-platform google-cloud-bigtable


【解决方案1】:
推荐的答案 Google Cloud

您可以使用NewRange 启动从userId#startTime 到userId#endTime 的ReadRows 操作,并使用LimitRows 读取选项设置返回的行数限制。

err = tbl.ReadRows(ctx, NewRange("<userId>#<startTime>", "<userId>#<endTime>"), func(r Row) bool {
    fmt.Println("Got a row")
    return true
}, LimitRows(100))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 2018-09-16
    • 2019-11-04
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 2018-02-10
    相关资源
    最近更新 更多