top

Package bigtable is an API to Google Cloud Bigtable.

See https://cloud.google.com/bigtable/docs/ for general product documentation.

Setup and Credentials

Use NewClient or NewAdminClient to create a client that can be used to access the data or admin APIs respectively. Both require credentials that have permission to access the Cloud Bigtable API.

If your program is run on Google App Engine or Google Compute Engine, using the Application Default Credentials (https://developers.google.com/accounts/docs/application-default-credentials) is the simplest option. Those credentials will be used by default when NewClient or NewAdminClient are called.

To use alternate credentials, pass them to NewClient or NewAdminClient using option.WithTokenSource. For instance, you can use service account credentials by visiting https://cloud.google.com/console/project/MYPROJECT/apiui/credential, creating a new OAuth "Client ID", storing the JSON key somewhere accessible, and writing

jsonKey, err := ioutil.ReadFile(pathToKeyFile)
...
config, err := google.JWTConfigFromJSON(jsonKey, bigtable.Scope) // or bigtable.AdminScope, etc.
...
client, err := bigtable.NewClient(ctx, project, instance, option.WithTokenSource(config.TokenSource(ctx)))
...

Here, `google` means the golang.org/x/oauth2/google package and `option` means the google.golang.org/api/option package.

Reading

The principal way to read from a Bigtable is to use the ReadRows method on *Table. A RowRange specifies a contiguous portion of a table. A Filter may be provided through RowFilter to limit or transform the data that is returned.

tbl := client.Open("mytable")
...
// Read all the rows starting with "com.google.",
// but only fetch the columns in the "links" family.
rr := bigtable.PrefixRange("com.google.")
err := tbl.ReadRows(ctx, rr, func(r Row) bool {
	// do something with r
	return true // keep going
}, bigtable.RowFilter(bigtable.FamilyFilter("links")))
...

To read a single row, use the ReadRow helper method.

r, err := tbl.ReadRow(ctx, "com.google.cloud") // "com.google.cloud" is the entire row key
...

Writing

This API exposes two distinct forms of writing to a Bigtable: a Mutation and a ReadModifyWrite. The former expresses idempotent operations. The latter expresses non-idempotent operations and returns the new values of updated cells. These operations are performed by creating a Mutation or ReadModifyWrite (with NewMutation or NewReadModifyWrite), building up one or more operations on that, and then using the Apply or ApplyReadModifyWrite methods on a Table.

For instance, to set a couple of cells in a table,

tbl := client.Open("mytable")
mut := bigtable.NewMutation()
mut.Set("links", "maps.google.com", bigtable.Now(), []byte("1"))
mut.Set("links", "golang.org", bigtable.Now(), []byte("1"))
err := tbl.Apply(ctx, "com.google.cloud", mut)
...

To increment an encoded value in one cell,

tbl := client.Open("mytable")
rmw := bigtable.NewReadModifyWrite()
rmw.Increment("links", "golang.org", 12) // add 12 to the cell in column "links:golang.org"
r, err := tbl.ApplyReadModifyWrite(ctx, "com.google.cloud", rmw)
...

Retries

If a read or write operation encounters a transient error it will be retried until a successful response, an unretryable error or the context deadline is reached. Non-idempotent writes (where the timestamp is set to ServerTime) will not be retried. In the case of ReadRows, retried calls will not re-scan rows that have already been processed.

Imported by 24 package(s)

  1. cloud.google.com/go/bigtable/cmd/cbt
  2. cloud.google.com/go/bigtable/cmd/loadtest
  3. cloud.google.com/go/bigtable/cmd/scantest
  4. cloud.google.com/go/examples/bigtable/helloworld
  5. cloud.google.com/go/examples/bigtable/search
  6. cloud.google.com/go/examples/bigtable/usercounter
  7. github.com/Nitecon/gcloud-golang/examples/bigtable/hello_world
  8. github.com/Nitecon/gcloud-golang/examples/bigtable/search
  9. github.com/Nitecon/gcloud-golang/examples/bigtable/user_visit_counter
  10. github.com/dataux/dataux/backends/bigtable
  11. github.com/jba/google-cloud-go/examples/bigtable/helloworld
  12. github.com/jba/google-cloud-go/examples/bigtable/search
  13. github.com/jba/google-cloud-go/examples/bigtable/usercounter
  14. github.com/luci/luci-go/logdog/common/storage/bigtable
  15. github.com/luci/luci-go/logdog/common/storage/bigtable/logdog_bigtable_test
  16. github.com/tortuoise/gcloud-golang/examples/bigtable/helloworld
  17. github.com/tortuoise/gcloud-golang/examples/bigtable/search
  18. github.com/tortuoise/gcloud-golang/examples/bigtable/usercounter
  19. google.golang.org/cloud/bigtable/cmd/cbt
  20. google.golang.org/cloud/bigtable/cmd/loadtest
  21. google.golang.org/cloud/bigtable/cmd/scantest
  22. google.golang.org/cloud/examples/bigtable/helloworld
  23. google.golang.org/cloud/examples/bigtable/search
  24. google.golang.org/cloud/examples/bigtable/usercounter

Imported only in test by 2 package(s)

  1. cloud.google.com/go/bigtable/bttest
  2. github.com/jba/google-cloud-go/bigtable/bttest

Imports 12 package(s)

  1. github.com/golang/protobuf/proto
  2. golang.org/x/net/context
  3. google.golang.org/api/transport
  4. cloud.google.com/go/bigtable/internal/gax
  5. github.com/golang/protobuf/ptypes/duration
  6. google.golang.org/genproto/googleapis/bigtable/v2
  7. google.golang.org/api/option
  8. google.golang.org/grpc
  9. google.golang.org/grpc/codes
  10. cloud.google.com/go/bigtable/internal/option
  11. google.golang.org/genproto/googleapis/bigtable/admin/v2
  12. google.golang.org/grpc/metadata

Test imports 3 package(s)

  1. github.com/golang/protobuf/ptypes/wrappers
  2. cloud.google.com/go/bigtable/bttest
  3. google.golang.org/genproto/googleapis/rpc/status