Movatterモバイル変換


[0]ホーム

URL:


bigquery

packagemodule
v1.72.0Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License:Apache-2.0Imports:50Imported by:1,407

Details

Repository

github.com/googleapis/google-cloud-go

Links

README

BigQueryGo Reference

Example Usage

First create abigquery.Client to use throughout your application:[snip]:# (bq-1)

c, err := bigquery.NewClient(ctx, "my-project-ID")if err != nil {// TODO: Handle error.}

Then use that client to interact with the API:[snip]:# (bq-2)

// Construct a query.q := c.Query(`    SELECT year, SUM(number)    FROM [bigquery-public-data:usa_names.usa_1910_2013]    WHERE name = "William"    GROUP BY year    ORDER BY year`)// Execute the query.it, err := q.Read(ctx)if err != nil {// TODO: Handle error.}// Iterate through the results.for {var values []bigquery.Valueerr := it.Next(&values)if err == iterator.Done {  // from "google.golang.org/api/iterator"break}if err != nil {// TODO: Handle error.}fmt.Println(values)}

Documentation

Overview

Package bigquery provides a client for the BigQuery service.

The following assumes a basic familiarity with BigQuery concepts.Seehttps://cloud.google.com/bigquery/docs.

Seehttps://godoc.org/cloud.google.com/go for authentication, timeouts,connection pooling and similar aspects of this package.

Creating a Client

To start working with this package, create a client withNewClient:

ctx := context.Background()client, err := bigquery.NewClient(ctx, projectID)if err != nil {    // TODO: Handle error.}

Querying

To query existing tables, create aClient.Query and call itsQuery.Read method, which starts thequery and waits for it to complete:

q := client.Query(`    SELECT year, SUM(number) as num    FROM bigquery-public-data.usa_names.usa_1910_2013    WHERE name = @name    GROUP BY year    ORDER BY year`)q.Parameters = []bigquery.QueryParameter{{Name: "name", Value: "William"},}it, err := q.Read(ctx)if err != nil {    // TODO: Handle error.}

Then iterate through the resulting rows. You can store a row usinganything that implements theValueLoader interface, or with a slice or map ofValue.A slice is simplest:

for {    var values []bigquery.Value    err := it.Next(&values)    if err == iterator.Done {        break    }    if err != nil {        // TODO: Handle error.    }    fmt.Println(values)}

You can also use a struct whose exported fields match the query:

type Count struct {    Year int    Num  int}for {    var c Count    err := it.Next(&c)    if err == iterator.Done {        break    }    if err != nil {        // TODO: Handle error.    }    fmt.Println(c)}

You can also start the query running and get the results later.Create the query as above, but callQuery.Run instead ofQuery.Read. This returns aJob,which represents an asynchronous operation.

job, err := q.Run(ctx)if err != nil {    // TODO: Handle error.}

Get the job's ID, a printable string. You can save this string to retrievethe results at a later time, even in another process.

jobID := job.ID()fmt.Printf("The job ID is %s\n", jobID)

To retrieve the job's results from the ID, first look up theJob with theClient.JobFromID method:

job, err = client.JobFromID(ctx, jobID)if err != nil {    // TODO: Handle error.}

Use theJob.Read method to obtain an iterator, and loop over the rows.CallingQuery.Read is preferred for queries with a relatively small result set,as it will call BigQuery jobs.query API for a optimized query path. If the querydoesn't meet that criteria, the method will just combineQuery.Run andJob.Read.

it, err = job.Read(ctx)if err != nil {    // TODO: Handle error.}// Proceed with iteration as above.

Datasets and Tables

You can refer to datasets in the client's project with theClient.Dataset method, andin other projects with theClient.DatasetInProject method:

myDataset := client.Dataset("my_dataset")yourDataset := client.DatasetInProject("your-project-id", "your_dataset")

These methods create references to datasets, not the datasets themselves. You can havea dataset reference even if the dataset doesn't exist yet. UseDataset.Create tocreate a dataset from a reference:

if err := myDataset.Create(ctx, nil); err != nil {    // TODO: Handle error.}

You can refer to tables withDataset.Table. LikeDataset,Table is a referenceto an object in BigQuery that may or may not exist.

table := myDataset.Table("my_table")

You can create, delete and update the metadata of tables with methods onTable.For instance, you could create a temporary table with:

err = myDataset.Table("temp").Create(ctx, &bigquery.TableMetadata{    ExpirationTime: time.Now().Add(1*time.Hour)})if err != nil {    // TODO: Handle error.}

We'll see how to create a table with a schema in the next section.

Schemas

There are two ways to construct schemas with this package.You can build a schema by hand with theSchema struct, like so:

schema1 := bigquery.Schema{    {Name: "Name", Required: true, Type: bigquery.StringFieldType},    {Name: "Grades", Repeated: true, Type: bigquery.IntegerFieldType},    {Name: "Optional", Required: false, Type: bigquery.IntegerFieldType},}

Or you can infer the schema from a struct with theInferSchema method:

type student struct {    Name   string    Grades []int    Optional bigquery.NullInt64}schema2, err := bigquery.InferSchema(student{})if err != nil {    // TODO: Handle error.}// schema1 and schema2 are identical.

Struct inference supports tags like those of theencoding/json package, so you canchange names, ignore fields, or mark a field as nullable (non-required). Fieldsdeclared as one of the Null types (NullInt64,NullFloat64,NullString,NullBool,NullTimestamp,NullDate,NullTime,NullDateTime,NullGeography, andNullJSON) areautomatically inferred as nullable, so the "nullable" tag is only needed for []byte,*big.Rat and pointer-to-struct fields.

type student2 struct {    Name     string `bigquery:"full_name"`    Grades   []int    Secret   string `bigquery:"-"`    Optional []byte `bigquery:",nullable"`}schema3, err := bigquery.InferSchema(student2{})if err != nil {    // TODO: Handle error.}// schema3 has required fields "full_name" and "Grade", and nullable BYTES field "Optional".

Having constructed a schema, you can create a table with it using theTable.Create method like so:

if err := table.Create(ctx, &bigquery.TableMetadata{Schema: schema1}); err != nil {    // TODO: Handle error.}

Copying

You can copy one or more tables to another table. Begin by constructing aCopierdescribing the copy using theTable.CopierFrom. Then set any desired copy options,and finally callCopier.Run to get aJob:

copier := myDataset.Table("dest").CopierFrom(myDataset.Table("src"))copier.WriteDisposition = bigquery.WriteTruncatejob, err = copier.Run(ctx)if err != nil {    // TODO: Handle error.}

You can chain the call toCopier.Run if you don't want to set options:

job, err = myDataset.Table("dest").CopierFrom(myDataset.Table("src")).Run(ctx)if err != nil {    // TODO: Handle error.}

You can wait for your job to complete with theJob.Wait method:

status, err := job.Wait(ctx)if err != nil {    // TODO: Handle error.}

Job.Wait polls with exponential backoff. You can also poll yourself, if youwish:

for {    status, err := job.Status(ctx)    if err != nil {        // TODO: Handle error.    }    if status.Done() {        if status.Err() != nil {            log.Fatalf("Job failed with error %v", status.Err())        }        break    }    time.Sleep(pollInterval)}

Loading and Uploading

There are two ways to populate a table with this package: load the data from a Google Cloud Storageobject, or upload rows directly from your program.

For loading, first create aGCSReference with theNewGCSReference method, configuring it if desired.Then make aLoader from a table with theTable.LoaderFrom method with the reference,optionally configure it as well, and call itsLoader.Run method.

gcsRef := bigquery.NewGCSReference("gs://my-bucket/my-object")gcsRef.AllowJaggedRows = trueloader := myDataset.Table("dest").LoaderFrom(gcsRef)loader.CreateDisposition = bigquery.CreateNeverjob, err = loader.Run(ctx)// Poll the job for completion if desired, as above.

To upload, first define a type that implements theValueSaver interface, which hasa single method named Save. Then create anInserter, and call itsInserter.Putmethod with a slice of values.

type Item struct {Name  stringSize  float64Count int}// Save implements the ValueSaver interface.func (i *Item) Save() (map[string]bigquery.Value, string, error) {return map[string]bigquery.Value{"Name":  i.Name,"Size":  i.Size,"Count": i.Count,}, "", nil}u := table.Inserter()// Item implements the ValueSaver interface.items := []*Item{    {Name: "n1", Size: 32.6, Count: 7},    {Name: "n2", Size: 4, Count: 2},    {Name: "n3", Size: 101.5, Count: 1},}if err := u.Put(ctx, items); err != nil {    // TODO: Handle error.}

You can also upload a struct that doesn't implementValueSaver. Use theStructSaver typeto specify the schema and insert ID by hand:

type item struct {Name stringNum  int}// Assume schema holds the table's schema.savers := []*bigquery.StructSaver{{Struct: score{Name: "n1", Num: 12}, Schema: schema, InsertID: "id1"},{Struct: score{Name: "n2", Num: 31}, Schema: schema, InsertID: "id2"},{Struct: score{Name: "n3", Num: 7}, Schema: schema, InsertID: "id3"},}if err := u.Put(ctx, savers); err != nil {    // TODO: Handle error.}

Lastly, but not least, you can just supply the struct or struct pointer directly and the schema will be inferred:

type Item2 struct {    Name  string    Size  float64    Count int}// Item2 doesn't implement ValueSaver interface, so schema will be inferred.items2 := []*Item2{    {Name: "n1", Size: 32.6, Count: 7},    {Name: "n2", Size: 4, Count: 2},    {Name: "n3", Size: 101.5, Count: 1},}if err := u.Put(ctx, items2); err != nil {    // TODO: Handle error.}

BigQuery allows for higher throughput when omitting insertion IDs. To enable this,specify the sentinelNoDedupeID value for the insertion ID when implementing aValueSaver.

Extracting

If you've been following so far, extracting data from a BigQuery tableinto a Google Cloud Storage object will feel familiar. First create anExtractor, then optionally configure it, and lastly call itsExtractor.Run method.

extractor := table.ExtractorTo(gcsRef)extractor.DisableHeader = truejob, err = extractor.Run(ctx)// Poll the job for completion if desired, as above.

Errors

Errors returned by this client are often of the typegoogleapi.Error.These errors can be introspected for more information by usingerrors.Aswith the richergoogleapi.Error type. For example:

var e *googleapi.Errorif ok := errors.As(err, &e); ok {  if e.Code == 409 { ... }}

In some cases, your client may received unstructuredgoogleapi.Error error responses. In such cases, it is likely thatyou have exceeded BigQuery request limits, documented at:https://cloud.google.com/bigquery/quotas

Index

Examples

Constants

View Source
const (// LogicalStorageBillingModel indicates billing for logical bytes.LogicalStorageBillingModel = ""// PhysicalStorageBillingModel indicates billing for physical bytes.PhysicalStorageBillingModel = "PHYSICAL")
View Source
const (// ScalarFunctionRoutine scalar function routine typeScalarFunctionRoutine = "SCALAR_FUNCTION"// ProcedureRoutine procedure routine typeProcedureRoutine = "PROCEDURE"// TableValuedFunctionRoutine routine type for table valued functionsTableValuedFunctionRoutine = "TABLE_VALUED_FUNCTION")
View Source
const (// NumericPrecisionDigits is the maximum number of digits in a NUMERIC value.NumericPrecisionDigits = 38// NumericScaleDigits is the maximum number of digits after the decimal point in a NUMERIC value.NumericScaleDigits = 9// BigNumericPrecisionDigits is the maximum number of full digits in a BIGNUMERIC value.BigNumericPrecisionDigits = 76// BigNumericScaleDigits is the maximum number of full digits in a BIGNUMERIC value.BigNumericScaleDigits = 38)
View Source
const DetectProjectID = "*detect-project-id*"

DetectProjectID is a sentinel value that instructsNewClient to detect theproject ID. It is given in place of the projectID argument.NewClient willuse 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 alloptions will allowNewClient to extract the project ID. Specifically a JWTdoes not have the project ID encoded.

View Source
const NoDedupeID = "NoDedupeID"

NoDedupeID indicates a streaming insert row wants to opt out of best-effortdeduplication.It is EXPERIMENTAL and subject to change or removal without notice.

View Source
const (// Scope is the Oauth2 scope for the service.// For relevant BigQuery scopes, see://https://developers.google.com/identity/protocols/googlescopes#bigqueryv2Scope = "https://www.googleapis.com/auth/bigquery")

Variables

View Source
var NeverExpire =time.Time{}.Add(-1)

NeverExpire is a sentinel value used to remove a table'e expiration time.

Functions

funcBigNumericStringadded inv1.14.0

func BigNumericString(r *big.Rat)string

BigNumericString returns a string representing a *big.Rat in a format compatible with BigQuerySQL. It returns a floating point literal with 38 digits after the decimal point.

funcCivilDateTimeString

func CivilDateTimeString(dtcivil.DateTime)string

CivilDateTimeString returns a string representing a civil.DateTime in a format compatiblewith BigQuery SQL. It separate the date and time with a space, and formats the timewith CivilTimeString.

Use CivilDateTimeString when using civil.DateTime in DML, for example in INSERTstatements.

funcCivilTimeString

func CivilTimeString(tcivil.Time)string

CivilTimeString returns a string representing a civil.Time in a format compatiblewith BigQuery SQL. It rounds the time to the nearest microsecond and returns astring with six digits of sub-second precision.

Use CivilTimeString when using civil.Time in DML, for example in INSERTstatements.

funcIntervalStringadded inv1.32.0

func IntervalString(iv *IntervalValue)string

IntervalString returns a string representing an *IntervalValue in a format compatible withBigQuery SQL. It returns an interval literal in canonical format.

funcNewArrowIteratorReaderadded inv1.57.0

func NewArrowIteratorReader(itArrowIterator)io.Reader

NewArrowIteratorReader allows to consume an ArrowIterator as an io.Reader.Experimental: this interface is experimental and may be modified or removed in future versions,regardless of any other documented package stability guarantees.

funcNumericString

func NumericString(r *big.Rat)string

NumericString returns a string representing a *big.Rat in a format compatiblewith BigQuery SQL. It returns a floating-point literal with 9 digitsafter the decimal point.

funcSeed

func Seed(sint64)

Seed seeds this package's random number generator, used for generating job andinsert IDs. Use Seed to obtain repeatable, deterministic behavior from bigqueryclients. Seed should be called before any clients are created.

funcWithDefaultJobCreationModeadded inv1.69.0

func WithDefaultJobCreationMode(modeJobCreationMode)option.ClientOption

WithDefaultJobCreationMode is a ClientOption that governs the job creationmode used when executing queries that can be accelerated via the jobs.QueryAPI. Users may experience performance improvements by leveraging theJobCreationModeOptional mode.

Types

typeAccessEntry

type AccessEntry struct {RoleAccessRole// The role of the entityEntityTypeEntityType// The type of entityEntitystring// The entity (individual or group) granted accessView       *Table// The view granted access (EntityType must be ViewEntity)Routine    *Routine// The routine granted access (only UDF currently supported)Dataset    *DatasetAccessEntry// The resources within a dataset granted access.Condition  *Expr// Condition for the access binding.}

An AccessEntry describes the permissions that an entity has on a dataset.

typeAccessRole

type AccessRolestring

AccessRole is the level of access to grant to a dataset.

const (// OwnerRole is the OWNER AccessRole.OwnerRoleAccessRole = "OWNER"// ReaderRole is the READER AccessRole.ReaderRoleAccessRole = "READER"// WriterRole is the WRITER AccessRole.WriterRoleAccessRole = "WRITER")

typeArrowIteratoradded inv1.57.0

type ArrowIterator interface {Next() (*ArrowRecordBatch,error)Schema()SchemaSerializedArrowSchema() []byte}

ArrowIterator represents a way to iterate through a stream of arrow records.Experimental: this interface is experimental and may be modified or removed in future versions,regardless of any other documented package stability guarantees.

typeArrowRecordBatchadded inv1.57.0

type ArrowRecordBatch struct {// Serialized Arrow Record Batch.Data []byte// Serialized Arrow Schema.Schema []byte// Source partition ID. In the Storage API world, it represents the ReadStream.PartitionIDstring// contains filtered or unexported fields}

ArrowRecordBatch represents an Arrow RecordBatch with the source PartitionID

func (*ArrowRecordBatch)Readadded inv1.57.0

func (r *ArrowRecordBatch) Read(p []byte) (int,error)

Read makes ArrowRecordBatch implements io.Reader

typeAvroOptionsadded inv1.25.0

type AvroOptions struct {// UseAvroLogicalTypes indicates whether to interpret logical types as the// corresponding BigQuery data type (for example, TIMESTAMP), instead of using// the raw type (for example, INTEGER).UseAvroLogicalTypesbool}

AvroOptions are additional options for Avro external data data sources.

typeBIEngineReasonadded inv1.25.0

type BIEngineReason struct {// High-Level BI engine reason for partial or disabled acceleration.Codestring// Human-readable reason for partial or disabled acceleration.Messagestring}

BIEngineReason contains more detailed information about why a query wasn't fullyaccelerated.

typeBIEngineStatisticsadded inv1.25.0

type BIEngineStatistics struct {// Specifies which mode of BI Engine acceleration was performed.BIEngineModestring// In case of DISABLED or PARTIAL BIEngineMode, these// contain the explanatory reasons as to why BI Engine could not// accelerate. In case the full query was accelerated, this field is not// populated.BIEngineReasons []*BIEngineReason}

BIEngineStatistics contains query statistics specific to the use of BI Engine.

typeBigLakeConfigurationadded inv1.68.0

type BigLakeConfiguration struct {// Optional. The connection specifying the credentials to be used to read and// write to external storage, such as Cloud Storage. The connection_id can// have the form `{project}.{location}.{connection_id}` or// `projects/{project}/locations/{location}/connections/{connection_id}".ConnectionIDstring// Optional. The fully qualified location prefix of the external folder where// table data is stored. The '*' wildcard character is not allowed. The URI// should be in the format `gs://bucket/path_to_table/`StorageURIstring// Optional. The file format the table data is stored in.FileFormatBigLakeFileFormat// Optional. The table format the metadata only snapshots are stored in.TableFormatBigLakeTableFormat}

BigLakeConfiguration is used to configure aspects of BigQuery tables forApache Iceberg (previously known as BigLake managed tables).

typeBigLakeFileFormatadded inv1.68.0

type BigLakeFileFormatstring

BigLakeFileFormat represents the file format for Managed Tables for Apache Iceberg.

var (// UnspecifiedBigLakeFileFormat represents the default value.UnspecifiedBigLakeFileFormatBigLakeFileFormat = "FILE_FORMAT_UNSPECIFIED"// ParquetBigLakeFileFormat represents Apache Parquet Format.ParquetBigLakeFileFormatBigLakeFileFormat = "PARQUET")

typeBigLakeTableFormatadded inv1.68.0

type BigLakeTableFormatstring

BigLakeTableFormat represents the table metadata format for Managed Tables for Apache Iceberg.

var (// UnspecifiedBigLakeTableFormat represents the default value.UnspecifiedBigLakeTableFormatBigLakeTableFormat = "TABLE_FORMAT_UNSPECIFIED"// IcebergBigLakeTableFormat represent Apache Iceberg Format.IcebergBigLakeTableFormatBigLakeTableFormat = "ICEBERG")

typeBigtableColumn

type BigtableColumn struct {// Qualifier of the column. Columns in the parent column family that have this// exact qualifier are exposed as . field. The column field name is the// same as the column qualifier.Qualifierstring// If the qualifier is not a valid BigQuery field identifier i.e. does not match// [a-zA-Z][a-zA-Z0-9_]*, a valid identifier must be provided as the column field// name and is used as field name in queries.FieldNamestring// If true, only the latest version of values are exposed for this column.// See BigtableColumnFamily.OnlyReadLatest.OnlyReadLatestbool// The encoding of the values when the type is not STRING.// See BigtableColumnFamily.EncodingEncodingstring// The type to convert the value in cells of this column.// See BigtableColumnFamily.TypeTypestring}

BigtableColumn describes how BigQuery should access a Bigtable column.

typeBigtableColumnFamily

type BigtableColumnFamily struct {// Identifier of the column family.FamilyIDstring// Lists of columns that should be exposed as individual fields as opposed to a// list of (column name, value) pairs. All columns whose qualifier matches a// qualifier in this list can be accessed as .. Other columns can be accessed as// a list through .Column field.Columns []*BigtableColumn// The encoding of the values when the type is not STRING. Acceptable encoding values are:// - TEXT - indicates values are alphanumeric text strings.// - BINARY - indicates values are encoded using HBase Bytes.toBytes family of functions.// This can be overridden for a specific column by listing that column in 'columns' and// specifying an encoding for it.Encodingstring// If true, only the latest version of values are exposed for all columns in this// column family. This can be overridden for a specific column by listing that// column in 'columns' and specifying a different setting for that column.OnlyReadLatestbool// The type to convert the value in cells of this// column family. The values are expected to be encoded using HBase// Bytes.toBytes function when using the BINARY encoding value.// Following BigQuery types are allowed (case-sensitive):// BYTES STRING INTEGER FLOAT BOOLEAN.// The default type is BYTES. This can be overridden for a specific column by// listing that column in 'columns' and specifying a type for it.Typestring}

BigtableColumnFamily describes how BigQuery should access a Bigtable column family.

typeBigtableOptions

type BigtableOptions struct {// A list of column families to expose in the table schema along with their// types. If omitted, all column families are present in the table schema and// their values are read as BYTES.ColumnFamilies []*BigtableColumnFamily// If true, then the column families that are not specified in columnFamilies// list are not exposed in the table schema. Otherwise, they are read with BYTES// type values. The default is false.IgnoreUnspecifiedColumnFamiliesbool// If true, then the rowkey column families will be read and converted to string.// Otherwise they are read with BYTES type values and users need to manually cast// them with CAST if necessary. The default is false.ReadRowkeyAsStringbool}

BigtableOptions are additional options for Bigtable external data sources.

typeCSVOptions

type CSVOptions struct {// AllowJaggedRows causes missing trailing optional columns to be tolerated// when reading CSV data. Missing values are treated as nulls.AllowJaggedRowsbool// AllowQuotedNewlines sets whether quoted data sections containing// newlines are allowed when reading CSV data.AllowQuotedNewlinesbool// Encoding is the character encoding of data to be read.EncodingEncoding// FieldDelimiter is the separator for fields in a CSV file, used when// reading or exporting data. The default is ",".FieldDelimiterstring// Quote is the value used to quote data sections in a CSV file. The// default quotation character is the double quote ("), which is used if// both Quote and ForceZeroQuote are unset.// To specify that no character should be interpreted as a quotation// character, set ForceZeroQuote to true.// Only used when reading data.QuotestringForceZeroQuotebool// The number of rows at the top of a CSV file that BigQuery will skip when// reading data.SkipLeadingRowsint64// An optional custom string that will represent a NULL// value in CSV import data.//// NullMarker and NullMarkers are mutually exclusive and should not be set at the same time.NullMarkerstring// An optional list of custom strings that will represent// a NULL value in CSV import data.//// NullMarker and NullMarkers are mutually exclusive and should not be set at the same time.NullMarkers []string// Preserves the embedded ASCII control characters (the first 32 characters in the ASCII-table,// from '\\x00' to '\\x1F') when loading from CSV. Only applicable to CSV, ignored for other formats.PreserveASCIIControlCharactersbool// SourceColumnMatch controls the strategy used to match loaded columns to the schema.// If not set, a sensible default is chosen based on how the schema is provided. If// autodetect is used, then columns are matched by name. Otherwise, columns// are matched by position. This is done to keep the behavior// backward-compatible.SourceColumnMatchSourceColumnMatch}

CSVOptions are additional options for CSV external data sources.

typeClient

type Client struct {// Location, if set, will be used as the default location for all subsequent// dataset creation and job operations. A location specified directly in one of// those operations will override this value.Locationstring// contains filtered or unexported fields}

Client may be used to perform BigQuery operations.

funcNewClient

func NewClient(ctxcontext.Context, projectIDstring, opts ...option.ClientOption) (*Client,error)

NewClient constructs a newClient which can perform BigQuery operations.Operations performed via the client are billed to the specified GCP project.

If the project ID is set toDetectProjectID, NewClient will attempt to detectthe project ID from credentials.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}_ = client // TODO: Use client.}

func (*Client)Close

func (c *Client) Close()error

Close closes any resources held by the client.Close should be called when the client is no longer needed.It need not be called at program exit.

func (*Client)Dataset

func (c *Client) Dataset(idstring) *Dataset

Dataset creates a handle to a BigQuery dataset in the client's project.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ds := client.Dataset("my_dataset")fmt.Println(ds)}

func (*Client)DatasetInProject

func (c *Client) DatasetInProject(projectID, datasetIDstring) *Dataset

DatasetInProject creates a handle to a BigQuery dataset in the specified project.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ds := client.DatasetInProject("their-project-id", "their-dataset")fmt.Println(ds)}

func (*Client)Datasets

func (c *Client) Datasets(ctxcontext.Context) *DatasetIterator

Datasets returns an iterator over the datasets in a project.The Client's project is used by default, but that can bechanged by setting ProjectID on the returned iterator before calling Next.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}it := client.Datasets(ctx)_ = it // TODO: iterate using Next or iterator.Pager.}

func (*Client)DatasetsInProjectdeprecated

func (c *Client) DatasetsInProject(ctxcontext.Context, projectIDstring) *DatasetIterator

DatasetsInProject returns an iterator over the datasets in the provided project.

Deprecated: call Client.Datasets, then set ProjectID on the returned iterator.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}it := client.DatasetsInProject(ctx, "their-project-id")_ = it // TODO: iterate using Next or iterator.Pager.}

func (*Client)EnableStorageReadClientadded inv1.46.0

func (c *Client) EnableStorageReadClient(ctxcontext.Context, opts ...option.ClientOption)error

EnableStorageReadClient sets up Storage API connection to be used when fetchinglarge datasets from tables, jobs or queries.Currently out of pagination methods like PageInfo().Token and RowIterator.StartIndexare not supported when the Storage API is enabled.Calling this method twice will return an error.

func (*Client)JobFromID

func (c *Client) JobFromID(ctxcontext.Context, idstring) (*Job,error)

JobFromID creates a Job which refers to an existing BigQuery job. The jobneed not have been created by this package. For example, the job may havebeen created in the BigQuery console.

For jobs whose location is other than "US" or "EU", set Client.Location or useJobFromIDLocation.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery")func getJobID() string { return "" }func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}jobID := getJobID() // Get a job ID using Job.ID, the console or elsewhere.job, err := client.JobFromID(ctx, jobID)if err != nil {// TODO: Handle error.}fmt.Println(job.LastStatus()) // Display the job's status.}

func (*Client)JobFromIDLocation

func (c *Client) JobFromIDLocation(ctxcontext.Context, id, locationstring) (j *Job, errerror)

JobFromIDLocation creates a Job which refers to an existing BigQuery job. The jobneed not have been created by this package (for example, it may havebeen created in the BigQuery console), but it must exist in the specified location.

func (*Client)JobFromProjectadded inv1.25.0

func (c *Client) JobFromProject(ctxcontext.Context, projectID, jobID, locationstring) (j *Job, errerror)

JobFromProject creates a Job which refers to an existing BigQuery job. The jobneed not have been created by this package, nor does it need to reside within the sameproject or location as the instantiated client.

func (*Client)Jobs

func (c *Client) Jobs(ctxcontext.Context) *JobIterator

Jobs lists jobs within a project.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}it := client.Jobs(ctx)it.State = bigquery.Running // list only running jobs._ = it                      // TODO: iterate using Next or iterator.Pager.}

func (*Client)Projectadded inv1.19.0

func (c *Client) Project()string

Project returns the project ID or number for this instance of the client, which may haveeither been explicitly specified or autodetected.

func (*Client)Query

func (c *Client) Query(qstring) *Query

Query creates a query with string q.The returned Query may optionally be further configured before its Run method is called.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}q := client.Query("select name, num from t1")q.DefaultProjectID = "project-id"// TODO: set other options on the Query.// TODO: Call Query.Run or Query.Read.}

Example (EncryptionKey)

This example demonstrates how to run a query job on a tablewith a customer-managed encryption key. The sameapplies to load and copy jobs as well.

package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}q := client.Query("select name, num from t1")// TODO: Replace this key with a key you have created in Cloud KMS.keyName := "projects/P/locations/L/keyRings/R/cryptoKeys/K"q.DestinationEncryptionConfig = &bigquery.EncryptionConfig{KMSKeyName: keyName}// TODO: set other options on the Query.// TODO: Call Query.Run or Query.Read.}

Example (Parameters)
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}q := client.Query("select num from t1 where name = @user")q.Parameters = []bigquery.QueryParameter{{Name: "user", Value: "Elizabeth"},}// TODO: set other options on the Query.// TODO: Call Query.Run or Query.Read.}

typeCloneDefinitionadded inv1.31.0

type CloneDefinition struct {// BaseTableReference describes the ID of the table that this clone// came from.BaseTableReference *Table// CloneTime indicates when the base table was cloned.CloneTimetime.Time}

CloneDefinition provides metadata related to the origin of a clone.

typeClustering

type Clustering struct {Fields []string}

Clustering governs the organization of data within a managed table.For more information, seehttps://cloud.google.com/bigquery/docs/clustered-tables

typeColumnNameCharacterMapadded inv1.62.0

type ColumnNameCharacterMapstring

ColumnNameCharacterMap is used to specific column naming behavior for load jobs.

var (// UnspecifiedColumnNameCharacterMap is the unspecified default value.UnspecifiedColumnNameCharacterMapColumnNameCharacterMap = "COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED"// StrictColumnNameCharacterMap indicates support for flexible column names.// Invalid column names will be rejected.StrictColumnNameCharacterMapColumnNameCharacterMap = "STRICT"// V1ColumnNameCharacterMap indicates support for alphanumeric + underscore characters and names must start with a letter or underscore.// Invalid column names will be normalized.V1ColumnNameCharacterMapColumnNameCharacterMap = "V1"// V2ColumnNameCharacterMap indicates support for flexible column names.// Invalid column names will be normalized.V2ColumnNameCharacterMapColumnNameCharacterMap = "V2")

typeColumnReferenceadded inv1.52.0

type ColumnReference struct {// ReferencingColumn is the column in the current table that composes the foreign key.ReferencingColumnstring// ReferencedColumn is the column in the primary key of the foreign table that// is referenced by the ReferencingColumn.ReferencedColumnstring}

ColumnReference represents the pair of the foreign key column and primary key column.

typeCompression

type Compressionstring

Compression is the type of compression to apply when writing data to Google Cloud Storage.

const (// None specifies no compression.NoneCompression = "NONE"// Gzip specifies gzip compression.GzipCompression = "GZIP"// Deflate specifies DEFLATE compression for Avro files.DeflateCompression = "DEFLATE"// Snappy specifies SNAPPY compression for Avro files.SnappyCompression = "SNAPPY")

typeConnectionPropertyadded inv1.23.0

type ConnectionProperty struct {// Name of the connection property to set.Keystring// Value of the connection property.Valuestring}

ConnectionProperty represents a single key and value pair that can be sent alongside a query request or load job.

typeCopier

type Copier struct {JobIDConfigCopyConfig// contains filtered or unexported fields}

A Copier copies data into a BigQuery table from one or more BigQuery tables.

func (*Copier)Run

func (c *Copier) Run(ctxcontext.Context) (*Job,error)

Run initiates a copy job.

typeCopyConfig

type CopyConfig struct {// Srcs are the tables from which data will be copied.Srcs []*Table// Dst is the table into which the data will be copied.Dst *Table// CreateDisposition specifies the circumstances under which the destination table will be created.// The default is CreateIfNeeded.CreateDispositionTableCreateDisposition// WriteDisposition specifies how existing data in the destination table is treated.// The default is WriteEmpty.WriteDispositionTableWriteDisposition// The labels associated with this job.Labels map[string]string// Custom encryption configuration (e.g., Cloud KMS keys).DestinationEncryptionConfig *EncryptionConfig// One of the supported operation types when executing a Table Copy jobs.  By default this// copies tables, but can also be set to perform snapshot or restore operations.OperationTypeTableCopyOperationType// Sets a best-effort deadline on a specific job.  If job execution exceeds this// timeout, BigQuery may attempt to cancel this work automatically.//// This deadline cannot be adjusted or removed once the job is created.  Consider// using Job.Cancel in situations where you need more dynamic behavior.//// Experimental: this option is experimental and may be modified or removed in future versions,// regardless of any other documented package stability guarantees.JobTimeouttime.Duration// The reservation that job would use. User can specify a reservation to// execute the job. If reservation is not set, reservation is determined// based on the rules defined by the reservation assignments. The expected// format is// `projects/{project}/locations/{location}/reservations/{reservation}`.Reservationstring// A target limit on the rate of slot consumption by this query. If set to a// value > 0, BigQuery will attempt to limit the rate of slot consumption by// this query to keep it below the configured limit, even if the query is// eligible for more slots based on fair scheduling. The unused slots will be// available for other jobs and queries to use.//// Note: This feature is not yet generally available.MaxSlotsint32}

CopyConfig holds the configuration for a copy job.

typeDMLStatisticsadded inv1.20.1

type DMLStatistics struct {// Rows added by the statement.InsertedRowCountint64// Rows removed by the statement.DeletedRowCountint64// Rows changed by the statement.UpdatedRowCountint64}

DMLStatistics contains counts of row mutations triggered by a DML query statement.

typeDataFormat

type DataFormatstring

DataFormat describes the format of BigQuery table data.

const (CSVDataFormat = "CSV"AvroDataFormat = "AVRO"JSONDataFormat = "NEWLINE_DELIMITED_JSON"DatastoreBackupDataFormat = "DATASTORE_BACKUP"GoogleSheetsDataFormat = "GOOGLE_SHEETS"BigtableDataFormat = "BIGTABLE"ParquetDataFormat = "PARQUET"ORCDataFormat = "ORC"// For BQ ML Models, TensorFlow Saved Model format.TFSavedModelDataFormat = "ML_TF_SAVED_MODEL"// For BQ ML Models, xgBoost Booster format.XGBoostBoosterDataFormat = "ML_XGBOOST_BOOSTER"IcebergDataFormat = "ICEBERG")

Constants describing the format of BigQuery table data.

typeDataset

type Dataset struct {ProjectIDstringDatasetIDstring// contains filtered or unexported fields}

Dataset is a reference to a BigQuery dataset.

func (*Dataset)Create

func (d *Dataset) Create(ctxcontext.Context, md *DatasetMetadata) (errerror)

Create creates a dataset in the BigQuery service.

An error will be returned if the dataset already exists.Pass in a DatasetMetadata value to configure the dataset.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ds := client.Dataset("my_dataset")if err := ds.Create(ctx, &bigquery.DatasetMetadata{Location: "EU"}); err != nil {// TODO: Handle error.}}

func (*Dataset)CreateWithOptionsadded inv1.65.0

func (d *Dataset) CreateWithOptions(ctxcontext.Context, md *DatasetMetadata, opts ...DatasetOption) (errerror)

CreateWithOptions creates a dataset in the BigQuery service, andprovides additional options to control the behavior of the call.

An error will be returned if the dataset already exists.Pass in a DatasetMetadata value to configure the dataset.

func (*Dataset)Delete

func (d *Dataset) Delete(ctxcontext.Context) (errerror)

Delete deletes the dataset. Delete will fail if the dataset is not empty.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}if err := client.Dataset("my_dataset").Delete(ctx); err != nil {// TODO: Handle error.}}

func (*Dataset)DeleteWithContents

func (d *Dataset) DeleteWithContents(ctxcontext.Context) (errerror)

DeleteWithContents deletes the dataset, as well as contained resources.

func (*Dataset)Identifieradded inv1.25.0

func (d *Dataset) Identifier(fIdentifierFormat) (string,error)

Identifier returns the ID of the dataset in the requested format.

For Standard SQL format, the identifier will be quoted if theProjectID contains dash (-) characters.

func (*Dataset)Metadata

func (d *Dataset) Metadata(ctxcontext.Context) (md *DatasetMetadata, errerror)

Metadata fetches the metadata for the dataset.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}md, err := client.Dataset("my_dataset").Metadata(ctx)if err != nil {// TODO: Handle error.}fmt.Println(md)}

func (*Dataset)MetadataWithOptionsadded inv1.65.0

func (d *Dataset) MetadataWithOptions(ctxcontext.Context, opts ...DatasetOption) (md *DatasetMetadata, errerror)

MetadataWithOptions fetches metadata for the dataset, and provides additional options forcontrolling the request.

func (*Dataset)Model

func (d *Dataset) Model(modelIDstring) *Model

Model creates a handle to a BigQuery model in the dataset.To determine if a model exists, call Model.Metadata.If the model does not already exist, you can create it via executionof a CREATE MODEL query.

func (*Dataset)Models

func (d *Dataset) Models(ctxcontext.Context) *ModelIterator

Models returns an iterator over the models in the Dataset.

func (*Dataset)Routine

func (d *Dataset) Routine(routineIDstring) *Routine

Routine creates a handle to a BigQuery routine in the dataset.To determine if a routine exists, call Routine.Metadata.

func (*Dataset)Routines

func (d *Dataset) Routines(ctxcontext.Context) *RoutineIterator

Routines returns an iterator over the routines in the Dataset.

func (*Dataset)Table

func (d *Dataset) Table(tableIDstring) *Table

Table creates a handle to a BigQuery table in the dataset.To determine if a table exists, call Table.Metadata.If the table does not already exist, use Table.Create to create it.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}// Table creates a reference to the table. It does not create the actual// table in BigQuery; to do so, use Table.Create.t := client.Dataset("my_dataset").Table("my_table")fmt.Println(t)}

func (*Dataset)Tables

func (d *Dataset) Tables(ctxcontext.Context) *TableIterator

Tables returns an iterator over the tables in the Dataset.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}it := client.Dataset("my_dataset").Tables(ctx)_ = it // TODO: iterate using Next or iterator.Pager.}

func (*Dataset)Update

Update modifies specific Dataset metadata fields.To perform a read-modify-write that protects against intervening reads,set the etag argument to the DatasetMetadata.ETag field from the read.Pass the empty string for etag for a "blind write" that will always succeed.

Example (BlindWrite)

To perform a blind write, ignoring the existing state (and possibly overwritingother updates), pass the empty string as the etag.

package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}md, err := client.Dataset("my_dataset").Update(ctx, bigquery.DatasetMetadataToUpdate{Name: "blind"}, "")if err != nil {// TODO: Handle error.}fmt.Println(md)}

Example (ReadModifyWrite)

This example illustrates how to perform a read-modify-write sequence on datasetmetadata. Passing the metadata's ETag to the Update call ensures that the callwill fail if the metadata was changed since the read.

package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ds := client.Dataset("my_dataset")md, err := ds.Metadata(ctx)if err != nil {// TODO: Handle error.}md2, err := ds.Update(ctx,bigquery.DatasetMetadataToUpdate{Name: "new " + md.Name},md.ETag)if err != nil {// TODO: Handle error.}fmt.Println(md2)}

func (*Dataset)UpdateWithOptionsadded inv1.65.0

func (d *Dataset) UpdateWithOptions(ctxcontext.Context, dmDatasetMetadataToUpdate, etagstring, opts ...DatasetOption) (md *DatasetMetadata, errerror)

UpdateWithOptions modifies specific Dataset metadata fields andprovides an interface for specifying additional options to the request.

To perform a read-modify-write that protects against intervening reads,set the etag argument to the DatasetMetadata.ETag field from the read.Pass the empty string for etag for a "blind write" that will always succeed.

typeDatasetAccessEntryadded inv1.30.0

type DatasetAccessEntry struct {// The dataset to which this entry applies.Dataset *Dataset// The list of target types within the dataset// to which this entry applies.//// Current supported values://// VIEWS - This entry applies to views in the dataset.TargetTypes []string}

DatasetAccessEntry is an access entry that refers to resources withinanother dataset.

typeDatasetIterator

type DatasetIterator struct {// ListHidden causes hidden datasets to be listed when set to true.// Set before the first call to Next.ListHiddenbool// Filter restricts the datasets returned by label. The filter syntax is described in//https://cloud.google.com/bigquery/docs/labeling-datasets#filtering_datasets_using_labels// Set before the first call to Next.Filterstring// The project ID of the listed datasets.// Set before the first call to Next.ProjectIDstring// contains filtered or unexported fields}

DatasetIterator iterates over the datasets in a project.

func (*DatasetIterator)Next

func (it *DatasetIterator) Next() (*Dataset,error)

Next returns the next Dataset. Its second return value is iterator.Done ifthere are no more results. Once Next returns Done, all subsequent calls willreturn Done.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery""google.golang.org/api/iterator")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}it := client.Datasets(ctx)for {ds, err := it.Next()if err == iterator.Done {break}if err != nil {// TODO: Handle error.}fmt.Println(ds)}}

func (*DatasetIterator)PageInfo

func (it *DatasetIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

typeDatasetMetadata

type DatasetMetadata struct {// These fields can be set when creating a dataset.Namestring// The user-friendly name for this dataset.Descriptionstring// The user-friendly description of this dataset.Locationstring// The geo location of the dataset.DefaultTableExpirationtime.Duration// The default expiration time for new tables.Labels                  map[string]string// User-provided labels.Access                  []*AccessEntry// Access permissions.DefaultEncryptionConfig *EncryptionConfig// DefaultPartitionExpiration is the default expiration time for// all newly created partitioned tables in the dataset.DefaultPartitionExpirationtime.Duration// Defines the default collation specification of future tables// created in the dataset. If a table is created in this dataset without// table-level default collation, then the table inherits the dataset default// collation, which is applied to the string fields that do not have explicit// collation specified. A change to this field affects only tables created// afterwards, and does not alter the existing tables.// More information:https://cloud.google.com/bigquery/docs/reference/standard-sql/collation-conceptsDefaultCollationstring// For externally defined datasets, contains information about the configuration.ExternalDatasetReference *ExternalDatasetReference// MaxTimeTravel represents the number of hours for the max time travel for all tables// in the dataset.  Durations are rounded towards zero for the nearest hourly value.MaxTimeTraveltime.Duration// Storage billing model to be used for all tables in the dataset.// Can be set to PHYSICAL. Default is LOGICAL.// Once you create a dataset with storage billing model set to physical bytes, you can't change it back to using logical bytes again.// More details:https://cloud.google.com/bigquery/docs/datasets-intro#dataset_storage_billing_modelsStorageBillingModelstring// These fields are read-only.CreationTimetime.TimeLastModifiedTimetime.Time// When the dataset or any of its tables were modified.FullIDstring// The full dataset ID in the form projectID:datasetID.// The tags associated with this dataset. Tag keys are// globally unique, and managed via the resource manager API.// More information:https://cloud.google.com/resource-manager/docs/tags/tags-overviewTags []*DatasetTag// TRUE if the dataset and its table names are case-insensitive, otherwise// FALSE. By default, this is FALSE, which means the dataset and its table// names are case-sensitive. This field does not affect routine references.IsCaseInsensitivebool// ETag is the ETag obtained when reading metadata. Pass it to Dataset.Update to// ensure that the metadata hasn't changed since it was read.ETagstring}

DatasetMetadata contains information about a BigQuery dataset.

typeDatasetMetadataToUpdate

type DatasetMetadataToUpdate struct {Descriptionoptional.String// The user-friendly description of this table.Nameoptional.String// The user-friendly name for this dataset.// DefaultTableExpiration is the default expiration time for new tables.// If set to time.Duration(0), new tables never expire.DefaultTableExpirationoptional.Duration// DefaultTableExpiration is the default expiration time for// all newly created partitioned tables.// If set to time.Duration(0), new table partitions never expire.DefaultPartitionExpirationoptional.Duration// DefaultEncryptionConfig defines CMEK settings for new resources created// in the dataset.DefaultEncryptionConfig *EncryptionConfig// Defines the default collation specification of future tables// created in the dataset.DefaultCollationoptional.String// For externally defined datasets, contains information about the configuration.ExternalDatasetReference *ExternalDatasetReference// MaxTimeTravel represents the number of hours for the max time travel for all tables// in the dataset.  Durations are rounded towards zero for the nearest hourly value.MaxTimeTraveloptional.Duration// Storage billing model to be used for all tables in the dataset.// Can be set to PHYSICAL. Default is LOGICAL.// Once you change a dataset's storage billing model to use physical bytes, you can't change it back to using logical bytes again.// More details:https://cloud.google.com/bigquery/docs/datasets-intro#dataset_storage_billing_modelsStorageBillingModeloptional.String// The entire access list. It is not possible to replace individual entries.Access []*AccessEntry// TRUE if the dataset and its table names are case-insensitive, otherwise// FALSE. By default, this is FALSE, which means the dataset and its table// names are case-sensitive. This field does not affect routine references.IsCaseInsensitiveoptional.Bool// contains filtered or unexported fields}

DatasetMetadataToUpdate is used when updating a dataset's metadata.Only non-nil fields will be updated.

func (*DatasetMetadataToUpdate)DeleteLabel

func (u *DatasetMetadataToUpdate) DeleteLabel(namestring)

DeleteLabel causes a label to be deleted on a call to Update.

func (*DatasetMetadataToUpdate)SetLabel

func (u *DatasetMetadataToUpdate) SetLabel(name, valuestring)

SetLabel causes a label to be added or modified on a call to Update.

typeDatasetOptionadded inv1.65.0

type DatasetOption func(*dsCallOption)

DatasetOption provides an option type for customizing requests against the Datasetservice.

funcWithAccessPolicyVersionadded inv1.65.0

func WithAccessPolicyVersion(apvint)DatasetOption

WithAccessPolicyVersion is an option that enabled setting of the Access Policy Version for a requestwhere appropriate. Valid values are 0, 1, and 3.

Requests specifying an invalid value will be rejected.Requests for conditional access policy binding in datasets must specify version 3.

Dataset with no conditional role bindings in access policy may specify any valid valueor leave the field unset.

This field will be mapped to [IAM Policy version] (https://cloud.google.com/iam/docs/policies#versions)and will be used to fetch policy from IAM. If unset or if 0 or 1 value is used fordataset with conditional bindings, access entry with condition will have role stringappended by 'withcond' string followed by a hash value.

Please referhttps://cloud.google.com/iam/docs/troubleshooting-withcond for more details.

funcWithDatasetViewadded inv1.69.0

func WithDatasetView(viewDatasetView)DatasetOption

WithDatasetView specifies the view that determines which dataset informationis returned. By default, metadata and ACL information are returned.

funcWithUpdateModeadded inv1.69.0

func WithUpdateMode(modeDatasetUpdateMode)DatasetOption

WithUpdateMode specifies the fields of dataset that the update/patchoperation is targeting. By default, both metadata and ACL fields are updated.

typeDatasetTagadded inv1.33.0

type DatasetTag struct {// TagKey is the namespaced friendly name of the tag key, e.g.// "12345/environment" where 12345 is org id.TagKeystring// TagValue is the friendly short name of the tag value, e.g.// "production".TagValuestring}

DatasetTag is a representation of a single tag key/value.

typeDatasetUpdateModeadded inv1.69.0

type DatasetUpdateModestring

DatasetUpdateMode specifies which fields of a dataset are going to be affectedby update/patch operations.

const (// DatasetMetadataUpdateMode targets metadata information for the dataset,// such as friendlyName, description, labels, etc.DatasetMetadataUpdateModeDatasetUpdateMode = "UPDATE_METADATA"// DatasetACLUpdateMode targets ACL information for the dataset,// which defines dataset access for one or more entities.DatasetACLUpdateModeDatasetUpdateMode = "UPDATE_ACL"// DatasetFullUpdateMode targets both dataset metadata and ACL// information on update operations.DatasetFullUpdateModeDatasetUpdateMode = "UPDATE_FULL"// UnspecifiedDatasetUpdateMode is the default value, which will be treated as DatasetFullUpdateModeUnspecifiedDatasetUpdateModeDatasetUpdateMode = "UPDATE_MODE_UNSPECIFIED")

typeDatasetViewadded inv1.69.0

type DatasetViewstring

DatasetView specifies which details about a dataset are desired.

const (// DatasetMetadataView populates metadata information for the dataset,// such as friendlyName, description, labels, etc.DatasetMetadataViewDatasetView = "METADATA"// DatasetACLView populates information for the dataset, which defines// dataset access for one or more entities.DatasetACLViewDatasetView = "ACL"// DatasetFullView populates both dataset metadata and ACL information.DatasetFullViewDatasetView = "FULL"// UnspecifiedDatasetView is the default value, which will be treated as DatasetFullViewUnspecifiedDatasetViewDatasetView = "DATASET_VIEW_UNSPECIFIED")

typeDecimalTargetTypeadded inv1.20.1

type DecimalTargetTypestring

DecimalTargetType is used to express preference ordering for converting values from external formats.

var (// NumericTargetType indicates the preferred type is NUMERIC when supported.NumericTargetTypeDecimalTargetType = "NUMERIC"// BigNumericTargetType indicates the preferred type is BIGNUMERIC when supported.BigNumericTargetTypeDecimalTargetType = "BIGNUMERIC"// StringTargetType indicates the preferred type is STRING when supported.StringTargetTypeDecimalTargetType = "STRING")

typeEncoding

type Encodingstring

Encoding specifies the character encoding of data to be loaded into BigQuery.Seehttps://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load.encodingfor more details about how this is used.

const (// UTF_8 specifies the UTF-8 encoding type.UTF_8Encoding = "UTF-8"// ISO_8859_1 specifies the ISO-8859-1 encoding type.ISO_8859_1Encoding = "ISO-8859-1")

typeEncryptionConfig

type EncryptionConfig struct {// Describes the Cloud KMS encryption key that will be used to protect// destination BigQuery table. The BigQuery Service Account associated with your// project requires access to this encryption key.KMSKeyNamestring}

EncryptionConfig configures customer-managed encryption on tables and ML models.

typeEntityType

type EntityTypeint

EntityType is the type of entity in an AccessEntry.

const (// DomainEntity is a domain (e.g. "example.com").DomainEntityEntityType =iota + 1// GroupEmailEntity is an email address of a Google Group.GroupEmailEntity// UserEmailEntity is an email address of an individual user.UserEmailEntity// SpecialGroupEntity is a special group: one of projectOwners, projectReaders, projectWriters or// allAuthenticatedUsers.SpecialGroupEntity// ViewEntity is a BigQuery logical view.ViewEntity// IAMMemberEntity represents entities present in IAM but not represented using// the other entity types.IAMMemberEntity// RoutineEntity is a BigQuery routine, referencing a User Defined Function (UDF).RoutineEntity// DatasetEntity is BigQuery dataset, present in the access list.DatasetEntity)

typeError

type Error struct {// Mirrors bq.ErrorProto, but drops DebugInfoLocation, Message, Reasonstring}

An Error contains detailed information about a failed bigquery operation.Detailed description of possible Reasons can be found here:https://cloud.google.com/bigquery/troubleshooting-errors.

func (Error)Error

func (eError) Error()string

typeExplainQueryStage

type ExplainQueryStage struct {// CompletedParallelInputs: Number of parallel input segments completed.CompletedParallelInputsint64// ComputeAvg: Duration the average shard spent on CPU-bound tasks.ComputeAvgtime.Duration// ComputeMax: Duration the slowest shard spent on CPU-bound tasks.ComputeMaxtime.Duration// Relative amount of the total time the average shard spent on CPU-bound tasks.ComputeRatioAvgfloat64// Relative amount of the total time the slowest shard spent on CPU-bound tasks.ComputeRatioMaxfloat64// EndTime: Stage end time.EndTimetime.Time// Unique ID for stage within plan.IDint64// InputStages: IDs for stages that are inputs to this stage.InputStages []int64// Human-readable name for stage.Namestring// ParallelInputs: Number of parallel input segments to be processed.ParallelInputsint64// ReadAvg: Duration the average shard spent reading input.ReadAvgtime.Duration// ReadMax: Duration the slowest shard spent reading input.ReadMaxtime.Duration// Relative amount of the total time the average shard spent reading input.ReadRatioAvgfloat64// Relative amount of the total time the slowest shard spent reading input.ReadRatioMaxfloat64// Number of records read into the stage.RecordsReadint64// Number of records written by the stage.RecordsWrittenint64// ShuffleOutputBytes: Total number of bytes written to shuffle.ShuffleOutputBytesint64// ShuffleOutputBytesSpilled: Total number of bytes written to shuffle// and spilled to disk.ShuffleOutputBytesSpilledint64// StartTime: Stage start time.StartTimetime.Time// Current status for the stage.Statusstring// List of operations within the stage in dependency order (approximately// chronological).Steps []*ExplainQueryStep// WaitAvg: Duration the average shard spent waiting to be scheduled.WaitAvgtime.Duration// WaitMax: Duration the slowest shard spent waiting to be scheduled.WaitMaxtime.Duration// Relative amount of the total time the average shard spent waiting to be scheduled.WaitRatioAvgfloat64// Relative amount of the total time the slowest shard spent waiting to be scheduled.WaitRatioMaxfloat64// WriteAvg: Duration the average shard spent on writing output.WriteAvgtime.Duration// WriteMax: Duration the slowest shard spent on writing output.WriteMaxtime.Duration// Relative amount of the total time the average shard spent on writing output.WriteRatioAvgfloat64// Relative amount of the total time the slowest shard spent on writing output.WriteRatioMaxfloat64}

ExplainQueryStage describes one stage of a query.

typeExplainQueryStep

type ExplainQueryStep struct {// Machine-readable operation type.Kindstring// Human-readable stage descriptions.Substeps []string}

ExplainQueryStep describes one step of a query stage.

typeExportDataStatisticsadded inv1.59.0

type ExportDataStatistics struct {// Number of destination files generated.FileCountint64// Number of destination rows generated.RowCountint64}

ExportDataStatistics represents statistics fora EXPORT DATA statement as part of Query Job.

typeExpradded inv1.65.0

type Expr struct {// Textual representation of an expression in Common Expression Language syntax.Expressionstring// Optional. Title for the expression, i.e. a short string describing// its purpose. This can be used e.g. in UIs which allow to enter the// expression.Titlestring// Optional. Description of the expression. This is a longer text which// describes the expression, e.g. when hovered over it in a UI.Descriptionstring// Optional. String indicating the location of the expression for error// reporting, e.g. a file name and a position in the file.Locationstring}

Expr represents the conditional information related to dataset access policies.

typeExternalData

type ExternalData interface {// contains filtered or unexported methods}

ExternalData is a table which is stored outside of BigQuery. It is implemented by*ExternalDataConfig.GCSReference also implements it, for backwards compatibility.

typeExternalDataConfig

type ExternalDataConfig struct {// The format of the data. Required.SourceFormatDataFormat// The fully-qualified URIs that point to your// data in Google Cloud. Required.//// For Google Cloud Storage URIs, each URI can contain one '*' wildcard character// and it must come after the 'bucket' name. Size limits related to load jobs// apply to external data sources.//// For Google Cloud Bigtable URIs, exactly one URI can be specified and it has be// a fully specified and valid HTTPS URL for a Google Cloud Bigtable table.//// For Google Cloud Datastore backups, exactly one URI can be specified. Also,// the '*' wildcard character is not allowed.SourceURIs []string// The schema of the data. Required for CSV and JSON; disallowed for the// other formats.SchemaSchema// Try to detect schema and format options automatically.// Any option specified explicitly will be honored.AutoDetectbool// The compression type of the data.CompressionCompression// IgnoreUnknownValues causes values not matching the schema to be// tolerated. Unknown values are ignored. For CSV this ignores extra values// at the end of a line. For JSON this ignores named values that do not// match any column name. If this field is not set, records containing// unknown values are treated as bad records. The MaxBadRecords field can// be used to customize how bad records are handled.IgnoreUnknownValuesbool// MaxBadRecords is the maximum number of bad records that will be ignored// when reading data.MaxBadRecordsint64// Additional options for CSV, GoogleSheets, Bigtable, and Parquet formats.OptionsExternalDataConfigOptions// HivePartitioningOptions allows use of Hive partitioning based on the// layout of objects in Google Cloud Storage.HivePartitioningOptions *HivePartitioningOptions// DecimalTargetTypes allows selection of how decimal values are converted when// processed in bigquery, subject to the value type having sufficient precision/scale// to support the values.  In the order of NUMERIC, BIGNUMERIC, and STRING, a type is// selected if is present in the list and if supports the necessary precision and scale.//// StringTargetType supports all precision and scale values.DecimalTargetTypes []DecimalTargetType// ConnectionID associates an external data configuration with a connection ID.// Connections are managed through the BigQuery Connection API://https://pkg.go.dev/cloud.google.com/go/bigquery/connection/apiv1ConnectionIDstring// When creating an external table, the user can provide a reference file with the table schema.// This is enabled for the following formats: AVRO, PARQUET, ORC.ReferenceFileSchemaURIstring// Metadata Cache Mode for the table. Set this to// enable caching of metadata from external data source.MetadataCacheModeMetadataCacheMode// Time zone used when parsing timestamp values that do not// have specific time zone information (e.g. 2024-04-20 12:34:56).// The expected format is a IANA timezone string (e.g. America/Los_Angeles).TimeZonestring// Format used to parse DATE values. Supports C-style and// SQL-style valuesDateFormatstring// Format used to parse DATETIME values. Supports// C-style and SQL-style values.DatetimeFormatstring// Format used to parse TIME values. Supports C-style and// SQL-style values.TimeFormatstring// Format used to parse TIMESTAMP values. Supports// C-style and SQL-style values.TimestampFormatstring}

ExternalDataConfig describes data external to BigQuery that can be usedin queries and to create external tables.

typeExternalDataConfigOptions

type ExternalDataConfigOptions interface {// contains filtered or unexported methods}

ExternalDataConfigOptions are additional options for external data configurations.This interface is implemented by CSVOptions, GoogleSheetsOptions and BigtableOptions.

typeExternalDatasetReferenceadded inv1.56.0

type ExternalDatasetReference struct {//The connection id that is used to access the external_source.// Format: projects/{project_id}/locations/{location_id}/connections/{connection_id}Connectionstring// External source that backs this dataset.ExternalSourcestring}

ExternalDatasetReference provides information about external dataset metadata.

typeExtractConfig

type ExtractConfig struct {// Src is the table from which data will be extracted.// Only one of Src or SrcModel should be specified.Src *Table// SrcModel is the ML model from which the data will be extracted.// Only one of Src or SrcModel should be specified.SrcModel *Model// Dst is the destination into which the data will be extracted.Dst *GCSReference// DisableHeader disables the printing of a header row in exported data.DisableHeaderbool// The labels associated with this job.Labels map[string]string// For Avro-based extracts, controls whether logical type annotations are generated.//// Example:  With this enabled, writing a BigQuery TIMESTAMP column will result in// an integer column annotated with the appropriate timestamp-micros/millis annotation// in the resulting Avro files.UseAvroLogicalTypesbool// Sets a best-effort deadline on a specific job.  If job execution exceeds this// timeout, BigQuery may attempt to cancel this work automatically.//// This deadline cannot be adjusted or removed once the job is created.  Consider// using Job.Cancel in situations where you need more dynamic behavior.//// Experimental: this option is experimental and may be modified or removed in future versions,// regardless of any other documented package stability guarantees.JobTimeouttime.Duration// The reservation that job would use. User can specify a reservation to// execute the job. If reservation is not set, reservation is determined// based on the rules defined by the reservation assignments. The expected// format is// `projects/{project}/locations/{location}/reservations/{reservation}`.Reservationstring// A target limit on the rate of slot consumption by this query. If set to a// value > 0, BigQuery will attempt to limit the rate of slot consumption by// this query to keep it below the configured limit, even if the query is// eligible for more slots based on fair scheduling. The unused slots will be// available for other jobs and queries to use.//// Note: This feature is not yet generally available.MaxSlotsint32}

ExtractConfig holds the configuration for an extract job.

typeExtractStatistics

type ExtractStatistics struct {// The number of files per destination URI or URI pattern specified in the// extract configuration. These values will be in the same order as the// URIs specified in the 'destinationUris' field.DestinationURIFileCounts []int64}

ExtractStatistics contains statistics about an extract job.

typeExtractor

type Extractor struct {JobIDConfigExtractConfig// contains filtered or unexported fields}

An Extractor extracts data from a BigQuery table into Google Cloud Storage.

func (*Extractor)Run

func (e *Extractor) Run(ctxcontext.Context) (j *Job, errerror)

Run initiates an extract job.

typeFieldSchema

type FieldSchema struct {// The field name.// Must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_),// and must start with a letter or underscore.// The maximum length is 128 characters.Namestring// A description of the field. The maximum length is 16,384 characters.Descriptionstring// Whether the field may contain multiple values.Repeatedbool// Whether the field is required.  Ignored if Repeated is true.Requiredbool// The field data type.  If Type is Record, then this field contains a nested schema,// which is described by Schema.TypeFieldType// Annotations for enforcing column-level security constraints.PolicyTags *PolicyTagList// Describes the nested schema if Type is set to Record.SchemaSchema// Maximum length of the field for STRING or BYTES type.//// It is invalid to set value for types other than STRING or BYTES.//// For STRING type, this represents the maximum UTF-8 length of strings// allowed in the field. For BYTES type, this represents the maximum// number of bytes in the field.MaxLengthint64// Precision can be used to constrain the maximum number of// total digits allowed for NUMERIC or BIGNUMERIC types.//// It is invalid to set values for Precision for types other than// NUMERIC or BIGNUMERIC.//// For NUMERIC type, acceptable values for Precision must// be: 1 ≤ (Precision - Scale) ≤ 29. Values for Scale// must be: 0 ≤ Scale ≤ 9.//// For BIGNUMERIC type, acceptable values for Precision must// be: 1 ≤ (Precision - Scale) ≤ 38. Values for Scale// must be: 0 ≤ Scale ≤ 38.Precisionint64// Scale can be used to constrain the maximum number of digits// in the fractional part of a NUMERIC or BIGNUMERIC type.//// If the Scale value is set, the Precision value must be set as well.//// It is invalid to set values for Scale for types other than// NUMERIC or BIGNUMERIC.//// See the Precision field for additional guidance about valid values.Scaleint64// DefaultValueExpression is used to specify the default value of a field// using a SQL expression.  It can only be set for top level fields (columns).//// You can use struct or array expression to specify default value for the// entire struct or array. The valid SQL expressions are://// - Literals for all data types, including STRUCT and ARRAY.// - The following functions://   - CURRENT_TIMESTAMP//   - CURRENT_TIME//   - CURRENT_DATE//   - CURRENT_DATETIME//   - GENERATE_UUID//   - RAND//   - SESSION_USER//   - ST_GEOGPOINT//   - Struct or array composed with the above allowed functions, for example://       [CURRENT_DATE(), DATE '2020-01-01']"DefaultValueExpressionstring// Collation can be set only when the type of field is STRING.// The following values are supported://   - 'und:ci': undetermined locale, case insensitive.//   - ”: empty string. Default to case-sensitive behavior.// More information:https://cloud.google.com/bigquery/docs/reference/standard-sql/collation-conceptsCollationstring// Information about the range.// If the type is RANGE, this field is required.RangeElementType *RangeElementType// RoundingMode specifies the rounding mode to be used when storing// values of NUMERIC and BIGNUMERIC type.// If unspecified, default value is RoundHalfAwayFromZero.RoundingModeRoundingMode}

FieldSchema describes a single field.

typeFieldType

type FieldTypestring

FieldType is the type of field.

const (// StringFieldType is a string field type.StringFieldTypeFieldType = "STRING"// BytesFieldType is a bytes field type.BytesFieldTypeFieldType = "BYTES"// IntegerFieldType is a integer field type.IntegerFieldTypeFieldType = "INTEGER"// FloatFieldType is a float field type.FloatFieldTypeFieldType = "FLOAT"// BooleanFieldType is a boolean field type.BooleanFieldTypeFieldType = "BOOLEAN"// TimestampFieldType is a timestamp field type.TimestampFieldTypeFieldType = "TIMESTAMP"// RecordFieldType is a record field type. It is typically used to create columns with repeated or nested data.RecordFieldTypeFieldType = "RECORD"// DateFieldType is a date field type.DateFieldTypeFieldType = "DATE"// TimeFieldType is a time field type.TimeFieldTypeFieldType = "TIME"// DateTimeFieldType is a datetime field type.DateTimeFieldTypeFieldType = "DATETIME"// NumericFieldType is a numeric field type. Numeric types include integer types, floating point types and the// NUMERIC data type.NumericFieldTypeFieldType = "NUMERIC"// GeographyFieldType is a string field type.  Geography types represent a set of points// on the Earth's surface, represented in Well Known Text (WKT) format.GeographyFieldTypeFieldType = "GEOGRAPHY"// BigNumericFieldType is a numeric field type that supports values of larger precision// and scale than the NumericFieldType.BigNumericFieldTypeFieldType = "BIGNUMERIC"// IntervalFieldType is a representation of a duration or an amount of time.IntervalFieldTypeFieldType = "INTERVAL"// JSONFieldType is a representation of a json object.JSONFieldTypeFieldType = "JSON"// RangeFieldType represents a continuous range of values.RangeFieldTypeFieldType = "RANGE")

typeFileConfig

type FileConfig struct {// SourceFormat is the format of the data to be read.// Allowed values are: Avro, CSV, DatastoreBackup, JSON, ORC, and Parquet.  The default is CSV.SourceFormatDataFormat// Indicates if we should automatically infer the options and// schema for CSV and JSON sources.AutoDetectbool// MaxBadRecords is the maximum number of bad records that will be ignored// when reading data.MaxBadRecordsint64// IgnoreUnknownValues causes values not matching the schema to be// tolerated. Unknown values are ignored. For CSV this ignores extra values// at the end of a line. For JSON this ignores named values that do not// match any column name. If this field is not set, records containing// unknown values are treated as bad records. The MaxBadRecords field can// be used to customize how bad records are handled.IgnoreUnknownValuesbool// Schema describes the data. It is required when reading CSV or JSON data,// unless the data is being loaded into a table that already exists.SchemaSchema// Additional options for CSV files.CSVOptions// Additional options for Parquet files.ParquetOptions *ParquetOptions// Additional options for Avro files.AvroOptions *AvroOptions// Time zone used when parsing timestamp values that do not// have specific time zone information (e.g. 2024-04-20 12:34:56).// The expected format is a IANA timezone string (e.g. America/Los_Angeles).TimeZonestring// Format used to parse DATE values. Supports C-style and// SQL-style valuesDateFormatstring// Format used to parse DATETIME values. Supports// C-style and SQL-style values.DatetimeFormatstring// Format used to parse TIME values. Supports C-style and// SQL-style values.TimeFormatstring// Format used to parse TIMESTAMP values. Supports// C-style and SQL-style values.TimestampFormatstring}

FileConfig contains configuration options that pertain to files, typicallytext files that require interpretation to be used as a BigQuery table. Afile may live in Google Cloud Storage (see GCSReference), or it may beloaded into a table via the Table.LoaderFromReader.

typeForeignKeyadded inv1.52.0

type ForeignKey struct {// Foreign key constraint name.Namestring// Table that holds the primary key and is referenced by this foreign key.ReferencedTable *Table// Columns that compose the foreign key.ColumnReferences []*ColumnReference}

ForeignKey represents a foreign key constraint on a table's columns.

typeGCSReference

type GCSReference struct {// URIs refer to Google Cloud Storage objects.URIs []stringFileConfig// DestinationFormat is the format to use when writing exported files.// Allowed values are: CSV, Avro, JSON.  The default is CSV.// CSV is not supported for tables with nested or repeated fields.DestinationFormatDataFormat// Compression specifies the type of compression to apply when writing data// to Google Cloud Storage, or using this GCSReference as an ExternalData// source with CSV or JSON SourceFormat. Default is None.//// Avro files allow additional compression types: DEFLATE and SNAPPY.CompressionCompression}

GCSReference is a reference to one or more Google Cloud Storage objects, which together constitutean input or output to a BigQuery operation.

funcNewGCSReference

func NewGCSReference(uri ...string) *GCSReference

NewGCSReference constructs a reference to one or more Google Cloud Storage objects, which together constitute a data source or destination.In the simple case, a single URI in the form gs://bucket/object may refer to a single GCS object.Data may also be split into mutiple files, if multiple URIs or URIs containing wildcards are provided.Each URI may contain one '*' wildcard character, which (if present) must come after the bucket name.For more information about the treatment of wildcards and multiple URIs,seehttps://cloud.google.com/bigquery/exporting-data-from-bigquery#exportingmultiple

Example
package mainimport ("fmt""cloud.google.com/go/bigquery")func main() {gcsRef := bigquery.NewGCSReference("gs://my-bucket/my-object")fmt.Println(gcsRef)}

typeGoogleSheetsOptions

type GoogleSheetsOptions struct {// The number of rows at the top of a sheet that BigQuery will skip when// reading data.SkipLeadingRowsint64// Optionally specifies a more specific range of cells to include.// Typical format: sheet_name!top_left_cell_id:bottom_right_cell_id//// Example: sheet1!A1:B20Rangestring}

GoogleSheetsOptions are additional options for GoogleSheets external data sources.

typeHighCardinalityJoinadded inv1.68.0

type HighCardinalityJoin struct {// Count of left input rows.LeftRowsint64// Count of right input rows.RightRowsint64// Count of the output rows.OutputRowsint64// The index of the join operator in the ExplainQueryStep lists.StepIndexint64}

HighCardinalityJoin contains high cardinality join detailed information.

typeHivePartitioningModeadded inv1.14.0

type HivePartitioningModestring

HivePartitioningMode is used in conjunction with HivePartitioningOptions.

const (// AutoHivePartitioningMode automatically infers partitioning key and types.AutoHivePartitioningModeHivePartitioningMode = "AUTO"// StringHivePartitioningMode automatically infers partitioning keys and treats values as string.StringHivePartitioningModeHivePartitioningMode = "STRINGS"// CustomHivePartitioningMode allows custom definition of the external partitioning.CustomHivePartitioningModeHivePartitioningMode = "CUSTOM")

typeHivePartitioningOptionsadded inv1.14.0

type HivePartitioningOptions struct {// Mode defines which hive partitioning mode to use when reading data.ModeHivePartitioningMode// When hive partition detection is requested, a common prefix for// all source uris should be supplied.  The prefix must end immediately// before the partition key encoding begins.//// For example, consider files following this data layout.//   gs://bucket/path_to_table/dt=2019-01-01/country=BR/id=7/file.avro//   gs://bucket/path_to_table/dt=2018-12-31/country=CA/id=3/file.avro//// When hive partitioning is requested with either AUTO or STRINGS// detection, the common prefix can be either of// gs://bucket/path_to_table or gs://bucket/path_to_table/ (trailing// slash does not matter).SourceURIPrefixstring// If set to true, queries against this external table require// a partition filter to be present that can perform partition// elimination.  Hive-partitioned load jobs with this field// set to true will fail.RequirePartitionFilterbool}

HivePartitioningOptions defines the behavior of Hive partitioningwhen working with external data.

typeIdentifierFormatadded inv1.25.0

type IdentifierFormatstring

IdentifierFormat represents a how certain resource identifiers such as table referencesare formatted.

var (// StandardSQLID returns an identifier suitable for use with Standard SQL.StandardSQLIDIdentifierFormat = "SQL"// LegacySQLID returns an identifier suitable for use with Legacy SQL.LegacySQLIDIdentifierFormat = "LEGACY_SQL"// StorageAPIResourceID returns an identifier suitable for use with the Storage API.  Namely, it's for formatting// a table resource for invoking read and write functionality.StorageAPIResourceIDIdentifierFormat = "STORAGE_API_RESOURCE"// ErrUnknownIdentifierFormat is indicative of requesting an identifier in a format that is// not supported.ErrUnknownIdentifierFormat =errors.New("unknown identifier format"))

typeInputDataChangeadded inv1.68.0

type InputDataChange struct {// Records read difference percentage compared to a previous run.RecordsReadDiffPercentagefloat64}

InputDataChange contains details about the input data change insight.

typeInserter

type Inserter struct {// SkipInvalidRows causes rows containing invalid data to be silently// ignored. The default value is false, which causes the entire request to// fail if there is an attempt to insert an invalid row.SkipInvalidRowsbool// IgnoreUnknownValues causes values not matching the schema to be ignored.// The default value is false, which causes records containing such values// to be treated as invalid records.IgnoreUnknownValuesbool// A TableTemplateSuffix allows Inserters to create tables automatically.//// Experimental: this option is experimental and may be modified or removed in future versions,// regardless of any other documented package stability guarantees. In general,// the BigQuery team recommends the use of partitioned tables over sharding// tables by suffix.//// When you specify a suffix, the table you upload data to// will be used as a template for creating a new table, with the same schema,// called <table> + <suffix>.//// More information is available at//https://cloud.google.com/bigquery/streaming-data-into-bigquery#template-tablesTableTemplateSuffixstring// contains filtered or unexported fields}

An Inserter does streaming inserts into a BigQuery table.It is safe for concurrent use.

func (*Inserter)Put

func (u *Inserter) Put(ctxcontext.Context, src interface{}) (errerror)

Put uploads one or more rows to the BigQuery service.

If src is ValueSaver, then its Save method is called to produce a row for uploading.

If src is a struct or pointer to a struct, then a schema is inferred from itand used to create a StructSaver. The InsertID of the StructSaver will beempty.

If src is a slice of ValueSavers, structs, or struct pointers, then eachelement of the slice is treated as above, and multiple rows are uploaded.

Put returns a PutMultiError if one or more rows failed to be uploaded.The PutMultiError contains a RowInsertionError for each failed row.

Put will retry on temporary errors (seehttps://cloud.google.com/bigquery/troubleshooting-errors). This can resultin duplicate rows if you do not use insert IDs. Also, if the error persists,the call will run indefinitely. Pass a context with a timeout to preventhanging calls.

Example
package mainimport ("context""cloud.google.com/go/bigquery")type Item struct {Name  stringSize  float64Count int}// Save implements the ValueSaver interface.func (i *Item) Save() (map[string]bigquery.Value, string, error) {return map[string]bigquery.Value{"Name":  i.Name,"Size":  i.Size,"Count": i.Count,}, "", nil}func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ins := client.Dataset("my_dataset").Table("my_table").Inserter()// Item implements the ValueSaver interface.items := []*Item{{Name: "n1", Size: 32.6, Count: 7},{Name: "n2", Size: 4, Count: 2},{Name: "n3", Size: 101.5, Count: 1},}if err := ins.Put(ctx, items); err != nil {// TODO: Handle error.}}

Example (Struct)
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ins := client.Dataset("my_dataset").Table("my_table").Inserter()type score struct {Name stringNum  int}scores := []score{{Name: "n1", Num: 12},{Name: "n2", Num: 31},{Name: "n3", Num: 7},}// Schema is inferred from the score type.if err := ins.Put(ctx, scores); err != nil {// TODO: Handle error.}}

Example (StructSaver)
package mainimport ("context""cloud.google.com/go/bigquery")var schema bigquery.Schemafunc main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ins := client.Dataset("my_dataset").Table("my_table").Inserter()type score struct {Name stringNum  int}// Assume schema holds the table's schema.savers := []*bigquery.StructSaver{{Struct: score{Name: "n1", Num: 12}, Schema: schema, InsertID: "id1"},{Struct: score{Name: "n2", Num: 31}, Schema: schema, InsertID: "id2"},{Struct: score{Name: "n3", Num: 7}, Schema: schema, InsertID: "id3"},}if err := ins.Put(ctx, savers); err != nil {// TODO: Handle error.}}

Example (ValuesSaver)
package mainimport ("context""cloud.google.com/go/bigquery")var schema bigquery.Schemafunc main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ins := client.Dataset("my_dataset").Table("my_table").Inserter()var vss []*bigquery.ValuesSaverfor i, name := range []string{"n1", "n2", "n3"} {// Assume schema holds the table's schema.vss = append(vss, &bigquery.ValuesSaver{Schema:   schema,InsertID: name,Row:      []bigquery.Value{name, int64(i)},})}if err := ins.Put(ctx, vss); err != nil {// TODO: Handle error.}}

typeIntervalValueadded inv1.32.0

type IntervalValue struct {// In canonical form, Years and Months share a consistent sign and reduced// to avoid large month values.Yearsint32Monthsint32// In canonical form, Days are independent of the other parts and can have it's// own sign.  There is no attempt to reduce larger Day values into the Y-M part.Daysint32// In canonical form, the time parts all share a consistent sign and are reduced.Hoursint32Minutesint32Secondsint32// This represents the fractional seconds as nanoseconds.SubSecondNanosint32}

IntervalValue is a go type for representing BigQuery INTERVAL values.Intervals are represented using three distinct parts:* Years and Months* Days* Time (Hours/Mins/Seconds/Fractional Seconds).

More information about BigQuery INTERVAL types can be found at:https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#interval_type

IntervalValue is EXPERIMENTAL and subject to change or removal without notice.

funcIntervalValueFromDurationadded inv1.32.0

func IntervalValueFromDuration(intime.Duration) *IntervalValue

IntervalValueFromDuration converts a time.Duration to an IntervalType representation.

The converted duration only leverages the hours/minutes/seconds part of the interval,the other parts representing days, months, and years are not used.

funcParseIntervaladded inv1.32.0

func ParseInterval(valuestring) (*IntervalValue,error)

ParseInterval parses an interval in canonical string format and returns the IntervalValue it represents.

func (*IntervalValue)Canonicalizeadded inv1.32.0

func (iv *IntervalValue) Canonicalize() *IntervalValue

Canonicalize returns an IntervalValue where signs for elements in theY-M and H:M:S.F are consistent and values are normalized/reduced.

Canonical form enables more consistent comparison of the encodedinterval. For example, encoding an interval with 12 months is equivalentto an interval of 1 year.

func (*IntervalValue)IsCanonicaladded inv1.32.0

func (iv *IntervalValue) IsCanonical()bool

IsCanonical evaluates whether the current representation is in canonicalform.

func (*IntervalValue)Stringadded inv1.32.0

func (iv *IntervalValue) String()string

String returns string representation of the interval value using the canonical format.The canonical format is as follows:

[sign]Y-M [sign]D [sign]H:M:S[.F]

func (*IntervalValue)ToDurationadded inv1.32.0

func (iv *IntervalValue) ToDuration()time.Duration

ToDuration converts an interval to a time.Duration value.

For the purposes of conversion:Years are normalized to 12 months.Months are normalized to 30 days.Days are normalized to 24 hours.

typeJob

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

A Job represents an operation which has been submitted to BigQuery for processing.

func (*Job)Cancel

func (j *Job) Cancel(ctxcontext.Context)error

Cancel requests that a job be cancelled. This method returns without waiting forcancellation to take effect. To check whether the job has terminated, use Job.Status.Cancelled jobs may still incur costs.

func (*Job)Childrenadded inv1.2.0

func (j *Job) Children(ctxcontext.Context) *JobIterator

Children returns a job iterator for enumerating child jobsof the current job. Currently only scripts, a form of query job,will create child jobs.

func (*Job)Config

func (j *Job) Config() (JobConfig,error)

Config returns the configuration information for j.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ds := client.Dataset("my_dataset")job, err := ds.Table("t1").CopierFrom(ds.Table("t2")).Run(ctx)if err != nil {// TODO: Handle error.}jc, err := job.Config()if err != nil {// TODO: Handle error.}copyConfig := jc.(*bigquery.CopyConfig)fmt.Println(copyConfig.Dst, copyConfig.CreateDisposition)}

func (*Job)Deleteadded inv1.19.0

func (j *Job) Delete(ctxcontext.Context) (errerror)

Delete deletes the job.

func (*Job)Email

func (j *Job) Email()string

Email returns the email of the job's creator.

func (*Job)ID

func (j *Job) ID()string

ID returns the job's ID.

func (*Job)LastStatus

func (j *Job) LastStatus() *JobStatus

LastStatus returns the most recently retrieved status of the job. The status isretrieved when a new job is created, or when JobFromID or Job.Status is called.Call Job.Status to get the most up-to-date information about a job.

func (*Job)Location

func (j *Job) Location()string

Location returns the job's location.

func (*Job)ProjectIDadded inv1.19.0

func (j *Job) ProjectID()string

ProjectID returns the job's associated project.

func (*Job)Read

func (j *Job) Read(ctxcontext.Context) (ri *RowIterator, errerror)

Read fetches the results of a query job.If j is not a query job, Read returns an error.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}q := client.Query("select name, num from t1")// Call Query.Run to get a Job, then call Read on the job.// Note: Query.Read is a shorthand for this.job, err := q.Run(ctx)if err != nil {// TODO: Handle error.}it, err := job.Read(ctx)if err != nil {// TODO: Handle error.}_ = it // TODO: iterate using Next or iterator.Pager.}

func (*Job)Status

func (j *Job) Status(ctxcontext.Context) (js *JobStatus, errerror)

Status retrieves the current status of the job from BigQuery. It fails if the Status could not be determined.

func (*Job)Wait

func (j *Job) Wait(ctxcontext.Context) (js *JobStatus, errerror)

Wait blocks until the job or the context is done. It returns the final statusof the job.If an error occurs while retrieving the status, Wait returns that error. ButWait returns nil if the status was retrieved successfully, even ifstatus.Err() != nil. So callers must check both errors. See the example.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ds := client.Dataset("my_dataset")job, err := ds.Table("t1").CopierFrom(ds.Table("t2")).Run(ctx)if err != nil {// TODO: Handle error.}status, err := job.Wait(ctx)if err != nil {// TODO: Handle error.}if status.Err() != nil {// TODO: Handle error.}}

typeJobConfig

type JobConfig interface {// contains filtered or unexported methods}

JobConfig contains configuration information for a job. It is implemented by*CopyConfig, *ExtractConfig, *LoadConfig and *QueryConfig.

typeJobCreationModeadded inv1.69.0

type JobCreationModestring

JobCreationMode controls how job creation is handled. Some queries maybe run without creating a job to expedite fetching results.

var (// JobCreationModeUnspecified is the default (unspecified) option.JobCreationModeUnspecifiedJobCreationMode = "JOB_CREATION_MODE_UNSPECIFIED"// JobCreationModeRequired indicates job creation is required.JobCreationModeRequiredJobCreationMode = "JOB_CREATION_REQUIRED"// JobCreationModeOptional indicates job creation is optional, and returning// results immediately is prioritized.  The conditions under which BigQuery// can choose to avoid job creation are internal and subject to change.JobCreationModeOptionalJobCreationMode = "JOB_CREATION_OPTIONAL")

typeJobIDConfig

type JobIDConfig struct {// JobID is the ID to use for the job. If empty, a random job ID will be generated.JobIDstring// If AddJobIDSuffix is true, then a random string will be appended to JobID.AddJobIDSuffixbool// Location is the location for the job.Locationstring// ProjectID is the Google Cloud project associated with the job.ProjectIDstring}

JobIDConfig describes how to create an ID for a job.

typeJobIterator

type JobIterator struct {ProjectIDstring// Project ID of the jobs to list. Default is the client's project.AllUsersbool// Whether to list jobs owned by all users in the project, or just the current caller.StateState// List only jobs in the given state. Defaults to all states.MinCreationTimetime.Time// List only jobs created after this time.MaxCreationTimetime.Time// List only jobs created before this time.ParentJobIDstring// List only jobs that are children of a given scripting job.// contains filtered or unexported fields}

JobIterator iterates over jobs in a project.

func (*JobIterator)Next

func (it *JobIterator) Next() (*Job,error)

Next returns the next Job. Its second return value is iterator.Done ifthere are no more results. Once Next returns Done, all subsequent calls willreturn Done.

func (*JobIterator)PageInfo

func (it *JobIterator) PageInfo() *iterator.PageInfo

PageInfo is a getter for the JobIterator's PageInfo.

typeJobStatistics

type JobStatistics struct {// CreationTime is the creation time of this job.// This field will be present on all jobs.CreationTimetime.Time// StartTime is the start time of this job.// This field will be present when the job transitions from the PENDING state to either RUNNING or DONE.StartTimetime.Time// EndTime is the end time of this job.// This field will be present whenever a job is in the DONE state.EndTimetime.Time// TotalBytesProcessed is the total bytes processed for the job.TotalBytesProcessedint64// Details is the jobType-specific statistics for the jobDetailsStatistics// TotalSlotDuration is the slot duration for the job.TotalSlotDurationtime.Duration// ReservationUsage attributes slot consumption to reservations.// This field reported misleading information and will no longer be populated.ReservationUsage []*ReservationUsage// ReservationID is the name of the primary reservation assigned to this job.// Note that this could be different than reservations reported in the reservation// usage field if parent reservations were used to execute this job.ReservationIDstring// NumChildJobs indicates the number of child jobs run as part of a script.NumChildJobsint64// ParentJobID indicates the origin job for jobs run as part of a script.ParentJobIDstring// ScriptStatistics includes information run as part of a child job within// a script.ScriptStatistics *ScriptStatistics// TransactionInfo indicates the transaction ID associated with the job, if any.TransactionInfo *TransactionInfo// SessionInfo contains information about the session if this job is part of one.SessionInfo *SessionInfo// FinalExecutionDuration is the duration of the execution of the final// attempt of this job, as BigQuery may internally re-attempt to execute the job.FinalExecutionDurationtime.Duration// Edition is the name of edition corresponding to the reservation for this job// at the time of this update.EditionReservationEdition// Job progress (0.0 -> 1.0) for LOAD and EXTRACT jobs.CompletionRatiofloat64}

JobStatistics contains statistics about a job.

typeJobStatus

type JobStatus struct {StateState// All errors encountered during the running of the job.// Not all Errors are fatal, so errors here do not necessarily mean that the job has completed or was unsuccessful.Errors []*Error// Statistics about the job.Statistics *JobStatistics// contains filtered or unexported fields}

JobStatus contains the current State of a job, and errors encountered while processing that job.

func (*JobStatus)Done

func (s *JobStatus) Done()bool

Done reports whether the job has completed.After Done returns true, the Err method will return an error if the job completed unsuccessfully.

func (*JobStatus)Err

func (s *JobStatus) Err()error

Err returns the error that caused the job to complete unsuccessfully (if any).

typeLoadConfig

type LoadConfig struct {// Src is the source from which data will be loaded.SrcLoadSource// Dst is the table into which the data will be loaded.Dst *Table// CreateDisposition specifies the circumstances under which the destination table will be created.// The default is CreateIfNeeded.CreateDispositionTableCreateDisposition// WriteDisposition specifies how existing data in the destination table is treated.// The default is WriteAppend.WriteDispositionTableWriteDisposition// The labels associated with this job.Labels map[string]string// If non-nil, the destination table is partitioned by time.TimePartitioning *TimePartitioning// If non-nil, the destination table is partitioned by integer range.RangePartitioning *RangePartitioning// Clustering specifies the data clustering configuration for the destination table.Clustering *Clustering// Custom encryption configuration (e.g., Cloud KMS keys).DestinationEncryptionConfig *EncryptionConfig// Allows the schema of the destination table to be updated as a side effect of// the load job.SchemaUpdateOptions []string// For Avro-based loads, controls whether logical type annotations are used.// Seehttps://cloud.google.com/bigquery/docs/loading-data-cloud-storage-avro#logical_types// for additional information.UseAvroLogicalTypesbool// For ingestion from datastore backups, ProjectionFields governs which fields// are projected from the backup.  The default behavior projects all fields.ProjectionFields []string// HivePartitioningOptions allows use of Hive partitioning based on the// layout of objects in Cloud Storage.HivePartitioningOptions *HivePartitioningOptions// DecimalTargetTypes allows selection of how decimal values are converted when// processed in bigquery, subject to the value type having sufficient precision/scale// to support the values.  In the order of NUMERIC, BIGNUMERIC, and STRING, a type is// selected if is present in the list and if supports the necessary precision and scale.//// StringTargetType supports all precision and scale values.DecimalTargetTypes []DecimalTargetType// Sets a best-effort deadline on a specific job.  If job execution exceeds this// timeout, BigQuery may attempt to cancel this work automatically.//// This deadline cannot be adjusted or removed once the job is created.  Consider// using Job.Cancel in situations where you need more dynamic behavior.//// Experimental: this option is experimental and may be modified or removed in future versions,// regardless of any other documented package stability guarantees.JobTimeouttime.Duration// When loading a table with external data, the user can provide a reference file with the table schema.// This is enabled for the following formats: AVRO, PARQUET, ORC.ReferenceFileSchemaURIstring// If true, creates a new session, where session id will// be a server generated random id. If false, runs query with an// existing session_id passed in ConnectionProperty, otherwise runs the// load job in non-session mode.CreateSessionbool// ConnectionProperties are optional key-values settings.ConnectionProperties []*ConnectionProperty// MediaOptions stores options for customizing media upload.MediaOptions []googleapi.MediaOption// Controls the behavior of column naming during a load job.// For more information, see://https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#columnnamecharactermapColumnNameCharacterMapColumnNameCharacterMap// The reservation that job would use. User can specify a reservation to// execute the job. If reservation is not set, reservation is determined// based on the rules defined by the reservation assignments. The expected// format is// `projects/{project}/locations/{location}/reservations/{reservation}`.Reservationstring// A target limit on the rate of slot consumption by this query. If set to a// value > 0, BigQuery will attempt to limit the rate of slot consumption by// this query to keep it below the configured limit, even if the query is// eligible for more slots based on fair scheduling. The unused slots will be// available for other jobs and queries to use.//// Note: This feature is not yet generally available.MaxSlotsint32}

LoadConfig holds the configuration for a load job.

typeLoadSource

type LoadSource interface {// contains filtered or unexported methods}

A LoadSource represents a source of data that can be loaded intoa BigQuery table.

This package defines two LoadSources: GCSReference, for Google Cloud Storageobjects, and ReaderSource, for data read from an io.Reader.

typeLoadStatistics

type LoadStatistics struct {// The number of bytes of source data in a load job.InputFileBytesint64// The number of source files in a load job.InputFilesint64// Size of the loaded data in bytes. Note that while a load job is in the// running state, this value may change.OutputBytesint64// The number of rows imported in a load job. Note that while an import job is// in the running state, this value may change.OutputRowsint64}

LoadStatistics contains statistics about a load job.

typeLoader

type Loader struct {JobIDConfigLoadConfig// contains filtered or unexported fields}

A Loader loads data from Google Cloud Storage into a BigQuery table.

func (*Loader)Run

func (l *Loader) Run(ctxcontext.Context) (j *Job, errerror)

Run initiates a load job.

typeMaterializedViewDefinitionadded inv1.6.0

type MaterializedViewDefinition struct {// EnableRefresh governs whether the derived view is updated to reflect// changes in the base table.EnableRefreshbool// LastRefreshTime reports the time, in millisecond precision, that the// materialized view was last updated.LastRefreshTimetime.Time// Query contains the SQL query used to define the materialized view.Querystring// RefreshInterval defines the maximum frequency, in millisecond precision,// at which this this materialized view will be refreshed.RefreshIntervaltime.Duration// AllowNonIncrementalDefinition for materialized view definition.// The default value is false.AllowNonIncrementalDefinitionbool// MaxStaleness of data that could be returned when materialized// view is queried.//// Deprecated: use Table level MaxStaleness.MaxStaleness *IntervalValue}

MaterializedViewDefinition contains information for materialized views.

typeMetadataCacheModeadded inv1.67.0

type MetadataCacheModestring

MetadataCacheMode describes the types of metadata cache mode for external data.

const (// Automatic metadata cache mode triggers automatic background refresh of// metadata cache from the external source. Queries will use the latest// available cache version within the table's maxStaleness interval.AutomaticMetadataCacheMode = "AUTOMATIC"// Manual metadata cache mode triggers manual refresh of the// metadata cache from external source. Queries will use the latest manually// triggered cache version within the table's maxStaleness interval.ManualMetadataCacheMode = "MANUAL")

Constants describing types of metadata cache mode for external data.

typeModel

type Model struct {ProjectIDstringDatasetIDstring// ModelID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_).// The maximum length is 1,024 characters.ModelIDstring// contains filtered or unexported fields}

Model represent a reference to a BigQuery ML model.Within the API, models are used largely for communicatingstatistical information about a given model, as creation of models is onlysupported via BigQuery queries (e.g. CREATE MODEL .. AS ..).

For more info, see documentation for Bigquery ML,see:https://cloud.google.com/bigquery/docs/bigqueryml

func (*Model)Delete

func (m *Model) Delete(ctxcontext.Context) (errerror)

Delete deletes an ML model.

func (*Model)ExtractorToadded inv1.7.0

func (m *Model) ExtractorTo(dst *GCSReference) *Extractor

ExtractorTo returns an Extractor which can be persist a BigQuery Model intoGoogle Cloud Storage.The returned Extractor may be further configured before its Run method is called.

func (*Model)FullyQualifiedName

func (m *Model) FullyQualifiedName()string

FullyQualifiedName returns the ID of the model in projectID:datasetID.modelid format.

func (*Model)Identifieradded inv1.25.0

func (m *Model) Identifier(fIdentifierFormat) (string,error)

Identifier returns the ID of the model in the requested format.

For Standard SQL format, the identifier will be quoted if theProjectID contains dash (-) characters.

func (*Model)Metadata

func (m *Model) Metadata(ctxcontext.Context) (mm *ModelMetadata, errerror)

Metadata fetches the metadata for a model, which includes ML training statistics.

func (*Model)Update

func (m *Model) Update(ctxcontext.Context, mmModelMetadataToUpdate, etagstring) (md *ModelMetadata, errerror)

Update updates mutable fields in an ML model.

typeModelIterator

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

A ModelIterator is an iterator over Models.

func (*ModelIterator)Next

func (it *ModelIterator) Next() (*Model,error)

Next returns the next result. Its second return value is Done if there areno more results. Once Next returns Done, all subsequent calls will returnDone.

func (*ModelIterator)PageInfo

func (it *ModelIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

typeModelMetadata

type ModelMetadata struct {// The user-friendly description of the model.Descriptionstring// The user-friendly name of the model.Namestring// The type of the model.  Possible values include:// "LINEAR_REGRESSION" - a linear regression model// "LOGISTIC_REGRESSION" - a logistic regression model// "KMEANS" - a k-means clustering modelTypestring// The creation time of the model.CreationTimetime.Time// The last modified time of the model.LastModifiedTimetime.Time// The expiration time of the model.ExpirationTimetime.Time// The geographic location where the model resides.  This value is// inherited from the encapsulating dataset.Locationstring// Custom encryption configuration (e.g., Cloud KMS keys).EncryptionConfig *EncryptionConfigLabels map[string]string// ETag is the ETag obtained when reading metadata. Pass it to Model.Update// to ensure that the metadata hasn't changed since it was read.ETagstring// contains filtered or unexported fields}

ModelMetadata represents information about a BigQuery ML model.

func (*ModelMetadata)RawFeatureColumns

func (mm *ModelMetadata) RawFeatureColumns() ([]*StandardSQLField,error)

RawFeatureColumns exposes the underlying feature columns used to train an ML model and uses types from"google.golang.org/api/bigquery/v2", which are subject to change without warning.It is EXPERIMENTAL and subject to change or removal without notice.

func (*ModelMetadata)RawLabelColumns

func (mm *ModelMetadata) RawLabelColumns() ([]*StandardSQLField,error)

RawLabelColumns exposes the underlying label columns used to train an ML model and uses types from"google.golang.org/api/bigquery/v2", which are subject to change without warning.It is EXPERIMENTAL and subject to change or removal without notice.

func (*ModelMetadata)RawTrainingRuns

func (mm *ModelMetadata) RawTrainingRuns() []*TrainingRun

RawTrainingRuns exposes the underlying training run stats for a model using types from"google.golang.org/api/bigquery/v2", which are subject to change without warning.It is EXPERIMENTAL and subject to change or removal without notice.

typeModelMetadataToUpdate

type ModelMetadataToUpdate struct {// The user-friendly description of this model.Descriptionoptional.String// The user-friendly name of this model.Nameoptional.String// The time when this model expires.  To remove a model's expiration,// set ExpirationTime to NeverExpire.  The zero value is ignored.ExpirationTimetime.Time// The model's encryption configuration.EncryptionConfig *EncryptionConfig// contains filtered or unexported fields}

ModelMetadataToUpdate is used when updating an ML model's metadata.Only non-nil fields will be updated.

func (*ModelMetadataToUpdate)DeleteLabel

func (u *ModelMetadataToUpdate) DeleteLabel(namestring)

DeleteLabel causes a label to be deleted on a call to Update.

func (*ModelMetadataToUpdate)SetLabel

func (u *ModelMetadataToUpdate) SetLabel(name, valuestring)

SetLabel causes a label to be added or modified on a call to Update.

typeMultiError

type MultiError []error

A MultiError contains multiple related errors.

func (MultiError)Error

func (mMultiError) Error()string

typeNullBool

type NullBool struct {BoolboolValidbool// Valid is true if Bool is not NULL.}

NullBool represents a BigQuery BOOL that may be NULL.

func (NullBool)MarshalJSON

func (nNullBool) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullBool to JSON.

func (NullBool)String

func (nNullBool) String()string

func (*NullBool)UnmarshalJSON

func (n *NullBool) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullBool.

typeNullDate

type NullDate struct {Datecivil.DateValidbool// Valid is true if Date is not NULL.}

NullDate represents a BigQuery DATE that may be null.

func (NullDate)MarshalJSON

func (nNullDate) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullDate to JSON.

func (NullDate)String

func (nNullDate) String()string

func (*NullDate)UnmarshalJSON

func (n *NullDate) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullDate.

typeNullDateTime

type NullDateTime struct {DateTimecivil.DateTimeValidbool// Valid is true if DateTime is not NULL.}

NullDateTime represents a BigQuery DATETIME that may be null.

func (NullDateTime)MarshalJSON

func (nNullDateTime) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullDateTime to JSON.

func (NullDateTime)String

func (nNullDateTime) String()string

func (*NullDateTime)UnmarshalJSON

func (n *NullDateTime) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullDateTime.

typeNullFloat64

type NullFloat64 struct {Float64float64Validbool// Valid is true if Float64 is not NULL.}

NullFloat64 represents a BigQuery FLOAT64 that may be NULL.

func (NullFloat64)MarshalJSON

func (nNullFloat64) MarshalJSON() (b []byte, errerror)

MarshalJSON converts the NullFloat64 to JSON.

func (NullFloat64)String

func (nNullFloat64) String()string

func (*NullFloat64)UnmarshalJSON

func (n *NullFloat64) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullFloat64.

typeNullGeography

type NullGeography struct {GeographyValstringValidbool// Valid is true if GeographyVal is not NULL.}

NullGeography represents a BigQuery GEOGRAPHY string that may be NULL.

func (NullGeography)MarshalJSON

func (nNullGeography) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullGeography to JSON.

func (NullGeography)String

func (nNullGeography) String()string

func (*NullGeography)UnmarshalJSON

func (n *NullGeography) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullGeography.

typeNullInt64

type NullInt64 struct {Int64int64Validbool// Valid is true if Int64 is not NULL.}

NullInt64 represents a BigQuery INT64 that may be NULL.

func (NullInt64)MarshalJSON

func (nNullInt64) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullInt64 to JSON.

func (NullInt64)String

func (nNullInt64) String()string

func (*NullInt64)UnmarshalJSON

func (n *NullInt64) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullInt64.

typeNullJSONadded inv1.37.0

type NullJSON struct {JSONValstringValidbool// Valid is true if JSONVal is not NULL.}

NullJSON represents a BigQuery JSON string that may be NULL.

func (NullJSON)MarshalJSONadded inv1.37.0

func (nNullJSON) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullJSON to JSON.

func (NullJSON)Stringadded inv1.37.0

func (nNullJSON) String()string

func (*NullJSON)UnmarshalJSONadded inv1.37.0

func (n *NullJSON) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullJSON.

typeNullString

type NullString struct {StringValstringValidbool// Valid is true if StringVal is not NULL.}

NullString represents a BigQuery STRING that may be NULL.

func (NullString)MarshalJSON

func (nNullString) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullString to JSON.

func (NullString)String

func (nNullString) String()string

func (*NullString)UnmarshalJSON

func (n *NullString) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullString.

typeNullTime

type NullTime struct {Timecivil.TimeValidbool// Valid is true if Time is not NULL.}

NullTime represents a BigQuery TIME that may be null.

func (NullTime)MarshalJSON

func (nNullTime) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullTime to JSON.

func (NullTime)String

func (nNullTime) String()string

func (*NullTime)UnmarshalJSON

func (n *NullTime) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullTime.

typeNullTimestamp

type NullTimestamp struct {Timestamptime.TimeValidbool// Valid is true if Time is not NULL.}

NullTimestamp represents a BigQuery TIMESTAMP that may be null.

func (NullTimestamp)MarshalJSON

func (nNullTimestamp) MarshalJSON() ([]byte,error)

MarshalJSON converts the NullTimestamp to JSON.

func (NullTimestamp)String

func (nNullTimestamp) String()string

func (*NullTimestamp)UnmarshalJSON

func (n *NullTimestamp) UnmarshalJSON(b []byte)error

UnmarshalJSON converts JSON into a NullTimestamp.

typeParquetOptionsadded inv1.18.0

type ParquetOptions struct {// EnumAsString indicates whether to infer Parquet ENUM logical type as// STRING instead of BYTES by default.EnumAsStringbool// EnableListInference indicates whether to use schema inference// specifically for Parquet LIST logical type.EnableListInferencebool}

ParquetOptions are additional options for Parquet external data sources.

typePartitionSkewadded inv1.68.0

type PartitionSkew struct {// Source stages which produce skewed data.SkewSources []*SkewSource}

PartitionSkew contains partition skew detailed information.

typePerformanceInsightsadded inv1.68.0

type PerformanceInsights struct {// Average execution of previous runs.AvgPreviousExecutiontime.Duration// Standalone query stage performance insights, for exploring potential improvements.StagePerformanceStandaloneInsights []*StagePerformanceStandaloneInsight// jobs.query stage performance insights compared to previous runs, for diagnosing performance regression.StagePerformanceChangeInsights []*StagePerformanceChangeInsight}

PerformanceInsights contains performance insights for the job.

typePolicyTagListadded inv1.6.0

type PolicyTagList struct {Names []string}

PolicyTagList represents the annotations on a schema column for enforcing column-level security.For more information, seehttps://cloud.google.com/bigquery/docs/column-level-security-intro

typePrimaryKeyadded inv1.52.0

type PrimaryKey struct {// Columns that compose the primary key constraint.Columns []string}

PrimaryKey represents the primary key constraint on a table's columns.

typePutMultiError

type PutMultiError []RowInsertionError

PutMultiError contains an error for each row which was not successfully insertedinto a BigQuery table.

func (PutMultiError)Error

func (pmePutMultiError) Error()string

typeQuery

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

A Query queries data from a BigQuery table. Use Client.Query to create a Query.

func (*Query)Read

func (q *Query) Read(ctxcontext.Context) (it *RowIterator, errerror)

Read submits a query for execution and returns the results via a RowIterator.If the request can be satisfied by running using the optimized query path, itis used in place of the jobs.insert path as this path does not expose a jobobject.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}q := client.Query("select name, num from t1")it, err := q.Read(ctx)if err != nil {// TODO: Handle error.}_ = it // TODO: iterate using Next or iterator.Pager.}

Example (Accelerated)
package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}// Enable Storage API usage for fetching dataerr = client.EnableStorageReadClient(ctx)if err != nil {// TODO: Handle error.}sql := fmt.Sprintf(`SELECT name, number, state FROM %s WHERE state = "CA"`, `bigquery-public-data.usa_names.usa_1910_current`)q := client.Query(sql)it, err := q.Read(ctx)if err != nil {// TODO: Handle error.}_ = it // TODO: iterate using Next or iterator.Pager.}

func (*Query)Run

func (q *Query) Run(ctxcontext.Context) (j *Job, errerror)

Run initiates a query job.

typeQueryConfig

type QueryConfig struct {// Dst is the table into which the results of the query will be written.// If this field is nil, a temporary table will be created.Dst *Table// The query to execute. Seehttps://cloud.google.com/bigquery/query-reference for details.Qstring// DefaultProjectID and DefaultDatasetID specify the dataset to use for unqualified table names in the query.// If DefaultProjectID is set, DefaultDatasetID must also be set.DefaultProjectIDstringDefaultDatasetIDstring// TableDefinitions describes data sources outside of BigQuery.// The map keys may be used as table names in the query string.//// When a QueryConfig is returned from Job.Config, the map values// are always of type *ExternalDataConfig.TableDefinitions map[string]ExternalData// CreateDisposition specifies the circumstances under which the destination table will be created.// The default is CreateIfNeeded.CreateDispositionTableCreateDisposition// WriteDisposition specifies how existing data in the destination table is treated.// The default is WriteEmpty.WriteDispositionTableWriteDisposition// DisableQueryCache prevents results being fetched from the query cache.// If this field is false, results are fetched from the cache if they are available.// The query cache is a best-effort cache that is flushed whenever tables in the query are modified.// Cached results are only available when TableID is unspecified in the query's destination Table.// For more information, seehttps://cloud.google.com/bigquery/querying-data#querycachingDisableQueryCachebool// DisableFlattenedResults prevents results being flattened.// If this field is false, results from nested and repeated fields are flattened.// DisableFlattenedResults implies AllowLargeResults// For more information, seehttps://cloud.google.com/bigquery/docs/data#nestedDisableFlattenedResultsbool// AllowLargeResults allows the query to produce arbitrarily large result tables.// The destination must be a table.// When using this option, queries will take longer to execute, even if the result set is small.// For additional limitations, seehttps://cloud.google.com/bigquery/querying-data#largequeryresultsAllowLargeResultsbool// Priority specifies the priority with which to schedule the query.// The default priority is InteractivePriority.// For more information, seehttps://cloud.google.com/bigquery/querying-data#batchqueriesPriorityQueryPriority// MaxBillingTier sets the maximum billing tier for a Query.// Queries that have resource usage beyond this tier will fail (without// incurring a charge). If this field is zero, the project default will be used.MaxBillingTierint// MaxBytesBilled limits the number of bytes billed for// this job.  Queries that would exceed this limit will fail (without incurring// a charge).// If this field is less than 1, the project default will be// used.MaxBytesBilledint64// UseStandardSQL causes the query to use standard SQL. The default.// Deprecated: use UseLegacySQL.UseStandardSQLbool// UseLegacySQL causes the query to use legacy SQL.UseLegacySQLbool// Parameters is a list of query parameters. The presence of parameters// implies the use of standard SQL.// If the query uses positional syntax ("?"), then no parameter may have a name.// If the query uses named syntax ("@p"), then all parameters must have names.// It is illegal to mix positional and named syntax.Parameters []QueryParameter// TimePartitioning specifies time-based partitioning// for the destination table.TimePartitioning *TimePartitioning// RangePartitioning specifies integer range-based partitioning// for the destination table.RangePartitioning *RangePartitioning// Clustering specifies the data clustering configuration for the destination table.Clustering *Clustering// The labels associated with this job.Labels map[string]string// If true, don't actually run this job. A valid query will return a mostly// empty response with some processing statistics, while an invalid query will// return the same error it would if it wasn't a dry run.//// Query.Read will fail with dry-run queries. Call Query.Run instead, and then// call LastStatus on the returned job to get statistics. Calling Status on a// dry-run job will fail.DryRunbool// Custom encryption configuration (e.g., Cloud KMS keys).DestinationEncryptionConfig *EncryptionConfig// Allows the schema of the destination table to be updated as a side effect of// the query job.SchemaUpdateOptions []string// CreateSession will trigger creation of a new session when true.CreateSessionbool// ConnectionProperties are optional key-values settings.ConnectionProperties []*ConnectionProperty// Sets a best-effort deadline on a specific job.  If job execution exceeds this// timeout, BigQuery may attempt to cancel this work automatically.//// This deadline cannot be adjusted or removed once the job is created.  Consider// using Job.Cancel in situations where you need more dynamic behavior.//// Experimental: this option is experimental and may be modified or removed in future versions,// regardless of any other documented package stability guarantees.JobTimeouttime.Duration// The reservation that job would use. User can specify a reservation to// execute the job. If reservation is not set, reservation is determined// based on the rules defined by the reservation assignments. The expected// format is// `projects/{project}/locations/{location}/reservations/{reservation}`.Reservationstring// A target limit on the rate of slot consumption by this query. If set to a// value > 0, BigQuery will attempt to limit the rate of slot consumption by// this query to keep it below the configured limit, even if the query is// eligible for more slots based on fair scheduling. The unused slots will be// available for other jobs and queries to use.//// Note: This feature is not yet generally available.MaxSlotsint32// Whether to run the query as continuous or a regular query.Continuousbool// contains filtered or unexported fields}

QueryConfig holds the configuration for a query job.

typeQueryParameter

type QueryParameter struct {// Name is used for named parameter mode.// It must match the name in the query case-insensitively.Namestring// Value is the value of the parameter.//// When you create a QueryParameter to send to BigQuery, the following Go types// are supported, with their corresponding Bigquery types:// int, int8, int16, int32, int64, uint8, uint16, uint32: INT64//   Note that uint, uint64 and uintptr are not supported, because//   they may contain values that cannot fit into a 64-bit signed integer.// float32, float64: FLOAT64// bool: BOOL// string: STRING// []byte: BYTES// time.Time: TIMESTAMP// *big.Rat: NUMERIC// *IntervalValue: INTERVAL// Arrays and slices of the above.// Structs of the above. Only the exported fields are used.//// For scalar values, you can supply the Null types within this library// to send the appropriate NULL values (e.g. NullInt64, NullString, etc).//// To specify query parameters explicitly rather by inference, *QueryParameterValue can be used.// For example, a BIGNUMERIC can be specified like this:// &QueryParameterValue{//Type: StandardSQLDataType{//TypeKind: "BIGNUMERIC",//},//Value: BigNumericString(*big.Rat),//}//// When a QueryParameter is returned inside a QueryConfig from a call to// Job.Config:// Integers are of type int64.// Floating-point values are of type float64.// Arrays are of type []interface{}, regardless of the array element type.// Structs are of type map[string]interface{}.//// When valid (non-null) Null types are sent, they come back as the Go types indicated// above.  Null strings will report in query statistics as a valid empty// string.Value interface{}}

A QueryParameter is a parameter to a query.

typeQueryParameterValueadded inv1.42.0

type QueryParameterValue struct {// Type specifies the parameter type. See StandardSQLDataType for more.// Scalar parameters and more complex types can be defined within this field.// See examples on the value fields.TypeStandardSQLDataType// Value is the value of the parameter, if a simple scalar type.// The default behavior for scalar values is to do type inference// and format it accordingly.// Because of that, depending on the parameter type, is recommended// to send value as a String.// We provide some formatter functions for some types://   CivilTimeString(civil.Time)//   CivilDateTimeString(civil.DateTime)//   NumericString(*big.Rat)//   BigNumericString(*big.Rat)//   IntervalString(*IntervalValue)//// Example://// &QueryParameterValue{// Type: StandardSQLDataType{//TypeKind: "BIGNUMERIC",//},//Value: BigNumericString(*big.Rat),//}Value interface{}// ArrayValue is the array of values for the parameter.//// Must be used with QueryParameterValue.Type being a StandardSQLDataType// with ArrayElementType filled with the given element type.//// Example of an array of strings :// &QueryParameterValue{//Type: &StandardSQLDataType{// ArrayElementType: &StandardSQLDataType{//TypeKind: "STRING",//},//},//ArrayValue: []QueryParameterValue{//{Value: "a"},//{Value: "b"},//},//}//// Example of an array of structs :// &QueryParameterValue{//Type: &StandardSQLDataType{// ArrayElementType: &StandardSQLDataType{// StructType: &StandardSQLDataType{//Fields: []*StandardSQLField{//{//Name: "NumberField",//Type: &StandardSQLDataType{//TypeKind: "INT64",//},//},//},//},//},// },//ArrayValue: []QueryParameterValue{//{StructValue: map[string]QueryParameterValue{//"NumberField": {//Value: int64(42),//},// }},// {StructValue: map[string]QueryParameterValue{//"NumberField": {//Value: int64(43),//},// }},//},//}ArrayValue []QueryParameterValue// StructValue is the struct field values for the parameter.//// Must be used with QueryParameterValue.Type being a StandardSQLDataType// with StructType filled with the given field types.//// Example://// &QueryParameterValue{//Type: &StandardSQLDataType{// StructType{//Fields: []*StandardSQLField{//{//Name: "StringField",//Type: &StandardSQLDataType{//TypeKind: "STRING",//},//},//{//Name: "NumberField",//Type: &StandardSQLDataType{//TypeKind: "INT64",//},//},//},//},//},//StructValue: []map[string]QueryParameterValue{//"NumberField": {//Value: int64(42),//},//"StringField": {//Value: "Value",//},//},//}StructValue map[string]QueryParameterValue}

QueryParameterValue is a go type for representing a explicit typed QueryParameter.

typeQueryPriority

type QueryPrioritystring

QueryPriority specifies a priority with which a query is to be executed.

const (// BatchPriority specifies that the query should be scheduled with the// batch priority.  BigQuery queues each batch query on your behalf, and// starts the query as soon as idle resources are available, usually within// a few minutes. If BigQuery hasn't started the query within 24 hours,// BigQuery changes the job priority to interactive. Batch queries don't// count towards your concurrent rate limit, which can make it easier to// start many queries at once.//// More information can be found athttps://cloud.google.com/bigquery/docs/running-queries#batchqueries.BatchPriorityQueryPriority = "BATCH"// InteractivePriority specifies that the query should be scheduled with// interactive priority, which means that the query is executed as soon as// possible. Interactive queries count towards your concurrent rate limit// and your daily limit. It is the default priority with which queries get// executed.//// More information can be found athttps://cloud.google.com/bigquery/docs/running-queries#queries.InteractivePriorityQueryPriority = "INTERACTIVE")

typeQueryStatistics

type QueryStatistics struct {// BI-Engine specific statistics.BIEngineStatistics *BIEngineStatistics// Billing tier for the job.BillingTierint64// Whether the query result was fetched from the query cache.CacheHitbool// The type of query statement, if valid.StatementTypestring// Total bytes billed for the job.TotalBytesBilledint64// Total bytes processed for the job.TotalBytesProcessedint64// For dry run queries, indicates how accurate the TotalBytesProcessed value is.// When indicated, values include:// UNKNOWN: accuracy of the estimate is unknown.// PRECISE: estimate is precise.// LOWER_BOUND: estimate is lower bound of what the query would cost.// UPPER_BOUND: estimate is upper bound of what the query would cost.TotalBytesProcessedAccuracystring// Describes execution plan for the query.QueryPlan []*ExplainQueryStage// The number of rows affected by a DML statement. Present only for DML// statements INSERT, UPDATE or DELETE.NumDMLAffectedRowsint64// DMLStats provides statistics about the row mutations performed by// DML statements.DMLStats *DMLStatistics// Describes a timeline of job execution.Timeline []*QueryTimelineSample// ReferencedTables: [Output-only] Referenced tables for// the job. Queries that reference more than 50 tables will not have a// complete list.ReferencedTables []*Table// The schema of the results. Present only for successful dry run of// non-legacy SQL queries.SchemaSchema// Slot-milliseconds consumed by this query job.SlotMillisint64// Standard SQL: list of undeclared query parameter names detected during a// dry run validation.UndeclaredQueryParameterNames []string// DDL target table.DDLTargetTable *Table// DDL Operation performed on the target table.  Used to report how the// query impacted the DDL target table.DDLOperationPerformedstring// The DDL target table, present only for CREATE/DROP FUNCTION/PROCEDURE queries.DDLTargetRoutine *Routine// Statistics for the EXPORT DATA statement as part of Query Job.ExportDataStatistics *ExportDataStatistics// Performance insights.PerformanceInsights *PerformanceInsights}

QueryStatistics contains statistics about a query job.

typeQueryTimelineSample

type QueryTimelineSample struct {// Total number of units currently being processed by workers, represented as largest value since last sample.ActiveUnitsint64// Total parallel units of work completed by this query.CompletedUnitsint64// Time elapsed since start of query execution.Elapsedtime.Duration// Total parallel units of work remaining for the active stages.PendingUnitsint64// Cumulative slot-milliseconds consumed by the query.SlotMillisint64}

QueryTimelineSample represents a sample of execution statistics at a point in time.

typeRangeElementTypeadded inv1.58.0

type RangeElementType struct {// The subtype of the RANGE, if the type of this field is RANGE.// Possible values for the field element type of a RANGE include:// DATE, DATETIME, or TIMESTAMP.TypeFieldType}

RangeElementType describes information about the range type.

typeRangePartitioningadded inv1.3.0

type RangePartitioning struct {// The field by which the table is partitioned.// This field must be a top-level field, and must be typed as an// INTEGER/INT64.Fieldstring// The details of how partitions are mapped onto the integer range.Range *RangePartitioningRange}

RangePartitioning indicates an integer-range based storage organization strategy.

typeRangePartitioningRangeadded inv1.3.0

type RangePartitioningRange struct {// The start value of defined range of values, inclusive of the specified value.Startint64// The end of the defined range of values, exclusive of the defined value.Endint64// The width of each interval range.Intervalint64}

RangePartitioningRange defines the boundaries and width of partitioned values.

typeRangeValueadded inv1.61.0

type RangeValue struct {// The start value of the range.  A missing value represents an// unbounded start.StartValue `json:"start"`// The end value of the range.  A missing value represents an// unbounded end.EndValue `json:"end"`}

RangeValue represents a continuous RANGE of values of a given elementtype. The supported element types for RANGE are currently the BigQueryDATE, DATETIME, and TIMESTAMP, types.

typeReaderSource

type ReaderSource struct {FileConfig// contains filtered or unexported fields}

A ReaderSource is a source for a load operation that getsdata from an io.Reader.

When a ReaderSource is part of a LoadConfig obtained via Job.Config,its internal io.Reader will be nil, so it cannot be used for asubsequent load operation.

funcNewReaderSource

func NewReaderSource(rio.Reader) *ReaderSource

NewReaderSource creates a ReaderSource from an io.Reader. You mayoptionally configure properties on the ReaderSource that describe thedata being read, before passing it to Table.LoaderFrom.

typeRemoteFunctionOptionsadded inv1.43.0

type RemoteFunctionOptions struct {// Fully qualified name of the user-provided connection object which holds// the authentication information to send requests to the remote service.// Format:// projects/{projectId}/locations/{locationId}/connections/{connectionId}Connectionstring// Endpoint of the user-provided remote service (e.g. a function url in// Google Cloud Function or Cloud Run )Endpointstring// Max number of rows in each batch sent to the remote service.// If absent or if 0, it means no limit.MaxBatchingRowsint64// User-defined context as a set of key/value pairs,// which will be sent as function invocation context together with// batched arguments in the requests to the remote service. The total// number of bytes of keys and values must be less than 8KB.UserDefinedContext map[string]string}

RemoteFunctionOptions contains information for a remote user-defined function.

typeReservationEditionadded inv1.68.0

type ReservationEditionstring

ReservationEdition is used to specify the name of edition corresponding to the reservation.

var (// ReservationEditionUnspecified is the default value, which will be treated as ReservationEditionEnterpriseReservationEditionUnspecifiedReservationEdition = "RESERVATION_EDITION_UNSPECIFIED"// ReservationEditionStandard represents the Standard edition.ReservationEditionStandardReservationEdition = "STANDARD"// ReservationEditionEnterprise represents the Enterprise edition.ReservationEditionEnterpriseReservationEdition = "ENTERPRISE"// ReservationEditionEnterprisePlus represents the Enterprise Plus edition.ReservationEditionEnterprisePlusReservationEdition = "ENTERPRISE_PLUS")

typeReservationUsageadded inv1.15.0

type ReservationUsage struct {// SlotMillis reports the slot milliseconds utilized within in the given reservation.SlotMillisint64// Name indicates the utilized reservation name, or "unreserved" for ondemand usage.Namestring}

ReservationUsage contains information about a job's usage of a single reservation.

typeRoundingModeadded inv1.62.0

type RoundingModestring

RoundingMode represents the rounding mode to be used when storingvalues of NUMERIC and BIGNUMERIC type.

const (// RoundHalfAwayFromZero rounds half values away from zero when applying// precision and scale upon writing of NUMERIC and BIGNUMERIC values.// For Scale: 0 1.1, 1.2, 1.3, 1.4 => 1 1.5, 1.6, 1.7, 1.8, 1.9 => 2RoundHalfAwayFromZeroRoundingMode = "ROUND_HALF_AWAY_FROM_ZERO"// RoundHalfEven rounds half values to the nearest even value when applying// precision and scale upon writing of NUMERIC and BIGNUMERIC values.// For Scale: 0 1.1, 1.2, 1.3, 1.4 => 1 1.5 => 2 1.6, 1.7, 1.8, 1.9 => 2 2.5 => 2RoundHalfEvenRoundingMode = "ROUND_HALF_EVEN")

typeRoutine

type Routine struct {ProjectIDstringDatasetIDstringRoutineIDstring// contains filtered or unexported fields}

Routine represents a reference to a BigQuery routine. There are multipletypes of routines including stored procedures and scalar user-defined functions (UDFs).For more information, see the BigQuery documentation athttps://cloud.google.com/bigquery/docs/

func (*Routine)Create

func (r *Routine) Create(ctxcontext.Context, rm *RoutineMetadata) (errerror)

Create creates a Routine in the BigQuery service.Pass in a RoutineMetadata to define the routine.

func (*Routine)Delete

func (r *Routine) Delete(ctxcontext.Context) (errerror)

Delete removes a Routine from a dataset.

func (*Routine)FullyQualifiedName

func (r *Routine) FullyQualifiedName()string

FullyQualifiedName returns an identifer for the routine in project.dataset.routine format.

func (*Routine)Identifieradded inv1.25.0

func (r *Routine) Identifier(fIdentifierFormat) (string,error)

Identifier returns the ID of the routine in the requested format.

For Standard SQL format, the identifier will be quoted if theProjectID contains dash (-) characters.

func (*Routine)Metadata

func (r *Routine) Metadata(ctxcontext.Context) (rm *RoutineMetadata, errerror)

Metadata fetches the metadata for a given Routine.

func (*Routine)Update

func (r *Routine) Update(ctxcontext.Context, upd *RoutineMetadataToUpdate, etagstring) (rm *RoutineMetadata, errerror)

Update modifies properties of a Routine using the API.

typeRoutineArgument

type RoutineArgument struct {// The name of this argument.  Can be absent for function return argument.Namestring// Kind indicates the kind of argument represented.// Possible values://   ARGUMENT_KIND_UNSPECIFIED//   FIXED_TYPE - The argument is a variable with fully specified//     type, which can be a struct or an array, but not a table.//   ANY_TYPE - The argument is any type, including struct or array,//     but not a table.Kindstring// Mode is optional, and indicates whether an argument is input or output.// Mode can only be set for procedures.//// Possible values://   MODE_UNSPECIFIED//   IN - The argument is input-only.//   OUT - The argument is output-only.//   INOUT - The argument is both an input and an output.Modestring// DataType provides typing information.  Unnecessary for ANY_TYPE Kind// arguments.DataType *StandardSQLDataType}

RoutineArgument represents an argument supplied to a routine such as a UDF orstored procedured.

typeRoutineDeterminismadded inv1.15.0

type RoutineDeterminismstring

RoutineDeterminism specifies the level of determinism that javascript User Defined Functionsexhibit.

const (// Deterministic indicates that two calls with the same input to a UDF yield the same output.DeterministicRoutineDeterminism = "DETERMINISTIC"// NotDeterministic indicates that the output of the UDF is not guaranteed to yield the same// output each time for a given set of inputs.NotDeterministicRoutineDeterminism = "NOT_DETERMINISTIC")

typeRoutineIterator

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

A RoutineIterator is an iterator over Routines.

func (*RoutineIterator)Next

func (it *RoutineIterator) Next() (*Routine,error)

Next returns the next result. Its second return value is Done if there areno more results. Once Next returns Done, all subsequent calls will returnDone.

func (*RoutineIterator)PageInfo

func (it *RoutineIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

typeRoutineMetadata

type RoutineMetadata struct {ETagstring// Type indicates the type of routine, such as SCALAR_FUNCTION, PROCEDURE,// or TABLE_VALUED_FUNCTION.TypestringCreationTimetime.TimeDescriptionstring// DeterminismLevel is only applicable to Javascript UDFs.DeterminismLevelRoutineDeterminismLastModifiedTimetime.Time// Language of the routine, such as SQL or JAVASCRIPT.Languagestring// The list of arguments for the the routine.Arguments []*RoutineArgument// Information for a remote user-defined function.RemoteFunctionOptions *RemoteFunctionOptionsReturnType *StandardSQLDataType// Set only if the routine type is TABLE_VALUED_FUNCTION.ReturnTableType *StandardSQLTableType// For javascript routines, this indicates the paths for imported libraries.ImportedLibraries []string// Body contains the routine's body.// For functions, Body is the expression in the AS clause.//// For SQL functions, it is the substring inside the parentheses of a CREATE// FUNCTION statement.//// For JAVASCRIPT function, it is the evaluated string in the AS clause of// a CREATE FUNCTION statement.Bodystring// For data governance use cases.  If set to "DATA_MASKING", the function// is validated and made available as a masking function. For more information,// see:https://cloud.google.com/bigquery/docs/user-defined-functions#custom-maskDataGovernanceTypestring}

RoutineMetadata represents details of a given BigQuery Routine.

typeRoutineMetadataToUpdate

type RoutineMetadataToUpdate struct {Arguments          []*RoutineArgumentDescriptionoptional.StringDeterminismLeveloptional.StringTypeoptional.StringLanguageoptional.StringBodyoptional.StringImportedLibraries  []stringReturnType         *StandardSQLDataTypeReturnTableType    *StandardSQLTableTypeDataGovernanceTypeoptional.String}

RoutineMetadataToUpdate governs updating a routine.

typeRowInsertionError

type RowInsertionError struct {InsertIDstring// The InsertID associated with the affected row.RowIndexint// The 0-based index of the affected row in the batch of rows being inserted.ErrorsMultiError}

RowInsertionError contains all errors that occurred when attempting to insert a row.

func (*RowInsertionError)Error

func (e *RowInsertionError) Error()string

typeRowIterator

type RowIterator struct {// StartIndex can be set before the first call to Next. If PageInfo().Token// is also set, StartIndex is ignored. If Storage API is enabled,// StartIndex is also ignored because is not supported. IsAccelerated()// method can be called to check if Storage API is enabled for the RowIterator.StartIndexuint64// The schema of the table.// In some scenarios it will only be available after the first// call to Next(), like when a call to Query.Read uses// the jobs.query API for an optimized query path.SchemaSchema// The total number of rows in the result.// In some scenarios it will only be available after the first// call to Next(), like when a call to Query.Read uses// the jobs.query API for an optimized query path.// May be zero just after rows were inserted.TotalRowsuint64// contains filtered or unexported fields}

A RowIterator provides access to the result of a BigQuery lookup.

func (*RowIterator)ArrowIteratoradded inv1.57.0

func (it *RowIterator) ArrowIterator() (ArrowIterator,error)

ArrowIterator gives access to the raw Arrow Record Batch stream to be consumed directly.Experimental: this interface is experimental and may be modified or removed in future versions,regardless of any other documented package stability guarantees.Don't try to mix RowIterator.Next and ArrowIterator.Next calls.

func (*RowIterator)IsAcceleratedadded inv1.46.0

func (it *RowIterator) IsAccelerated()bool

IsAccelerated check if the current RowIterator isbeing accelerated by Storage API.

func (*RowIterator)Next

func (it *RowIterator) Next(dst interface{})error

Next loads the next row into dst. Its return value is iterator.Done if thereare no more results. Once Next returns iterator.Done, all subsequent callswill return iterator.Done.

dst may implement ValueLoader, or may be a *[]Value, *map[string]Value, or struct pointer.

If dst is a *[]Value, it will be set to new []Value whose i'th elementwill be populated with the i'th column of the row.

If dst is a *map[string]Value, a new map will be created if dst is nil. Thenfor each schema column name, the map key of that name will be set to the column'svalue. STRUCT types (RECORD types or nested schemas) become nested maps.

If dst is pointer to a struct, each column in the schema will be matchedwith an exported field of the struct that has the same name, ignoring case.Unmatched schema columns and struct fields will be ignored.

Each BigQuery column type corresponds to one or more Go types; a matching structfield must be of the correct type. The correspondences are:

STRING      stringBOOL        boolINTEGER     int, int8, int16, int32, int64, uint8, uint16, uint32FLOAT       float32, float64BYTES       []byteTIMESTAMP   time.TimeDATE        civil.DateTIME        civil.TimeDATETIME    civil.DateTimeNUMERIC     *big.RatBIGNUMERIC  *big.Rat

The big.Rat type supports numbers of arbitrary size and precision.Seehttps://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#numeric-typefor more on NUMERIC.

A repeated field corresponds to a slice or array of the element type. BigQuery translatesNULL arrays into an empty array, so we follow that behavior.Seehttps://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#array_nullsfor more about NULL and empty arrays.

A STRUCT type (RECORD or nested schema) corresponds to a nested struct or struct pointer.All calls to Next on the same iterator must use the same struct type.

It is an error to attempt to read a BigQuery NULL value into a struct field,unless the field is of type []byte or is one of the special Null types: NullInt64,NullFloat64, NullBool, NullString, NullTimestamp, NullDate, NullTime orNullDateTime. You can also use a *[]Value or *map[string]Value to read from atable with NULLs.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery""google.golang.org/api/iterator")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}q := client.Query("select name, num from t1")it, err := q.Read(ctx)if err != nil {// TODO: Handle error.}for {var row []bigquery.Valueerr := it.Next(&row)if err == iterator.Done {break}if err != nil {// TODO: Handle error.}fmt.Println(row)}}

Example (Struct)
package mainimport ("context""fmt""cloud.google.com/go/bigquery""google.golang.org/api/iterator")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}type score struct {Name stringNum  int}q := client.Query("select name, num from t1")it, err := q.Read(ctx)if err != nil {// TODO: Handle error.}for {var s scoreerr := it.Next(&s)if err == iterator.Done {break}if err != nil {// TODO: Handle error.}fmt.Println(s)}}

func (*RowIterator)PageInfo

func (it *RowIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.Currently pagination is not supported when the Storage API is enabled. IsAccelerated()method can be called to check if Storage API is enabled for the RowIterator.

func (*RowIterator)QueryIDadded inv1.58.0

func (ri *RowIterator) QueryID()string

QueryID returns a query ID if available, or an empty string.

func (*RowIterator)SourceJobadded inv1.23.0

func (ri *RowIterator) SourceJob() *Job

SourceJob returns an instance of a Job if the RowIterator is backed by a query,or a nil.

typeSchema

type Schema []*FieldSchema

Schema describes the fields in a table or query result.

funcInferSchema

func InferSchema(st interface{}) (Schema,error)

InferSchema tries to derive a BigQuery schema from the supplied struct value.Each exported struct field is mapped to a field in the schema.

The following BigQuery types are inferred from the corresponding Go types.(This is the same mapping as that used for RowIterator.Next.) Fields inferredfrom these types are marked required (non-nullable).

STRING      stringBOOL        boolINTEGER     int, int8, int16, int32, int64, uint8, uint16, uint32FLOAT       float32, float64BYTES       []byteTIMESTAMP   time.TimeDATE        civil.DateTIME        civil.TimeDATETIME    civil.DateTimeNUMERIC     *big.RatJSON        map[string]interface{}

The big.Rat type supports numbers of arbitrary size and precision. Valueswill be rounded to 9 digits after the decimal point before being transmittedto BigQuery. Seehttps://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#numeric-typefor more on NUMERIC.

A Go slice or array type is inferred to be a BigQuery repeated field of theelement type. The element type must be one of the above listed types.

Due to lack of unique native Go type for GEOGRAPHY, there is no schemainference to GEOGRAPHY at this time.

This package also provides some value types for expressing the corresponding SQL types.

INTERVAL*IntervalValueRANGE *RangeValue

In the case of RANGE types, a RANGE represents a continuous set of values of a givenelement type (DATE, DATETIME, or TIMESTAMP). InferSchema does not attempt to determinethe element type, as it uses generic Value types to denote the start/end of the range.

Nullable fields are inferred from the NullXXX types, declared in this package:

STRING      NullStringBOOL        NullBoolINTEGER     NullInt64FLOAT       NullFloat64TIMESTAMP   NullTimestampDATE        NullDateTIME        NullTimeDATETIME    NullDateTimeGEOGRAPHY   NullGeography

For a nullable BYTES field, use the type []byte and tag the field "nullable" (see below).For a nullable NUMERIC field, use the type *big.Rat and tag the field "nullable".

A struct field that is of struct type is inferred to be a required field of typeRECORD with a schema inferred recursively. For backwards compatibility, a field oftype pointer to struct is also inferred to be required. To get a nullable RECORDfield, use the "nullable" tag (see below).

InferSchema returns an error if any of the examined fields is of type uint,uint64, uintptr, map, interface, complex64, complex128, func, or chan. Futureversions may handle these cases without error.

Recursively defined structs are also disallowed.

Struct fields may be tagged in a way similar to the encoding/json package.A tag of the form

bigquery:"name"

uses "name" instead of the struct field name as the BigQuery field name.A tag of the form

bigquery:"-"

omits the field from the inferred schema.The "nullable" option marks the field as nullable (not required). It is onlyneeded for []byte, *big.Rat and pointer-to-struct fields, and cannot appear on otherfields. In this example, the Go name of the field is retained:

bigquery:",nullable"
Example
package mainimport ("fmt""cloud.google.com/go/bigquery")func main() {type Item struct {Name  stringSize  float64Count int}schema, err := bigquery.InferSchema(Item{})if err != nil {fmt.Println(err)// TODO: Handle error.}for _, fs := range schema {fmt.Println(fs.Name, fs.Type)}}
Output:Name STRINGSize FLOATCount INTEGER

Example (Tags)
package mainimport ("fmt""cloud.google.com/go/bigquery")func main() {type Item struct {Name     stringSize     float64Count    int    `bigquery:"number"`Secret   []byte `bigquery:"-"`Optional bigquery.NullBoolOptBytes []byte `bigquery:",nullable"`}schema, err := bigquery.InferSchema(Item{})if err != nil {fmt.Println(err)// TODO: Handle error.}for _, fs := range schema {fmt.Println(fs.Name, fs.Type, fs.Required)}}
Output:Name STRING trueSize FLOAT truenumber INTEGER trueOptional BOOLEAN falseOptBytes BYTES false

funcSchemaFromJSON

func SchemaFromJSON(schemaJSON []byte) (Schema,error)

SchemaFromJSON takes a native JSON BigQuery table schema definition and converts it toa populated Schema. The native API definition is used by tools such as the BQ CLI andhttps://github.com/GoogleCloudPlatform/protoc-gen-bq-schema.

The expected format is a JSON array of TableFieldSchema objects from the underlying API:https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#TableFieldSchema

func (Schema)Relaxadded inv1.1.0

func (sSchema) Relax()Schema

Relax returns a version of the schema where no fields are markedas Required.

func (Schema)ToJSONFieldsadded inv1.31.0

func (sSchema) ToJSONFields() ([]byte,error)

ToJSONFields exposes the schema as a JSON array ofTableFieldSchema objects:https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#TableFieldSchema

Generally this isn't needed for direct usage of this library, but isprovided for use cases where you're interacting with other toolsthat consume the underlying API representation directly such as theBQ CLI tool.

typeScriptStackFrameadded inv1.2.0

type ScriptStackFrame struct {StartLineint64StartColumnint64EndLineint64EndColumnint64// Name of the active procedure.  Empty if in a top-level script.ProcedureIDstring// Text of the current statement/expression.Textstring}

ScriptStackFrame represents the location of the statement/expression being evaluated.

Line and column numbers are defined as follows:

  • Line and column numbers start with one. That is, line 1 column 1 denotesthe start of the script.
  • When inside a stored procedure, all line/column numbers are relativeto the procedure body, not the script in which the procedure was defined.
  • Start/end positions exclude leading/trailing comments and whitespace.The end position always ends with a ";", when present.
  • Multi-byte Unicode characters are treated as just one column.
  • If the original script (or procedure definition) contains TAB characters,a tab "snaps" the indentation forward to the nearest multiple of 8characters, plus 1. For example, a TAB on column 1, 2, 3, 4, 5, 6 , or 8will advance the next character to column 9. A TAB on column 9, 10, 11,12, 13, 14, 15, or 16 will advance the next character to column 17.

typeScriptStatisticsadded inv1.2.0

type ScriptStatistics struct {EvaluationKindstringStackFrames    []*ScriptStackFrame}

ScriptStatistics report information about script-based query jobs.

typeSessionInfoadded inv1.23.0

type SessionInfo struct {SessionIDstring}

SessionInfo contains information about a session associated with a job.

typeSkewSourceadded inv1.68.0

type SkewSource struct {// Stage id of the skew source stage.StageIDint64}

SkewSource contains details about source stages which produce skewed data.

typeSnapshotDefinitionadded inv1.19.0

type SnapshotDefinition struct {// BaseTableReference describes the ID of the table that this snapshot// came from.BaseTableReference *Table// SnapshotTime indicates when the base table was snapshot.SnapshotTimetime.Time}

SnapshotDefinition provides metadata related to the origin of a snapshot.

typeSourceColumnMatchadded inv1.70.0

type SourceColumnMatchstring

SourceColumnMatch indicates the strategy used to match loaded columns to the schema.

const (// SourceColumnMatchUnspecified keeps the default behavior. Which is to use// sensible defaults based on how the schema is provided. If autodetect// is used, then columns are matched by name. Otherwise, columns are matched// by position. This is done to keep the behavior backward-compatible.SourceColumnMatchUnspecifiedSourceColumnMatch = "SOURCE_COLUMN_MATCH_UNSPECIFIED"// SourceColumnMatchPosition matches by position. This assumes that the columns are ordered the same// way as the schema.SourceColumnMatchPositionSourceColumnMatch = "POSITION"// SourceColumnMatchName matches by name. This reads the header row as column names and reorders// columns to match the field names in the schema.SourceColumnMatchNameSourceColumnMatch = "NAME")

typeStagePerformanceChangeInsightadded inv1.68.0

type StagePerformanceChangeInsight struct {//  The stage id that the insight mapped to.StageIDint64InputDataChange *InputDataChange}

StagePerformanceChangeInsight contains performance insights compared to the previous executions for a specific stage.

typeStagePerformanceStandaloneInsightadded inv1.68.0

type StagePerformanceStandaloneInsight struct {// The stage id that the insight mapped to.StageIDint64// If present, the stage had the following reasons for being disqualified from BI Engine execution.BIEngineReasons []*BIEngineReason// High cardinality joins in the stage.HighCardinalityJoins []*HighCardinalityJoin// True if the stage has a slot contention issue.SlotContentionbool// True if the stage has insufficient shuffle quota.InsufficientShuffleQuotabool// Partition skew in the stage.PartitionSkew *PartitionSkew}

StagePerformanceStandaloneInsight describes standalone performance insights for a specific stage.

typeStandardSQLDataType

type StandardSQLDataType struct {// ArrayElementType indicates the type of an array's elements, when the// TypeKind is ARRAY.ArrayElementType *StandardSQLDataType// The type of the range's elements, if TypeKind is RANGE.RangeElementType *StandardSQLDataType// StructType indicates the struct definition (fields), when the// TypeKind is STRUCT.StructType *StandardSQLStructType// The top-level type of this type definition.// Can be any standard SQL data type.  For more information about BigQuery// data types, see//https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types//// Additional information is available in the REST documentation://https://cloud.google.com/bigquery/docs/reference/rest/v2/StandardSqlDataTypeTypeKindstring}

StandardSQLDataType conveys type information using the Standard SQL typesystem.

typeStandardSQLField

type StandardSQLField struct {// The name of this field.  Can be absent for struct fields.Namestring// Data type for the field.Type *StandardSQLDataType}

StandardSQLField represents a field using the Standard SQL data type system.

typeStandardSQLStructType

type StandardSQLStructType struct {Fields []*StandardSQLField}

StandardSQLStructType represents a structure type, which is a list of Standard SQL fields.For more information, see:https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct-type

typeStandardSQLTableTypeadded inv1.19.0

type StandardSQLTableType struct {// The columns of the table.Columns []*StandardSQLField}

StandardSQLTableType models a table-like resource, which has a set of columns.

typeState

type Stateint

State is one of a sequence of states that a Job progresses through as it is processed.

const (// StateUnspecified is the default JobIterator state.StateUnspecifiedState =iota// Pending is a state that describes that the job is pending.Pending// Running is a state that describes that the job is running.Running// Done is a state that describes that the job is done.Done)

typeStatistics

type Statistics interface {// contains filtered or unexported methods}

Statistics is one of ExtractStatistics, LoadStatistics or QueryStatistics.

typeStreamingBuffer

type StreamingBuffer struct {// A lower-bound estimate of the number of bytes currently in the streaming// buffer.EstimatedBytesuint64// A lower-bound estimate of the number of rows currently in the streaming// buffer.EstimatedRowsuint64// The time of the oldest entry in the streaming buffer.OldestEntryTimetime.Time}

StreamingBuffer holds information about the streaming buffer.

typeStructSaver

type StructSaver struct {// Schema determines what fields of the struct are uploaded. It should// match the table's schema.// Schema is optional for StructSavers that are passed to Uploader.Put.SchemaSchema// InsertID governs the best-effort deduplication feature of// BigQuery streaming inserts.//// If the InsertID is empty, a random InsertID will be generated by// this library to facilitate deduplication.//// If the InsertID is set to the sentinel value NoDedupeID, an InsertID// is not sent.//// For all other non-empty values, BigQuery will use the provided// value for best-effort deduplication.InsertIDstring// Struct should be a struct or a pointer to a struct.Struct interface{}}

StructSaver implements ValueSaver for a struct.The struct is converted to a map of values by using the values of structfields corresponding to schema fields. Additional and missingfields are ignored, as are nested struct pointers that are nil.

func (*StructSaver)Save

func (ss *StructSaver) Save() (row map[string]Value, insertIDstring, errerror)

Save implements ValueSaver.

typeTable

type Table struct {// ProjectID, DatasetID and TableID may be omitted if the Table is the destination for a query.// In this case the result will be stored in an ephemeral table.ProjectIDstringDatasetIDstring// TableID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_).// The maximum length is 1,024 characters.TableIDstring// contains filtered or unexported fields}

A Table is a reference to a BigQuery table.

func (*Table)CopierFrom

func (t *Table) CopierFrom(srcs ...*Table) *Copier

CopierFrom returns a Copier which can be used to copy data into aBigQuery table from one or more BigQuery tables.The returned Copier may optionally be further configured before its Run method is called.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ds := client.Dataset("my_dataset")c := ds.Table("combined").CopierFrom(ds.Table("t1"), ds.Table("t2"))c.WriteDisposition = bigquery.WriteTruncate// TODO: set other options on the Copier.job, err := c.Run(ctx)if err != nil {// TODO: Handle error.}status, err := job.Wait(ctx)if err != nil {// TODO: Handle error.}if status.Err() != nil {// TODO: Handle error.}}

func (*Table)Create

func (t *Table) Create(ctxcontext.Context, tm *TableMetadata) (errerror)

Create creates a table in the BigQuery service.Pass in a TableMetadata value to configure the table.If tm.View.Query is non-empty, the created table will be of type VIEW.If no ExpirationTime is specified, the table will never expire.After table creation, a view can be modified only if its table was initially createdwith a view.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}t := client.Dataset("my_dataset").Table("new-table")if err := t.Create(ctx, nil); err != nil {// TODO: Handle error.}}

Example (EncryptionKey)

This example demonstrates how to create a table witha customer-managed encryption key.

package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()// Infer table schema from a Go type.schema, err := bigquery.InferSchema(Item{})if err != nil {// TODO: Handle error.}client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}t := client.Dataset("my_dataset").Table("new-table")// TODO: Replace this key with a key you have created in Cloud KMS.keyName := "projects/P/locations/L/keyRings/R/cryptoKeys/K"if err := t.Create(ctx,&bigquery.TableMetadata{Name:             "My New Table",Schema:           schema,EncryptionConfig: &bigquery.EncryptionConfig{KMSKeyName: keyName},}); err != nil {// TODO: Handle error.}}type Item struct {Name  stringSize  float64Count int}// Save implements the ValueSaver interface.func (i *Item) Save() (map[string]bigquery.Value, string, error) {return map[string]bigquery.Value{"Name":  i.Name,"Size":  i.Size,"Count": i.Count,}, "", nil}

Example (Initialize)

Initialize a new table by passing TableMetadata to Table.Create.

package mainimport ("context""time""cloud.google.com/go/bigquery")func main() {ctx := context.Background()// Infer table schema from a Go type.schema, err := bigquery.InferSchema(Item{})if err != nil {// TODO: Handle error.}client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}t := client.Dataset("my_dataset").Table("new-table")if err := t.Create(ctx,&bigquery.TableMetadata{Name:           "My New Table",Schema:         schema,ExpirationTime: time.Now().Add(24 * time.Hour),}); err != nil {// TODO: Handle error.}}type Item struct {Name  stringSize  float64Count int}// Save implements the ValueSaver interface.func (i *Item) Save() (map[string]bigquery.Value, string, error) {return map[string]bigquery.Value{"Name":  i.Name,"Size":  i.Size,"Count": i.Count,}, "", nil}

func (*Table)Delete

func (t *Table) Delete(ctxcontext.Context) (errerror)

Delete deletes the table.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}if err := client.Dataset("my_dataset").Table("my_table").Delete(ctx); err != nil {// TODO: Handle error.}}

func (*Table)ExtractorTo

func (t *Table) ExtractorTo(dst *GCSReference) *Extractor

ExtractorTo returns an Extractor which can be used to extract data from aBigQuery table into Google Cloud Storage.The returned Extractor may optionally be further configured before its Run method is called.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}gcsRef := bigquery.NewGCSReference("gs://my-bucket/my-object")gcsRef.FieldDelimiter = ":"// TODO: set other options on the GCSReference.ds := client.Dataset("my_dataset")extractor := ds.Table("my_table").ExtractorTo(gcsRef)extractor.DisableHeader = true// TODO: set other options on the Extractor.job, err := extractor.Run(ctx)if err != nil {// TODO: Handle error.}status, err := job.Wait(ctx)if err != nil {// TODO: Handle error.}if status.Err() != nil {// TODO: Handle error.}}

func (*Table)FullyQualifiedName

func (t *Table) FullyQualifiedName()string

FullyQualifiedName returns the ID of the table in projectID:datasetID.tableID format.

func (*Table)IAMadded inv1.9.0

func (t *Table) IAM() *iam.Handle

IAM provides access to an iam.Handle that allows access to IAM functionality forthe given BigQuery table. For more information, seehttps://pkg.go.dev/cloud.google.com/go/iam

func (*Table)Identifieradded inv1.25.0

func (t *Table) Identifier(fIdentifierFormat) (string,error)

Identifier returns the ID of the table in the requested format.

func (*Table)Inserter

func (t *Table) Inserter() *Inserter

Inserter returns an Inserter that can be used to append rows to t.The returned Inserter may optionally be further configured before its Put method is called.

To stream rows into a date-partitioned table at a particular date, add the$yyyymmdd suffix to the table name when constructing the Table.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ins := client.Dataset("my_dataset").Table("my_table").Inserter()_ = ins // TODO: Use ins.}

Example (Options)
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}ins := client.Dataset("my_dataset").Table("my_table").Inserter()ins.SkipInvalidRows = trueins.IgnoreUnknownValues = true_ = ins // TODO: Use ins.}

func (*Table)LoaderFrom

func (t *Table) LoaderFrom(srcLoadSource) *Loader

LoaderFrom returns a Loader which can be used to load data into a BigQuery table.The returned Loader may optionally be further configured before its Run method is called.See GCSReference and ReaderSource for additional configuration options thataffect loading.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}gcsRef := bigquery.NewGCSReference("gs://my-bucket/my-object")gcsRef.AllowJaggedRows = truegcsRef.MaxBadRecords = 5gcsRef.Schema = schema// TODO: set other options on the GCSReference.ds := client.Dataset("my_dataset")loader := ds.Table("my_table").LoaderFrom(gcsRef)loader.CreateDisposition = bigquery.CreateNever// TODO: set other options on the Loader.job, err := loader.Run(ctx)if err != nil {// TODO: Handle error.}status, err := job.Wait(ctx)if err != nil {// TODO: Handle error.}if status.Err() != nil {// TODO: Handle error.}}var schema bigquery.Schema

Example (Reader)
package mainimport ("context""os""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}f, err := os.Open("data.csv")if err != nil {// TODO: Handle error.}rs := bigquery.NewReaderSource(f)rs.AllowJaggedRows = truers.MaxBadRecords = 5rs.Schema = schema// TODO: set other options on the GCSReference.ds := client.Dataset("my_dataset")loader := ds.Table("my_table").LoaderFrom(rs)loader.CreateDisposition = bigquery.CreateNever// TODO: set other options on the Loader.job, err := loader.Run(ctx)if err != nil {// TODO: Handle error.}status, err := job.Wait(ctx)if err != nil {// TODO: Handle error.}if status.Err() != nil {// TODO: Handle error.}}var schema bigquery.Schema

func (*Table)Metadata

func (t *Table) Metadata(ctxcontext.Context, opts ...TableMetadataOption) (md *TableMetadata, errerror)

Metadata fetches the metadata for the table.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}md, err := client.Dataset("my_dataset").Table("my_table").Metadata(ctx)if err != nil {// TODO: Handle error.}fmt.Println(md)}

func (*Table)Read

func (t *Table) Read(ctxcontext.Context) *RowIterator

Read fetches the contents of the table.

Example
package mainimport ("context""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}it := client.Dataset("my_dataset").Table("my_table").Read(ctx)_ = it // TODO: iterate using Next or iterator.Pager.}

func (*Table)Update

func (t *Table) Update(ctxcontext.Context, tmTableMetadataToUpdate, etagstring, opts ...TableUpdateOption) (md *TableMetadata, errerror)

Update modifies specific Table metadata fields.

Example (BlindWrite)

To perform a blind write, ignoring the existing state (and possibly overwritingother updates), pass the empty string as the etag.

package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}t := client.Dataset("my_dataset").Table("my_table")tm, err := t.Update(ctx, bigquery.TableMetadataToUpdate{Description: "my favorite table",}, "")if err != nil {// TODO: Handle error.}fmt.Println(tm)}

Example (ReadModifyWrite)

This example illustrates how to perform a read-modify-write sequence on tablemetadata. Passing the metadata's ETag to the Update call ensures that the callwill fail if the metadata was changed since the read.

package mainimport ("context""fmt""cloud.google.com/go/bigquery")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}t := client.Dataset("my_dataset").Table("my_table")md, err := t.Metadata(ctx)if err != nil {// TODO: Handle error.}md2, err := t.Update(ctx,bigquery.TableMetadataToUpdate{Name: "new " + md.Name},md.ETag)if err != nil {// TODO: Handle error.}fmt.Println(md2)}

func (*Table)Uploader

func (t *Table) Uploader() *Inserter

Uploader calls Inserter.Deprecated: use Table.Inserter instead.

typeTableConstraintsadded inv1.52.0

type TableConstraints struct {// PrimaryKey constraint on a table's columns.// Present only if the table has a primary key.// The primary key is not enforced.PrimaryKey *PrimaryKey// ForeignKeys represent a list of foreign keys constraints.// Foreign keys are not enforced.ForeignKeys []*ForeignKey}

TableConstraints defines the primary key and foreign key of a table.

typeTableCopyOperationTypeadded inv1.19.0

type TableCopyOperationTypestring

TableCopyOperationType is used to indicate the type of operation performed by a BigQuerycopy job.

var (// CopyOperation indicates normal table to table copying.CopyOperationTableCopyOperationType = "COPY"// SnapshotOperation indicates creating a snapshot from a regular table, which// operates as an immutable copy.SnapshotOperationTableCopyOperationType = "SNAPSHOT"// RestoreOperation indicates creating/restoring a table from a snapshot.RestoreOperationTableCopyOperationType = "RESTORE"// CloneOperation indicates creating a table clone, which creates a writeable// copy of a base table that is billed based on difference from the base table.CloneOperationTableCopyOperationType = "CLONE")

typeTableCreateDisposition

type TableCreateDispositionstring

TableCreateDisposition specifies the circumstances under which destination table will be created.Default is CreateIfNeeded.

const (// CreateIfNeeded will create the table if it does not already exist.// Tables are created atomically on successful completion of a job.CreateIfNeededTableCreateDisposition = "CREATE_IF_NEEDED"// CreateNever ensures the table must already exist and will not be// automatically created.CreateNeverTableCreateDisposition = "CREATE_NEVER")

typeTableIterator

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

A TableIterator is an iterator over Tables.

func (*TableIterator)Next

func (it *TableIterator) Next() (*Table,error)

Next returns the next result. Its second return value is Done if there areno more results. Once Next returns Done, all subsequent calls will returnDone.

Example
package mainimport ("context""fmt""cloud.google.com/go/bigquery""google.golang.org/api/iterator")func main() {ctx := context.Background()client, err := bigquery.NewClient(ctx, "project-id")if err != nil {// TODO: Handle error.}it := client.Dataset("my_dataset").Tables(ctx)for {t, err := it.Next()if err == iterator.Done {break}if err != nil {// TODO: Handle error.}fmt.Println(t)}}

func (*TableIterator)PageInfo

func (it *TableIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

typeTableMetadata

type TableMetadata struct {// The user-friendly name for the table.Namestring// Output-only location of the table, based on the encapsulating dataset.Locationstring// The user-friendly description of the table.Descriptionstring// The table schema. If provided on create, ViewQuery must be empty.SchemaSchema// If non-nil, this table is a materialized view.MaterializedView *MaterializedViewDefinition// The query to use for a logical view. If provided on create, Schema must be nil.ViewQuerystring// Use Legacy SQL for the view query.// At most one of UseLegacySQL and UseStandardSQL can be true.UseLegacySQLbool// Use Standard SQL for the view query. The default.// At most one of UseLegacySQL and UseStandardSQL can be true.// Deprecated: use UseLegacySQL.UseStandardSQLbool// If non-nil, the table is partitioned by time. Only one of// time partitioning or range partitioning can be specified.TimePartitioning *TimePartitioning// If non-nil, the table is partitioned by integer range.  Only one of// time partitioning or range partitioning can be specified.RangePartitioning *RangePartitioning// If set to true, queries that reference this table must specify a// partition filter (e.g. a WHERE clause) that can be used to eliminate// partitions. Used to prevent unintentional full data scans on large// partitioned tables.RequirePartitionFilterbool// Clustering specifies the data clustering configuration for the table.Clustering *Clustering// The time when this table expires. If set, this table will expire at the// specified time. Expired tables will be deleted and their storage// reclaimed. The zero value is ignored.ExpirationTimetime.Time// User-provided labels.Labels map[string]string// Information about a table stored outside of BigQuery.ExternalDataConfig *ExternalDataConfig// Custom encryption configuration (e.g., Cloud KMS keys).EncryptionConfig *EncryptionConfigFullIDstring// An opaque ID uniquely identifying the table.TypeTableTypeCreationTimetime.TimeLastModifiedTimetime.Time// The size of the table in bytes.// This does not include data that is being buffered during a streaming insert.NumBytesint64// The number of bytes in the table considered "long-term storage" for reduced// billing purposes.  Seehttps://cloud.google.com/bigquery/pricing#long-term-storage// for more information.NumLongTermBytesint64// The number of rows of data in this table.// This does not include data that is being buffered during a streaming insert.NumRowsuint64// SnapshotDefinition contains additional information about the provenance of a// given snapshot table.SnapshotDefinition *SnapshotDefinition// CloneDefinition contains additional information about the provenance of a// given cloned table.CloneDefinition *CloneDefinition// Contains information regarding this table's streaming buffer, if one is// present. This field will be nil if the table is not being streamed to or if// there is no data in the streaming buffer.StreamingBuffer *StreamingBuffer// ETag is the ETag obtained when reading metadata. Pass it to Table.Update to// ensure that the metadata hasn't changed since it was read.ETagstring// Defines the default collation specification of new STRING fields// in the table. During table creation or update, if a STRING field is added// to this table without explicit collation specified, then the table inherits// the table default collation. A change to this field affects only fields// added afterwards, and does not alter the existing fields.// The following values are supported://   - 'und:ci': undetermined locale, case insensitive.//   - ”: empty string. Default to case-sensitive behavior.// More information:https://cloud.google.com/bigquery/docs/reference/standard-sql/collation-conceptsDefaultCollationstring// TableConstraints contains table primary and foreign keys constraints.// Present only if the table has primary or foreign keys.TableConstraints *TableConstraints// MaxStaleness staleness of data that could be// returned when the table (or stale MV) is queried.MaxStaleness *IntervalValue// The tags associated with this table. Tag// keys are globally unique. See additional information on tags// (https://cloud.google.com/iam/docs/tags-access-control#definitions).// An object containing a list of "key": value pairs. The key is the// namespaced friendly name of the tag key, e.g. "12345/environment"// where 12345 is parent id. The value is the friendly short name of the// tag value, e.g. "production".ResourceTags map[string]string// Specifies the configuration of a BigQuery table for Apache Iceberg (formerly BigLake Managed Table).BigLakeConfiguration *BigLakeConfiguration}

TableMetadata contains information about a BigQuery table.

typeTableMetadataOptionadded inv1.33.0

type TableMetadataOption func(*tableGetCall)

TableMetadataOption allow requests to alter requests for table metadata.

funcWithMetadataViewadded inv1.33.0

func WithMetadataView(tmvTableMetadataView)TableMetadataOption

WithMetadataView is used to customize what details are returned when interrogating atable via the Metadata() call. Generally this is used to limit data returned for performancereasons (such as large tables that take time computing storage statistics).

typeTableMetadataToUpdate

type TableMetadataToUpdate struct {// The user-friendly description of this table.Descriptionoptional.String// The user-friendly name for this table.Nameoptional.String// The table's schema.// When updating a schema, you can add columns but not remove them.SchemaSchema// The table's clustering configuration.// For more information on how modifying clustering affects the table, see://https://cloud.google.com/bigquery/docs/creating-clustered-tables#modifying-cluster-specClustering *Clustering// The table's encryption configuration.EncryptionConfig *EncryptionConfig// The time when this table expires. To remove a table's expiration,// set ExpirationTime to NeverExpire. The zero value is ignored.ExpirationTimetime.Time// ExternalDataConfig controls the definition of a table defined against// an external source, such as one based on files in Google Cloud Storage.ExternalDataConfig *ExternalDataConfig// The query to use for a view.ViewQueryoptional.String// Use Legacy SQL for the view query.UseLegacySQLoptional.Bool// MaterializedView allows changes to the underlying materialized view// definition. When calling Update, ensure that all mutable fields of// MaterializedViewDefinition are populated.MaterializedView *MaterializedViewDefinition// TimePartitioning allows modification of certain aspects of partition// configuration such as partition expiration and whether partition// filtration is required at query time.  When calling Update, ensure// that all mutable fields of TimePartitioning are populated.TimePartitioning *TimePartitioning// RequirePartitionFilter governs whether the table enforces partition// elimination when referenced in a query.RequirePartitionFilteroptional.Bool// Defines the default collation specification of new STRING fields// in the table.DefaultCollationoptional.String// TableConstraints allows modification of table constraints// such as primary and foreign keys.TableConstraints *TableConstraints// MaxStaleness staleness of data that could be// returned when the table (or stale MV) is queried.MaxStaleness *IntervalValue// The tags associated with this table. Tag// keys are globally unique. See additional information on tags// (https://cloud.google.com/iam/docs/tags-access-control#definitions).// An object containing a list of "key": value pairs. The key is the// namespaced friendly name of the tag key, e.g. "12345/environment"// where 12345 is parent id. The value is the friendly short name of the// tag value, e.g. "production".ResourceTags map[string]string// Update the configuration of a BigQuery table for Apache Iceberg (formerly BigLake Managed Table).BigLakeConfiguration *BigLakeConfiguration// contains filtered or unexported fields}

TableMetadataToUpdate is used when updating a table's metadata.Only non-nil fields will be updated.

func (*TableMetadataToUpdate)DeleteLabel

func (u *TableMetadataToUpdate) DeleteLabel(namestring)

DeleteLabel causes a label to be deleted on a call to Update.

func (*TableMetadataToUpdate)SetLabel

func (u *TableMetadataToUpdate) SetLabel(name, valuestring)

SetLabel causes a label to be added or modified on a call to Update.

typeTableMetadataViewadded inv1.33.0

type TableMetadataViewstring

TableMetadataView specifies which details about a table are desired.

const (// BasicMetadataView populates basic table information including schema partitioning,// but does not contain storage statistics like number or rows or bytes.  This is a more// efficient view to use for large tables or higher metadata query rates.BasicMetadataViewTableMetadataView = "BASIC"// FullMetadataView returns all table information, including storage statistics.  It currently// returns the same information as StorageStatsMetadataView, but may include additional information// in the future.FullMetadataViewTableMetadataView = "FULL"// StorageStatsMetadataView includes all information from the basic view, and includes storage statistics.  It currentlyStorageStatsMetadataViewTableMetadataView = "STORAGE_STATS")

typeTableType

type TableTypestring

TableType is the type of table.

const (// RegularTable is a regular table.RegularTableTableType = "TABLE"// ViewTable is a table type describing that the table is a logical view.// See more information athttps://cloud.google.com/bigquery/docs/views.ViewTableTableType = "VIEW"// ExternalTable is a table type describing that the table is an external// table (also known as a federated data source). See more information at//https://cloud.google.com/bigquery/external-data-sources.ExternalTableTableType = "EXTERNAL"// MaterializedView represents a managed storage table that's derived from// a base table.MaterializedViewTableType = "MATERIALIZED_VIEW"// Snapshot represents an immutable point in time snapshot of some other// table.SnapshotTableType = "SNAPSHOT")

typeTableUpdateOptionadded inv1.32.0

type TableUpdateOption func(*tablePatchCall)

TableUpdateOption allow requests to update table metadata.

funcWithAutoDetectSchemaadded inv1.32.0

func WithAutoDetectSchema(bbool)TableUpdateOption

WithAutoDetectSchema governs whether the schema autodetection occurs as part of the table update.This is relevant in cases like external tables where schema is detected from the source data.

typeTableWriteDisposition

type TableWriteDispositionstring

TableWriteDisposition specifies how existing data in a destination table is treated.Default is WriteAppend.

const (// WriteAppend will append to any existing data in the destination table.// Data is appended atomically on successful completion of a job.WriteAppendTableWriteDisposition = "WRITE_APPEND"// WriteTruncate overwrites the existing data in the destination table.// Data is overwritten atomically on successful completion of a job.WriteTruncateTableWriteDisposition = "WRITE_TRUNCATE"// WriteTruncateData overwrites the data, but keeps the constraints and// reuses the schema for an existing table.WriteTruncateDataTableWriteDisposition = "WRITE_TRUNCATE_DATA"// WriteEmpty fails writes if the destination table already contains data.WriteEmptyTableWriteDisposition = "WRITE_EMPTY")

typeTimePartitioning

type TimePartitioning struct {// Defines the partition interval type.  Supported values are "HOUR", "DAY", "MONTH", and "YEAR".// When the interval type is not specified, default behavior is DAY.TypeTimePartitioningType// The amount of time to keep the storage for a partition.// If the duration is empty (0), the data in the partitions do not expire.Expirationtime.Duration// If empty, the table is partitioned by pseudo column '_PARTITIONTIME'; if set, the// table is partitioned by this field. The field must be a top-level TIMESTAMP or// DATE field. Its mode must be NULLABLE or REQUIRED.Fieldstring// If set to true, queries that reference this table must specify a// partition filter (e.g. a WHERE clause) that can be used to eliminate// partitions. Used to prevent unintentional full data scans on large// partitioned tables.// DEPRECATED: use the top-level RequirePartitionFilter in TableMetadata.RequirePartitionFilterbool}

TimePartitioning describes the time-based date partitioning on a table.For more information see:https://cloud.google.com/bigquery/docs/creating-partitioned-tables.

typeTimePartitioningTypeadded inv1.8.0

type TimePartitioningTypestring

TimePartitioningType defines the interval used to partition managed data.

const (// DayPartitioningType uses a day-based interval for time partitioning.DayPartitioningTypeTimePartitioningType = "DAY"// HourPartitioningType uses an hour-based interval for time partitioning.HourPartitioningTypeTimePartitioningType = "HOUR"// MonthPartitioningType uses a month-based interval for time partitioning.MonthPartitioningTypeTimePartitioningType = "MONTH"// YearPartitioningType uses a year-based interval for time partitioning.YearPartitioningTypeTimePartitioningType = "YEAR")

typeTrainingRun

type TrainingRunbq.TrainingRun

TrainingRun represents information about a single training run for a BigQuery ML model.Experimental: This information may be modified or removed in future versions of this package.

typeTransactionInfoadded inv1.20.1

type TransactionInfo struct {// TransactionID is the system-generated identifier for the transaction.TransactionIDstring}

TransactionInfo contains information about a multi-statement transaction that may have associated with a job.

typeUploader

type Uploader =Inserter

Uploader is an obsolete name for Inserter.

typeValue

type Value interface{}

Value stores the contents of a single cell from a BigQuery result.

typeValueLoader

type ValueLoader interface {Load(v []Value, sSchema)error}

ValueLoader stores a slice of Values representing a result row from a Read operation.See RowIterator.Next for more information.

typeValueSaver

type ValueSaver interface {// Save returns a row to be inserted into a BigQuery table, represented// as a map from field name to Value.// The insertID governs the best-effort deduplication feature of// BigQuery streaming inserts.//// If the insertID is empty, a random insertID will be generated by// this library to facilitate deduplication.//// If the insertID is set to the sentinel value NoDedupeID, an insertID// is not sent.//// For all other non-empty values, BigQuery will use the provided// value for best-effort deduplication.Save() (row map[string]Value, insertIDstring, errerror)}

A ValueSaver returns a row of data to be inserted into a table.

typeValuesSaver

type ValuesSaver struct {SchemaSchema// InsertID governs the best-effort deduplication feature of// BigQuery streaming inserts.//// If the InsertID is empty, a random insertID will be generated by// this library to facilitate deduplication.//// If the InsertID is set to the sentinel value NoDedupeID, an insertID// is not sent.//// For all other non-empty values, BigQuery will use the provided// value for best-effort deduplication.InsertIDstringRow []Value}

ValuesSaver implements ValueSaver for a slice of Values.

func (*ValuesSaver)Save

func (vls *ValuesSaver) Save() (map[string]Value,string,error)

Save implements ValueSaver.

Source Files

View all Source files

Directories

PathSynopsis
analyticshub
apiv1
Package analyticshub is an auto-generated package for the Analytics Hub API.
Package analyticshub is an auto-generated package for the Analytics Hub API.
biglake
apiv1
Package biglake is an auto-generated package for the BigLake API.
Package biglake is an auto-generated package for the BigLake API.
apiv1alpha1
Package biglake is an auto-generated package for the BigLake API.
Package biglake is an auto-generated package for the BigLake API.
connection
apiv1
Package connection is an auto-generated package for the BigQuery Connection API.
Package connection is an auto-generated package for the BigQuery Connection API.
apiv1beta1
Package connection is an auto-generated package for the BigQuery Connection API.
Package connection is an auto-generated package for the BigQuery Connection API.
dataexchange
apiv1beta1
Package dataexchange is an auto-generated package for the Analytics Hub API.
Package dataexchange is an auto-generated package for the Analytics Hub API.
datapolicies
apiv1
Package datapolicies is an auto-generated package for the BigQuery Data Policy API.
Package datapolicies is an auto-generated package for the BigQuery Data Policy API.
apiv1beta1
Package datapolicies is an auto-generated package for the BigQuery Data Policy API.
Package datapolicies is an auto-generated package for the BigQuery Data Policy API.
apiv2
Package datapolicies is an auto-generated package for the BigQuery Data Policy API.
Package datapolicies is an auto-generated package for the BigQuery Data Policy API.
apiv2beta1
Package datapolicies is an auto-generated package for the BigQuery Data Policy API.
Package datapolicies is an auto-generated package for the BigQuery Data Policy API.
datatransfer
apiv1
Package datatransfer is an auto-generated package for the BigQuery Data Transfer API.
Package datatransfer is an auto-generated package for the BigQuery Data Transfer API.
Package internal is used to manage versioning of the released library.
Package internal is used to manage versioning of the released library.
migration
apiv2
Package migration is an auto-generated package for the BigQuery Migration API.
Package migration is an auto-generated package for the BigQuery Migration API.
apiv2alpha
Package migration is an auto-generated package for the BigQuery Migration API.
Package migration is an auto-generated package for the BigQuery Migration API.
reservation
apiv1
Package reservation is an auto-generated package for the BigQuery Reservation API.
Package reservation is an auto-generated package for the BigQuery Reservation API.
storage
apiv1
Package storage is an auto-generated package for the BigQuery Storage API.
Package storage is an auto-generated package for the BigQuery Storage API.
apiv1alpha
Package storage is an auto-generated package for the BigQuery Storage API.
Package storage is an auto-generated package for the BigQuery Storage API.
apiv1beta
Package storage is an auto-generated package for the BigQuery Storage API.
Package storage is an auto-generated package for the BigQuery Storage API.
apiv1beta1
Package storage is an auto-generated package for the BigQuery Storage API.
Package storage is an auto-generated package for the BigQuery Storage API.
apiv1beta2
Package storage is an auto-generated package for the BigQuery Storage API.
Package storage is an auto-generated package for the BigQuery Storage API.
managedwriter
Package managedwriter provides a thick client around the BigQuery storage API's BigQueryWriteClient.
Package managedwriter provides a thick client around the BigQuery storage API's BigQueryWriteClient.
managedwriter/adapt
Package adapt adds functionality related to converting bigquery representations like schema and data type representations.
Package adapt adds functionality related to converting bigquery representations like schema and data type representations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp