bigquery

package
v0.0.0-...-25a572b Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package bigquery provides a client for reading and writing to BigQuery.

Index

Constants

This section is empty.

Variables

View Source
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 AddTable

func AddTable(tableID string, s bq.Schema)

AddTable records the schema for a table, so table creation just needs the name.

func All

func All[T any](iter *bq.RowIterator) ([]*T, error)

All returns all rows returned by iter.

func CreateDataset

func CreateDataset(ctx context.Context, projectID, datasetID string) (err error)

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 NullFloat

func NullFloat(f float64) bq.NullFloat64

NullFloat constructs a bq.NullFloat64

func NullInt

func NullInt(i int) bq.NullInt64

NullInt constructs a bq.NullInt.

func NullString

func NullString(s string) bq.NullString

NullString constructs a bq.NullString.

func NullTime

func NullTime(t time.Time) bq.NullTime

NullTime constructs a bq.NullTime.

func SchemaString

func SchemaString(schema bq.Schema) string

SchemaString returns a long, human-readable string summarizing schema.

func SchemaVersion

func SchemaVersion(schema bq.Schema) string

SchemaVersion computes a relatively short string from a schema, such that different schemas result in different strings with high probability.

func TableSchema

func TableSchema(tableID string) bq.Schema

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

func NewClientCreate(ctx context.Context, projectID, datasetID string) (_ *Client, err error)

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

func NewClientForTesting(ctx context.Context, projectID, testID string) (*Client, error)

NewClientForTesting creates a client with a new, unique dataset. Closing the client deletes the dataset.

func (*Client) Close

func (c *Client) Close() (err error)

func (*Client) CreateOrUpdateTable

func (c *Client) CreateOrUpdateTable(ctx context.Context, tableID string) (created bool, err error)

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) Dataset

func (c *Client) Dataset() *bq.Dataset

Dataset returns the underlying client dataset.

func (*Client) FullTableName

func (c *Client) FullTableName(tableID string) string

FullTableName returns the fully-qualified name of the table, suitable for use in queries.

func (*Client) Query

func (c *Client) Query(ctx context.Context, q string) (*bq.RowIterator, error)

func (*Client) Table

func (c *Client) Table(tableID string) *bq.Table

Table returns a handle for the given tableID in the client's dataset.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, tableID string, row Row) (err error)

Upload inserts a row into the table.

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

type Row

type Row interface {
	SetUploadTime(time.Time)
}

A Row is something that can be uploaded to BigQuery.

Jump to

Keyboard shortcuts

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