Package bigtable
Overview ▹
Index ▹
Constants
Scope constants for authentication credentials. These should be used when using credential creation functions such as oauth.NewServiceAccountFromFile.
const ( // Scope is the OAuth scope for Cloud Bigtable data operations. Scope = "https://www.googleapis.com/auth/bigtable.data" // ReadonlyScope is the OAuth scope for Cloud Bigtable read-only data operations. ReadonlyScope = "https://www.googleapis.com/auth/bigtable.readonly" // AdminScope is the OAuth scope for Cloud Bigtable table admin operations. AdminScope = "https://www.googleapis.com/auth/bigtable.admin.table" // InstanceAdminScope is the OAuth scope for Cloud Bigtable instance (and cluster) admin operations. InstanceAdminScope = "https://www.googleapis.com/auth/bigtable.admin.cluster" )
func GCRuleToString ¶
func GCRuleToString(rule *bttdpb.GcRule) string
GCRuleToString converts the given GcRule proto to a user-visible string.
type AdminClient ¶
AdminClient is a client type for performing admin operations within a specific instance.
type AdminClient struct {
// contains filtered or unexported fields
}
func NewAdminClient ¶
func NewAdminClient(ctx context.Context, project, instance string, opts ...option.ClientOption) (*AdminClient, error)
NewAdminClient creates a new AdminClient for a given project and instance.
func (*AdminClient) Close ¶
func (ac *AdminClient) Close() error
Close closes the AdminClient.
func (*AdminClient) CreateColumnFamily ¶
func (ac *AdminClient) CreateColumnFamily(ctx context.Context, table, family string) error
CreateColumnFamily creates a new column family in a table.
func (*AdminClient) CreatePresplitTable ¶
func (ac *AdminClient) CreatePresplitTable(ctx context.Context, table string, split_keys []string) error
CreatePresplitTable creates a new table in the instance. The list of row keys will be used to initially split the table into multiple tablets. Given two split keys, "s1" and "s2", three tablets will be created, spanning the key ranges: [, s1), [s1, s2), [s2, ). This method may return before the table's creation is complete.
func (*AdminClient) CreateTable ¶
func (ac *AdminClient) CreateTable(ctx context.Context, table string) error
CreateTable creates a new table in the instance. This method may return before the table's creation is complete.
func (*AdminClient) DeleteColumnFamily ¶
func (ac *AdminClient) DeleteColumnFamily(ctx context.Context, table, family string) error
DeleteColumnFamily deletes a column family in a table and all of its data.
func (*AdminClient) DeleteTable ¶
func (ac *AdminClient) DeleteTable(ctx context.Context, table string) error
DeleteTable deletes a table and all of its data.
func (*AdminClient) DropRowRange ¶
func (ac *AdminClient) DropRowRange(ctx context.Context, table, rowKeyPrefix string) error
DropRowRange permanently deletes a row range from the specified table.
func (*AdminClient) SetGCPolicy ¶
func (ac *AdminClient) SetGCPolicy(ctx context.Context, table, family string, policy GCPolicy) error
SetGCPolicy specifies which cells in a column family should be garbage collected. GC executes opportunistically in the background; table reads may return data matching the GC policy.
func (*AdminClient) TableInfo ¶
func (ac *AdminClient) TableInfo(ctx context.Context, table string) (*TableInfo, error)
TableInfo retrieves information about a table.
func (*AdminClient) Tables ¶
func (ac *AdminClient) Tables(ctx context.Context) ([]string, error)
Tables returns a list of the tables in the instance.
type ApplyOption ¶
An ApplyOption is an optional argument to Apply.
type ApplyOption interface {
// contains filtered or unexported methods
}
func GetCondMutationResult ¶
func GetCondMutationResult(matched *bool) ApplyOption
GetCondMutationResult returns an ApplyOption that reports whether the conditional mutation's condition matched.
type Client ¶
Client is a client for reading and writing data to tables in an instance.
A Client is safe to use concurrently, except for its Close method.
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(ctx context.Context, project, instance string, opts ...option.ClientOption) (*Client, error)
NewClient creates a new Client for a given project and instance.
func (*Client) Close ¶
func (c *Client) Close() error
Close closes the Client.
func (*Client) Open ¶
func (c *Client) Open(table string) *Table
Open opens a table.
type FamilyInfo ¶
FamilyInfo represents information about a column family.
type FamilyInfo struct { Name string GCPolicy string }
type Filter ¶
A Filter represents a row filter.
type Filter interface {
String() string
// contains filtered or unexported methods
}
func ChainFilters ¶
func ChainFilters(sub ...Filter) Filter
ChainFilters returns a filter that applies a sequence of filters.
func ColumnFilter ¶
func ColumnFilter(pattern string) Filter
ColumnFilter returns a filter that matches cells whose column name matches the provided RE2 pattern. See https://github.com/google/re2/wiki/Syntax for the accepted syntax.
func ColumnRangeFilter ¶
func ColumnRangeFilter(family, start, end string) Filter
ColumnRangeFilter returns a filter that matches a contiguous range of columns within a single family, as specified by an inclusive start qualifier and exclusive end qualifier.
func ConditionFilter ¶
func ConditionFilter(predicateFilter, trueFilter, falseFilter Filter) Filter
ConditionFilter returns a filter that evaluates to one of two possible filters depending on whether or not the given predicate filter matches at least one cell. If the matched filter is nil then no results will be returned. IMPORTANT NOTE: The predicate filter does not execute atomically with the true and false filters, which may lead to inconsistent or unexpected results. Additionally, condition filters have poor performance, especially when filters are set for the false condition.
func FamilyFilter ¶
func FamilyFilter(pattern string) Filter
FamilyFilter returns a filter that matches cells whose family name matches the provided RE2 pattern. See https://github.com/google/re2/wiki/Syntax for the accepted syntax.
func InterleaveFilters ¶
func InterleaveFilters(sub ...Filter) Filter
InterleaveFilters returns a filter that applies a set of filters in parallel and interleaves the results.
func LatestNFilter ¶
func LatestNFilter(n int) Filter
LatestNFilter returns a filter that matches the most recent N cells in each column.
func RowKeyFilter ¶
func RowKeyFilter(pattern string) Filter
RowKeyFilter returns a filter that matches cells from rows whose key matches the provided RE2 pattern. See https://github.com/google/re2/wiki/Syntax for the accepted syntax.
func StripValueFilter ¶
func StripValueFilter() Filter
StripValueFilter returns a filter that replaces each value with the empty string.
func TimestampRangeFilter ¶
func TimestampRangeFilter(startTime time.Time, endTime time.Time) Filter
TimestampRangeFilter returns a filter that matches any cells whose timestamp is within the given time bounds. A zero time means no bound. The timestamp will be truncated to millisecond granularity.
func TimestampRangeFilterMicros ¶
func TimestampRangeFilterMicros(startTime Timestamp, endTime Timestamp) Filter
TimestampRangeFilterMicros returns a filter that matches any cells whose timestamp is within the given time bounds, specified in units of microseconds since 1 January 1970. A zero value for the end time is interpreted as no bound. The timestamp will be truncated to millisecond granularity.
func ValueFilter ¶
func ValueFilter(pattern string) Filter
ValueFilter returns a filter that matches cells whose value matches the provided RE2 pattern. See https://github.com/google/re2/wiki/Syntax for the accepted syntax.
func ValueRangeFilter ¶
func ValueRangeFilter(start, end []byte) Filter
ValueRangeFilter returns a filter that matches cells with values that fall within the given range, as specified by an inclusive start value and exclusive end value.
type GCPolicy ¶
A GCPolicy represents a rule that determines which cells are eligible for garbage collection.
type GCPolicy interface {
String() string
// contains filtered or unexported methods
}
func IntersectionPolicy ¶
func IntersectionPolicy(sub ...GCPolicy) GCPolicy
IntersectionPolicy returns a GC policy that only applies when all its sub-policies apply.
func MaxAgePolicy ¶
func MaxAgePolicy(d time.Duration) GCPolicy
MaxAgePolicy returns a GC policy that applies to all cells older than the given age.
func MaxVersionsPolicy ¶
func MaxVersionsPolicy(n int) GCPolicy
MaxVersionsPolicy returns a GC policy that applies to all versions of a cell except for the most recent n.
func UnionPolicy ¶
func UnionPolicy(sub ...GCPolicy) GCPolicy
UnionPolicy returns a GC policy that applies when any of its sub-policies apply.
type InstanceAdminClient ¶
InstanceAdminClient is a client type for performing admin operations on instances. These operations can be substantially more dangerous than those provided by AdminClient.
type InstanceAdminClient struct {
// contains filtered or unexported fields
}
func NewInstanceAdminClient ¶
func NewInstanceAdminClient(ctx context.Context, project string, opts ...option.ClientOption) (*InstanceAdminClient, error)
NewInstanceAdminClient creates a new InstanceAdminClient for a given project.
func (*InstanceAdminClient) Close ¶
func (iac *InstanceAdminClient) Close() error
Close closes the InstanceAdminClient.
func (*InstanceAdminClient) CreateInstance ¶
func (iac *InstanceAdminClient) CreateInstance(ctx context.Context, conf *InstanceConf) error
CreateInstance creates a new instance in the project. This method will return when the instance has been created or when an error occurs.
func (*InstanceAdminClient) DeleteInstance ¶
func (iac *InstanceAdminClient) DeleteInstance(ctx context.Context, instanceId string) error
DeleteInstance deletes an instance from the project.
func (*InstanceAdminClient) Instances ¶
func (iac *InstanceAdminClient) Instances(ctx context.Context) ([]*InstanceInfo, error)
Instances returns a list of instances in the project.
type InstanceConf ¶
InstanceConf contains the information necessary to create an Instance
type InstanceConf struct { InstanceId, DisplayName, ClusterId, Zone string NumNodes int32 StorageType StorageType }
type InstanceInfo ¶
InstanceInfo represents information about an instance
type InstanceInfo struct { Name string // name of the instance DisplayName string // display name for UIs }
type Mutation ¶
Mutation represents a set of changes for a single row of a table.
type Mutation struct {
// contains filtered or unexported fields
}
func NewCondMutation ¶
func NewCondMutation(cond Filter, mtrue, mfalse *Mutation) *Mutation
NewCondMutation returns a conditional mutation. The given row filter determines which mutation is applied: If the filter matches any cell in the row, mtrue is applied; otherwise, mfalse is applied. Either given mutation may be nil.
func NewMutation ¶
func NewMutation() *Mutation
NewMutation returns a new mutation.
func (*Mutation) DeleteCellsInColumn ¶
func (m *Mutation) DeleteCellsInColumn(family, column string)
DeleteCellsInColumn will delete all the cells whose columns are family:column.
func (*Mutation) DeleteCellsInFamily ¶
func (m *Mutation) DeleteCellsInFamily(family string)
DeleteCellsInFamily will delete all the cells whose columns are family:*.
func (*Mutation) DeleteRow ¶
func (m *Mutation) DeleteRow()
DeleteRow deletes the entire row.
func (*Mutation) DeleteTimestampRange ¶
func (m *Mutation) DeleteTimestampRange(family, column string, start, end Timestamp)
DeleteTimestampRange deletes all cells whose columns are family:column and whose timestamps are in the half-open interval [start, end). If end is zero, it will be interpreted as infinity. The timestamps will be truncated to millisecond granularity.
func (*Mutation) Set ¶
func (m *Mutation) Set(family, column string, ts Timestamp, value []byte)
Set sets a value in a specified column, with the given timestamp. The timestamp will be truncated to millisecond granularity. A timestamp of ServerTime means to use the server timestamp.
type ReadItem ¶
A ReadItem is returned by Read. A ReadItem contains data from a specific row and column.
type ReadItem struct { Row, Column string Timestamp Timestamp Value []byte }
type ReadModifyWrite ¶
ReadModifyWrite represents a set of operations on a single row of a table. It is like Mutation but for non-idempotent changes. When applied, these operations operate on the latest values of the row's cells, and result in a new value being written to the relevant cell with a timestamp that is max(existing timestamp, current server time).
The application of a ReadModifyWrite is atomic; concurrent ReadModifyWrites will be executed serially by the server.
type ReadModifyWrite struct {
// contains filtered or unexported fields
}
func NewReadModifyWrite ¶
func NewReadModifyWrite() *ReadModifyWrite
NewReadModifyWrite returns a new ReadModifyWrite.
func (*ReadModifyWrite) AppendValue ¶
func (m *ReadModifyWrite) AppendValue(family, column string, v []byte)
AppendValue appends a value to a specific cell's value. If the cell is unset, it will be treated as an empty value.
func (*ReadModifyWrite) Increment ¶
func (m *ReadModifyWrite) Increment(family, column string, delta int64)
Increment interprets the value in a specific cell as a 64-bit big-endian signed integer, and adds a value to it. If the cell is unset, it will be treated as zero. If the cell is set and is not an 8-byte value, the entire ApplyReadModifyWrite operation will fail.
type ReadOption ¶
A ReadOption is an optional argument to ReadRows.
type ReadOption interface {
// contains filtered or unexported methods
}
func LimitRows ¶
func LimitRows(limit int64) ReadOption
LimitRows returns a ReadOption that will limit the number of rows to be read.
func RowFilter ¶
func RowFilter(f Filter) ReadOption
RowFilter returns a ReadOption that applies f to the contents of read rows.
type Row ¶
A Row is returned by ReadRows. The map is keyed by column family (the prefix of the column name before the colon). The values are the returned ReadItems for that column family in the order returned by Read.
type Row map[string][]ReadItem
func (Row) Key ¶
func (r Row) Key() string
Key returns the row's key, or "" if the row is empty.
type RowList ¶
RowList is a sequence of row keys.
type RowList []string
type RowRange ¶
A RowRange is a half-open interval [Start, Limit) encompassing all the rows with keys at least as large as Start, and less than Limit. (Bigtable string comparison is the same as Go's.) A RowRange can be unbounded, encompassing all keys at least as large as Start.
type RowRange struct {
// contains filtered or unexported fields
}
func InfiniteRange ¶
func InfiniteRange(start string) RowRange
InfiniteRange returns the RowRange consisting of all keys at least as large as start.
func NewRange ¶
func NewRange(begin, end string) RowRange
NewRange returns the new RowRange [begin, end).
func PrefixRange ¶
func PrefixRange(prefix string) RowRange
PrefixRange returns a RowRange consisting of all keys starting with the prefix.
func (RowRange) Contains ¶
func (r RowRange) Contains(row string) bool
Contains says whether the RowRange contains the key.
func (RowRange) String ¶
func (r RowRange) String() string
String provides a printable description of a RowRange.
func (RowRange) Unbounded ¶
func (r RowRange) Unbounded() bool
Unbounded tests whether a RowRange is unbounded.
type RowRangeList ¶
RowRangeList is a sequence of RowRanges representing the union of the ranges.
type RowRangeList []RowRange
type RowSet ¶
RowSet is a set of rows to be read. It is satisfied by RowList, RowRange and RowRangeList.
type RowSet interface {
// contains filtered or unexported methods
}
func SingleRow ¶
func SingleRow(row string) RowSet
SingleRow returns a RowSet for reading a single row.
type StorageType ¶
StorageType is the type of storage used for all tables in an instance
type StorageType int
const ( SSD StorageType = iota HDD )
type Table ¶
A Table refers to a table.
A Table is safe to use concurrently.
type Table struct {
// contains filtered or unexported fields
}
func (*Table) Apply ¶
func (t *Table) Apply(ctx context.Context, row string, m *Mutation, opts ...ApplyOption) error
Apply applies a Mutation to a specific row.
func (*Table) ApplyBulk ¶
func (t *Table) ApplyBulk(ctx context.Context, rowKeys []string, muts []*Mutation, opts ...ApplyOption) ([]error, error)
ApplyBulk applies multiple Mutations. Each mutation is individually applied atomically, but the set of mutations may be applied in any order.
Two types of failures may occur. If the entire process fails, (nil, err) will be returned. If specific mutations fail to apply, ([]err, nil) will be returned, and the errors will correspond to the relevant rowKeys/muts arguments.
Conditional mutations cannot be applied in bulk and providing one will result in an error.
func (*Table) ApplyReadModifyWrite ¶
func (t *Table) ApplyReadModifyWrite(ctx context.Context, row string, m *ReadModifyWrite) (Row, error)
ApplyReadModifyWrite applies a ReadModifyWrite to a specific row. It returns the newly written cells.
func (*Table) ReadRow ¶
func (t *Table) ReadRow(ctx context.Context, row string, opts ...ReadOption) (Row, error)
ReadRow is a convenience implementation of a single-row reader. A missing row will return a zero-length map and a nil error.
func (*Table) ReadRows ¶
func (t *Table) ReadRows(ctx context.Context, arg RowSet, f func(Row) bool, opts ...ReadOption) error
ReadRows reads rows from a table. f is called for each row. If f returns false, the stream is shut down and ReadRows returns. f owns its argument, and f is called serially in order by row key.
By default, the yielded rows will contain all values in all cells. Use RowFilter to limit the cells returned.
type TableInfo ¶
TableInfo represents information about a table.
type TableInfo struct {
// DEPRECATED - This field is deprecated. Please use FamilyInfos instead.
Families []string
FamilyInfos []FamilyInfo
}
type Timestamp ¶
Timestamp is in units of microseconds since 1 January 1970.
type Timestamp int64
ServerTime is a specific Timestamp that may be passed to (*Mutation).Set. It indicates that the server's timestamp should be used.
const ServerTime Timestamp = -1
func Now ¶
func Now() Timestamp
Now returns the Timestamp representation of the current time on the client.
func Time ¶
func Time(t time.Time) Timestamp
Time converts a time.Time into a Timestamp.
func (Timestamp) Time ¶
func (ts Timestamp) Time() time.Time
Time converts a Timestamp into a time.Time.
func (Timestamp) TruncateToMilliseconds ¶
func (ts Timestamp) TruncateToMilliseconds() Timestamp
TruncateToMilliseconds truncates a Timestamp to millisecond granularity, which is currently the only granularity supported.
Subdirectories
Name | Synopsis |
---|---|
.. | |
bttest | Package bttest contains test helpers for working with the bigtable package. |
cmd | |
cbt | Cbt is a tool for doing basic interactions with Cloud Bigtable. |
emulator | cbtemulator launches the in-memory Cloud Bigtable server on the given address. |
loadtest | Loadtest does some load testing through the Go client library for Cloud Bigtable. |
scantest | Scantest does scan-related load testing against Cloud Bigtable. |