bqutil

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package bqutil provides utils to interact with BigQuery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RetryQueryEntries

func RetryQueryEntries[T any](ctx context.Context, q Query[T], wantCount int, backoff retry.Backoff) ([]T, error)

RetryQueryEntries retries the given Query until either the query result returns "wantCount" number of entries or the retry backoff is exhausted (and returns error). The returned result size is guaranteed to be greater or equal to "wantCount".

To collect result in custom Go struct:

type queryResult struct {
	ColNameX, ColNameY string
}

q := NewQuery[*queryResult](bigqueryQuery)
backoff := retry.WithMaxRetries(3, retry.NewConstant(time.Second))
result, err := RetryQueryEntries(context.Background(), q, 1, backoff)
// result will be in type []*queryResult

To use this func in testing:

// Set the test logger in the context on the debug level.
ctx := logging.WithLogger(context.Background(),
	logging.TestLogger(t, zaptest.Level(zapcore.DebugLevel)))

q := NewQuery[*queryResult](bigqueryQuery)
backoff := retry.WithMaxRetries(3, retry.NewConstant(time.Second))
result, err := RetryQueryEntries(ctx, q, 1, backoff)

Types

type Query

type Query[T any] interface {
	// Execute runs the query and returns the result in type []*T.
	Execute(context.Context) ([]T, error)

	// String returns the underlying query string.
	String() string
}

Query is the interface to execute a query.

func NewQuery

func NewQuery[T any](q *bigquery.Query) Query[T]

NewQuery creates a new BigQuery query.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL