DetectProjectID is a sentinel value that instructs NewClient to detect the project ID. It is given in place of the projectID argument. NewClient will use the project ID from the given credentials or the default credentials (https://developers.google.com/accounts/docs/application-default-credentials) if no credentials were provided. When providing credentials, not all options will allow NewClient to extract the project ID. Specifically a JWT does not have the project ID encoded.
const DetectProjectID = "*detect-project-id*"
NoStreamOffset is a sentinel value for signalling we're not tracking stream offset (e.g. a default stream which allows simultaneous append streams).
const NoStreamOffset int64 = -1
var ( // AppendClientOpenCount is a measure of the number of times the AppendRowsClient was opened. // It is EXPERIMENTAL and subject to change or removal without notice. AppendClientOpenCount = stats.Int64(statsPrefix+"stream_open_count", "Number of times AppendRowsClient was opened", stats.UnitDimensionless) // AppendClientOpenRetryCount is a measure of the number of times the AppendRowsClient open was retried. // It is EXPERIMENTAL and subject to change or removal without notice. AppendClientOpenRetryCount = stats.Int64(statsPrefix+"stream_open_retry_count", "Number of times AppendRowsClient open was retried", stats.UnitDimensionless) // AppendRequests is a measure of the number of append requests sent. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequests = stats.Int64(statsPrefix+"append_requests", "Number of append requests sent", stats.UnitDimensionless) // AppendRequestBytes is a measure of the bytes sent as append requests. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestBytes = stats.Int64(statsPrefix+"append_request_bytes", "Number of bytes sent as append requests", stats.UnitBytes) // AppendRequestErrors is a measure of the number of append requests that errored on send. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestErrors = stats.Int64(statsPrefix+"append_request_errors", "Number of append requests that yielded immediate error", stats.UnitDimensionless) // AppendRequestReconnects is a measure of the number of times that sending an append request triggered reconnect. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestReconnects = stats.Int64(statsPrefix+"append_reconnections", "Number of append rows reconnections", stats.UnitDimensionless) // AppendRequestRows is a measure of the number of append rows sent. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestRows = stats.Int64(statsPrefix+"append_rows", "Number of append rows sent", stats.UnitDimensionless) // AppendResponses is a measure of the number of append responses received. // It is EXPERIMENTAL and subject to change or removal without notice. AppendResponses = stats.Int64(statsPrefix+"append_responses", "Number of append responses sent", stats.UnitDimensionless) // AppendResponseErrors is a measure of the number of append responses received with an error attached. // It is EXPERIMENTAL and subject to change or removal without notice. AppendResponseErrors = stats.Int64(statsPrefix+"append_response_errors", "Number of append responses with errors attached", stats.UnitDimensionless) // AppendRetryCount is a measure of the number of appends that were automatically retried by the library // after receiving a non-successful response. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRetryCount = stats.Int64(statsPrefix+"append_retry_count", "Number of appends that were retried", stats.UnitDimensionless) // FlushRequests is a measure of the number of FlushRows requests sent. // It is EXPERIMENTAL and subject to change or removal without notice. FlushRequests = stats.Int64(statsPrefix+"flush_requests", "Number of FlushRows requests sent", stats.UnitDimensionless) )
var ( // AppendClientOpenView is a cumulative sum of AppendClientOpenCount. // It is EXPERIMENTAL and subject to change or removal without notice. AppendClientOpenView *view.View // AppendClientOpenRetryView is a cumulative sum of AppendClientOpenRetryCount. // It is EXPERIMENTAL and subject to change or removal without notice. AppendClientOpenRetryView *view.View // AppendRequestsView is a cumulative sum of AppendRequests. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestsView *view.View // AppendRequestBytesView is a cumulative sum of AppendRequestBytes. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestBytesView *view.View // AppendRequestErrorsView is a cumulative sum of AppendRequestErrors. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestErrorsView *view.View // AppendRequestReconnectsView is a cumulative sum of AppendRequestReconnects. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestReconnectsView *view.View // AppendRequestRowsView is a cumulative sum of AppendRows. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRequestRowsView *view.View // AppendResponsesView is a cumulative sum of AppendResponses. // It is EXPERIMENTAL and subject to change or removal without notice. AppendResponsesView *view.View // AppendResponseErrorsView is a cumulative sum of AppendResponseErrors. // It is EXPERIMENTAL and subject to change or removal without notice. AppendResponseErrorsView *view.View // AppendRetryView is a cumulative sum of AppendRetryCount. // It is EXPERIMENTAL and subject to change or removal without notice. AppendRetryView *view.View // FlushRequestsView is a cumulative sum of FlushRequests. // It is EXPERIMENTAL and subject to change or removal without notice. FlushRequestsView *view.View )
DefaultOpenCensusViews retains the set of all opencensus views that this library has instrumented, to add view registration for exporters.
var DefaultOpenCensusViews []*view.View
func TableParentFromParts(projectID, datasetID, tableID string) string
TableParentFromParts constructs a table identifier using individual identifiers and returns a string in the form "projects/{project}/datasets/{dataset}/tables/{table}".
func TableParentFromStreamName(streamName string) string
TableParentFromStreamName is a utility function for extracting the parent table prefix from a stream name. When an invalid stream ID is passed, this simply returns the original stream name.
func WithDefaultAppendRowsCallOption(o gax.CallOption) option.ClientOption
WithDefaultAppendRowsCallOption is an EXPERIMENTAL ClientOption for controlling the gax.CallOptions passed when opening the underlying AppendRows bidi stream connections used by this library to communicate with the BigQuery Storage service. This option is propagated to all connections created by the instantiated Client.
Note: the WithAppendRowsCallOption WriterOption can still be used to control the behavior for individual ManagedStream writers that don't participate in multiplexing.
This ClientOption is EXPERIMENTAL and subject to change.
func WithDefaultInflightBytes(n int) option.ClientOption
WithDefaultInflightBytes is an EXPERIMENTAL ClientOption for controlling the default byte limit for how many individual AppendRows write requests can be in flight on a connection at a time. This limit is enforced on all connections created by the instantiated Client.
Note: the WithMaxInflightBytes WriterOption can still be used to control the behavior for individual ManagedStream writers when not using multiplexing.
This ClientOption is EXPERIMENTAL and subject to change.
func WithDefaultInflightRequests(n int) option.ClientOption
WithDefaultInflightRequests is an EXPERIMENTAL ClientOption for controlling the default limit of how many individual AppendRows write requests can be in flight on a connection at a time. This limit is enforced on all connections created by the instantiated Client.
Note: the WithMaxInflightRequests WriterOption can still be used to control the behavior for individual ManagedStream writers when not using multiplexing.
This ClientOption is EXPERIMENTAL and subject to change.
func WithMultiplexPoolLimit(maxSize int) option.ClientOption
WithMultiplexPoolLimit is an EXPERIMENTAL option that sets the maximum shared multiplex pool size when instantiating the Client. If multiplexing is not enabled, this setting is ignored. By default, the limit is a single shared connection. This limit is applied per destination region.
This ClientOption is EXPERIMENTAL and subject to change.
func WithMultiplexing() option.ClientOption
WithMultiplexing is an EXPERIMENTAL option that controls connection sharing when instantiating the Client. Only writes to default streams can leverage the multiplex pool. Internally, the client maintains a pool of connections per BigQuery destination region, and will grow the pool to it's maximum allowed size if there's sufficient traffic on the shared connection(s).
This ClientOption is EXPERIMENTAL and subject to change.
AppendOption are options that can be passed when appending data with a managed stream instance.
type AppendOption func(*pendingWrite)
func UpdateDefaultMissingValueInterpretation(def storagepb.AppendRowsRequest_MissingValueInterpretation) AppendOption
UpdateDefaultMissingValueInterpretation updates the default intepretations setting for the stream, and is retained for subsequent writes. See the WithDefaultMissingValueInterpretations WriterOption for more details.
func UpdateMissingValueInterpretations(mvi map[string]storagepb.AppendRowsRequest_MissingValueInterpretation) AppendOption
UpdateMissingValueInterpretations updates the per-column missing-value intepretations settings, and is retained for subsequent writes. See the WithMissingValueInterpretations WriterOption for more details.
func UpdateSchemaDescriptor(schema *descriptorpb.DescriptorProto) AppendOption
UpdateSchemaDescriptor is used to update the descriptor message schema associated with a given stream.
func WithOffset(offset int64) AppendOption
WithOffset sets an explicit offset value for this append request.
AppendResult tracks the status of a batch of data rows.
type AppendResult struct {
// contains filtered or unexported fields
}
func (ar *AppendResult) FullResponse(ctx context.Context) (*storagepb.AppendRowsResponse, error)
FullResponse returns the full content of the AppendRowsResponse, and any error encountered while processing the append.
The AppendRowResponse may contain an embedded error. An embedded error in the response will be converted and returned as the error response, so this method may return both the AppendRowsResponse and an error.
This call blocks until the result is ready, or context is no longer valid.
func (ar *AppendResult) GetResult(ctx context.Context) (int64, error)
GetResult returns the optional offset of this row, as well as any error encountered while processing the append.
This call blocks until the result is ready, or context is no longer valid.
func (ar *AppendResult) Ready() <-chan struct{}
Ready blocks until the append request has reached a completed state, which may be a successful append or an error.
func (ar *AppendResult) TotalAttempts(ctx context.Context) (int, error)
TotalAttempts returns the number of times this write was attempted.
This call blocks until the result is ready, or context is no longer valid.
func (ar *AppendResult) UpdatedSchema(ctx context.Context) (*storagepb.TableSchema, error)
UpdatedSchema returns the updated schema for a table if supplied by the backend as part of the append response.
This call blocks until the result is ready, or context is no longer valid.
Client is a managed BigQuery Storage write client scoped to a single project.
type Client struct {
// contains filtered or unexported fields
}
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (c *Client, err error)
NewClient instantiates a new client.
The context provided here is retained and used for background connection management between the client and the BigQuery Storage service.
func (c *Client) BatchCommitWriteStreams(ctx context.Context, req *storagepb.BatchCommitWriteStreamsRequest, opts ...gax.CallOption) (*storagepb.BatchCommitWriteStreamsResponse, error)
BatchCommitWriteStreams atomically commits a group of PENDING streams that belong to the same parent table.
Streams must be finalized before commit and cannot be committed multiple times. Once a stream is committed, data in the stream becomes available for read operations.
func (c *Client) Close() error
Close releases resources held by the client.
func (c *Client) CreateWriteStream(ctx context.Context, req *storagepb.CreateWriteStreamRequest, opts ...gax.CallOption) (*storagepb.WriteStream, error)
CreateWriteStream creates a write stream to the given table. Additionally, every table has a special stream named ‘_default’ to which data can be written. This stream doesn’t need to be created using CreateWriteStream. It is a stream that can be used simultaneously by any number of clients. Data written to this stream is considered committed as soon as an acknowledgement is received.
func (c *Client) GetWriteStream(ctx context.Context, req *storagepb.GetWriteStreamRequest, opts ...gax.CallOption) (*storagepb.WriteStream, error)
GetWriteStream returns information about a given WriteStream.
func (c *Client) NewManagedStream(ctx context.Context, opts ...WriterOption) (*ManagedStream, error)
NewManagedStream establishes a new managed stream for appending data into a table.
Context here is retained for use by the underlying streaming connections the managed stream may create.
ManagedStream is the abstraction over a single write stream.
type ManagedStream struct {
// contains filtered or unexported fields
}
func (ms *ManagedStream) AppendRows(ctx context.Context, data [][]byte, opts ...AppendOption) (*AppendResult, error)
AppendRows sends the append requests to the service, and returns a single AppendResult for tracking the set of data.
The format of the row data is binary serialized protocol buffer bytes. The message must be compatible with the schema currently set for the stream.
Use the WithOffset() AppendOption to set an explicit offset for this append. Setting an offset for a default stream is unsupported.
The size of a single request must be less than 10 MB in size. Requests larger than this return an error, typically `INVALID_ARGUMENT`.
func (ms *ManagedStream) Close() error
Close closes a managed stream.
func (ms *ManagedStream) Finalize(ctx context.Context, opts ...gax.CallOption) (int64, error)
Finalize is used to mark a stream as complete, and thus ensure no further data can be appended to the stream. You cannot finalize a DefaultStream, as it always exists.
Finalizing does not advance the current offset of a BufferedStream, nor does it commit data in a PendingStream.
func (ms *ManagedStream) FlushRows(ctx context.Context, offset int64, opts ...gax.CallOption) (int64, error)
FlushRows advances the offset at which rows in a BufferedStream are visible. Calling this method for other stream types yields an error.
func (ms *ManagedStream) StreamName() string
StreamName returns the corresponding write stream ID being managed by this writer.
func (ms *ManagedStream) StreamType() StreamType
StreamType returns the configured type for this stream.
StreamType indicates the type of stream this write client is managing.
type StreamType string
var ( // DefaultStream most closely mimics the legacy bigquery // tabledata.insertAll semantics. Successful inserts are // committed immediately, and there's no tracking offsets as // all writes go into a "default" stream that always exists // for a table. DefaultStream StreamType = "DEFAULT" // CommittedStream appends data immediately, but creates a // discrete stream for the work so that offset tracking can // be used to track writes. CommittedStream StreamType = "COMMITTED" // BufferedStream is a form of checkpointed stream, that allows // you to advance the offset of visible rows via Flush operations. BufferedStream StreamType = "BUFFERED" // PendingStream is a stream in which no data is made visible to // readers until the stream is finalized and committed explicitly. PendingStream StreamType = "PENDING" )
WriterOption are variadic options used to configure a ManagedStream instance.
type WriterOption func(*ManagedStream)
func EnableWriteRetries(enable bool) WriterOption
EnableWriteRetries enables ManagedStream to automatically retry failed appends.
Enabling retries is best suited for cases where users want to achieve at-least-once append semantics. Use of automatic retries may complicate patterns where the user is designing for exactly-once append semantics.
func WithAppendRowsCallOption(o gax.CallOption) WriterOption
WithAppendRowsCallOption is used to supply additional call options to the ManagedStream when it opens the underlying append stream.
Note: See the DefaultAppendRowsCallOption ClientOption for setting defaults when instantiating a client, rather than setting this limit per-writer. This WriterOption is ignored for ManagedStream writers that participate in multiplexing.
func WithDataOrigin(dataOrigin string) WriterOption
WithDataOrigin is used to attach an origin context to the instrumentation metrics emitted by the library.
func WithDefaultMissingValueInterpretation(def storagepb.AppendRowsRequest_MissingValueInterpretation) WriterOption
WithDefaultMissingValueInterpretation controls how missing values are interpreted by for a given stream. See WithMissingValueIntepretations for more information about missing values.
WithMissingValueIntepretations set for individual colums can override the default chosen with this option.
For example, if you want to write `NULL` instead of using default values for some columns, you can set `default_missing_value_interpretation` to `DEFAULT_VALUE` and at the same time, set `missing_value_interpretations` to `NULL_VALUE` on those columns.
func WithDestinationTable(destTable string) WriterOption
WithDestinationTable specifies the destination table to which a created stream will append rows. Format of the table:
projects/{projectid}/datasets/{dataset}/tables/{table}
func WithMaxInflightBytes(n int) WriterOption
WithMaxInflightBytes bounds the inflight append request bytes on the write connection.
Note: See the WithDefaultInflightBytes ClientOption for setting a default when instantiating a client, rather than setting this limit per-writer. This WriterOption is ignored for ManagedStreams that participate in multiplexing.
func WithMaxInflightRequests(n int) WriterOption
WithMaxInflightRequests bounds the inflight appends on the write connection.
Note: See the WithDefaultInflightRequests ClientOption for setting a default when instantiating a client, rather than setting this limit per-writer. This WriterOption is ignored for ManagedStreams that participate in multiplexing.
func WithMissingValueInterpretations(mvi map[string]storagepb.AppendRowsRequest_MissingValueInterpretation) WriterOption
WithMissingValueInterpretations controls how missing values are interpreted for individual columns.
You must provide a map to indicate how to interpret missing value for some fields. Missing values are fields present in user schema but missing in rows. The key is the field name. The value is the interpretation of missing values for the field.
For example, the following option would indicate that missing values in the "foo" column are interpreted as null, whereas missing values in the "bar" column are treated as the default value:
WithMissingValueInterpretations(map[string]storagepb.AppendRowsRequest_MissingValueInterpretation{ "foo": storagepb.AppendRowsRequest_DEFAULT_VALUE, "bar": storagepb.AppendRowsRequest_NULL_VALUE, })
If a field is not in this map and has missing values, the missing values in this field are interpreted as NULL unless overridden with a default missing value interpretation.
Currently, field name can only be top-level column name, can't be a struct field path like 'foo.bar'.
func WithSchemaDescriptor(dp *descriptorpb.DescriptorProto) WriterOption
WithSchemaDescriptor describes the format of the serialized data being sent by AppendRows calls on the stream.
func WithStreamName(name string) WriterOption
WithStreamName allows users to set the stream name this writer will append to explicitly. By default, the managed client will create the stream when instantiated if necessary.
Note: Supplying this option causes other options which affect stream construction such as WithStreamType and WithDestinationTable to be ignored.
func WithTraceID(traceID string) WriterOption
WithTraceID allows instruments requests to the service with a custom trace prefix. This is generally for diagnostic purposes only.
func WithType(st StreamType) WriterOption
WithType sets the stream type for the managed stream.