Documentation ¶
Overview ¶
Package bigquery provides a client for reading and writing to BigQuery.
Index ¶
- Variables
- func AddTable(tableID string, s bq.Schema)
- func All[T any](iter *bq.RowIterator) ([]*T, error)
- func CreateDataset(ctx context.Context, projectID, datasetID string) (err error)
- func ForEachRow[T any](iter *bq.RowIterator, f func(*T) bool) error
- func NullFloat(f float64) bq.NullFloat64
- func NullInt(i int) bq.NullInt64
- func NullString(s string) bq.NullString
- func NullTime(t time.Time) bq.NullTime
- func SchemaString(schema bq.Schema) string
- func SchemaVersion(schema bq.Schema) string
- func TableSchema(tableID string) bq.Schema
- func UploadMany[T Row](ctx context.Context, client *Client, tableID string, rows []T, chunkSize int) (err error)
- type Client
- func (c *Client) Close() (err error)
- func (c *Client) CreateOrUpdateTable(ctx context.Context, tableID string) (created bool, err error)
- func (c *Client) Dataset() *bq.Dataset
- func (c *Client) FullTableName(tableID string) string
- func (c *Client) Query(ctx context.Context, q string) (*bq.RowIterator, error)
- func (c *Client) Table(tableID string) *bq.Table
- func (c *Client) Upload(ctx context.Context, tableID string, row Row) (err error)
- type PartitionQuery
- type Row
Constants ¶
This section is empty.
Variables ¶
var InferSchema = bq.InferSchema
InferSchema is a copy of cloud.google.com/go/bigquery.InferSchema so users don't have to import cloud.google.com/go/bigquery just to get it.
Functions ¶
func All ¶
func All[T any](iter *bq.RowIterator) ([]*T, error)
All returns all rows returned by iter.
func CreateDataset ¶
CreateDataset creates a BigQuery dataset if it does not already exist.
func ForEachRow ¶
func ForEachRow[T any](iter *bq.RowIterator, f func(*T) bool) error
ForEachRow calls f for each row in the given iterator. It returns as soon as f returns false.
func SchemaString ¶
SchemaString returns a long, human-readable string summarizing schema.
func SchemaVersion ¶
SchemaVersion computes a relatively short string from a schema, such that different schemas result in different strings with high probability.
func TableSchema ¶
TableSchema returns the schema associated with the given table, or nil if there is none.
func UploadMany ¶
func UploadMany[T Row](ctx context.Context, client *Client, tableID string, rows []T, chunkSize int) (err error)
UploadMany inserts multiple rows into the table. Each row should be a struct pointer. The chunkSize parameter limits the number of rows sent in a single request; this may be necessary to avoid reaching the maximum size of a request. If chunkSize is <= 0, all rows will be sent in one request.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for connecting to BigQuery.
func NewClientCreate ¶
NewClientCreate creates a new client for connecting to BigQuery, referring to a single dataset. It creates the dataset if it doesn't exist.
func NewClientForTesting ¶
NewClientForTesting creates a client with a new, unique dataset. Closing the client deletes the dataset.
func (*Client) CreateOrUpdateTable ¶
CreateOrUpdateTable creates a table if it does not exist, or updates it if it does. It returns true if it created the table.
func (*Client) FullTableName ¶
FullTableName returns the fully-qualified name of the table, suitable for use in queries.
type PartitionQuery ¶
type PartitionQuery struct { From string // should use full table name Columns string // comma-separated columns to select, or "*" ("" => "*") PartitionOn string // comma-separated columns defining the partition Where string // WHERE clause OrderBy string // text after ORDER BY: comma-separated columns, each }
PartitionQuery describes a query that returns one row for each distinct value of the partition columns in the given table.
The selected row will be the first one according to the OrderBy clauses.
For example, say the students table holds student names and classes. Then
PartitionQuery{ Table: "students", PartitionOn: "class", OrderBy: "name ASC", }.String()
will construct a query returning the student in each class whose name is alphabetically first.
(BigQuery SQL has no DISTINCT ON feature and doesn't allow columns of type RECORD in queries with DISTINCT, so we have to take this approach.)
func (PartitionQuery) String ¶
func (q PartitionQuery) String() string