bigquery

package
v1.186.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package bigquery contains a client to query BigQuery quicker & safely.

Index

Constants

View Source
const (
	// DefaultPageSize if not specified.
	DefaultPageSize = 50

	// MaxPageSize we can ask for in the pagination.
	MaxPageSize = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v1.55.0

type Client struct {
	// contains filtered or unexported fields
}

Client holds a connection to the BigQuery service.

func NewClient added in v1.55.0

func NewClient(googleProject string, dataset Dataset) (*Client, error)

NewClient opens a new connection to the BigQuery service.

func (*Client) Inserter added in v1.55.0

func (client *Client) Inserter(table Table) *Inserter

Inserter returns a helper to insert new rows into the table.

func (*Client) Query added in v1.55.0

func (client *Client) Query(query *Query) *Pager

Query prepares a new paginator for the query.

type Condition added in v1.55.0

type Condition struct {
	// contains filtered or unexported fields
}

Condition is a filter condition of a query.

func ConditionAnd added in v1.55.0

func ConditionAnd() *Condition

ConditionAnd builds a new condition where all the members are merged with the AND operator.

func ConditionOr added in v1.55.0

func ConditionOr() *Condition

ConditionAnd builds a new condition where all the members are merged with the OR operator.

func (*Condition) Clone added in v1.55.0

func (c *Condition) Clone() *Condition

Clone returns a copy of the condition.

func (*Condition) Filter added in v1.55.0

func (c *Condition) Filter(filter string, values ...interface{}) *Condition

Filter builds a new condition adding the filter we specify. Examples:

.Filter("foo", 3)
.Filter("foo >", 3)
.Filter("foo BETWEEN ? AND ?", 3, 4)

func (*Condition) FilterCond added in v1.55.0

func (c *Condition) FilterCond(child *Condition) *Condition

FilterCond builds a new condition adding the new child condition we specify here. Examples:

cond := ConditionOr()
cond = cond.Filter("foo", 3)
cond = cond.Filter("bar", 4)
.FilterCond(cond)

type Dataset added in v1.55.0

type Dataset string

Dataset represents a BigQuery dataset name.

type Inserter added in v1.55.0

type Inserter = bigquery.Inserter

Inserter helps with batch insertion of new rows in a table.

type Pager added in v1.55.0

type Pager struct {
	// NextPageToken is the token of the next page, or empty if there is no more
	// results. It is filled after the call to Fetch.
	NextPageToken string

	// TotalSize is the total number of results the job has returned. It is filled
	// after the call to Fetch.
	TotalSize int32
	// contains filtered or unexported fields
}

Pager helps when retrieving paginated results.

func (*Pager) Fetch added in v1.55.0

func (pager *Pager) Fetch(ctx context.Context, models interface{}) error

Fetch retrieves the next page of results. Pass a pointer to an empty slice of the type of model you need to read.

func (*Pager) SetInputs added in v1.55.0

func (pager *Pager) SetInputs(pageToken string, pageSize int32)

SetInputs fills the pagination inputs we receive from the client.

type Query added in v1.55.0

type Query struct {
	// contains filtered or unexported fields
}

Query is a SQL builder for BigQuery queries.

func NewQuery added in v1.55.0

func NewQuery(table Table, opts ...QueryOption) *Query

NewQuery builds a new query to the table.

There is a required option for all tables: Select(...) For partitioned tables there is another required option: WithPartitionRange(...)

func (*Query) Checksum added in v1.55.0

func (q *Query) Checksum(dataset Dataset, pageSize int32) uint32

Checksum returns a checksum of the filters, conditions, table name, ... and other internal data of the collection that identifies it. It won't include the columns, so you can add or remove them without busting the checksums.

func (*Query) Clone added in v1.55.0

func (q *Query) Clone() *Query

Clone returns a copy of the query.

func (*Query) Filter added in v1.55.0

func (q *Query) Filter(filter string, value interface{}) *Query

Filter adds a new WHERE condition directly to the query. All the query conditions will be combined with the AND operator.

func (*Query) FilterCond added in v1.55.0

func (q *Query) FilterCond(cond *Condition) *Query

FilterCond adds a new child condition directly to the query. All the children query conditions will be combined with the AND operator.

func (*Query) Limit added in v1.55.0

func (q *Query) Limit(limit int64) *Query

Limit sets the limit of results to be returned.

func (*Query) OrderBy added in v1.55.0

func (q *Query) OrderBy(column string) *Query

OrderBy sets the order the results will be returned.

func (*Query) String added in v1.55.0

func (q *Query) String() string

String returns a human representation of the query to pretty print it.

type QueryOption added in v1.55.0

type QueryOption func(q *Query)

QueryOption are options we can configure in a query.

func Select added in v1.55.0

func Select(cols ...string) QueryOption

Select the columns to return in the query. This is a required option in all queries because there is no sane default to not consume BigQuery quota.

func WithPartitionRange added in v1.55.0

func WithPartitionRange(start, end time.Time) QueryOption

WithPartitionRange controls the range of partitions we want to query in a table to save money not processing unnecessary data.

The range is according to API standards, that is: [start, end)

type StructSaver

type StructSaver = bigquery.StructSaver

StructSaver helps with struct insertion in a table.

type Table added in v1.55.0

type Table string

Table represents a BigQuery table name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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