Help us shape the future of Go! Take the 2026 Go Developer Survey

bigquery

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package bigquery builds models on Google BigQuery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect struct{}

Dialect is the BigQuery half of building a model.

func (Dialect) Build

func (d Dialect) Build(m model.Model, st dialect.State) ([]string, error)

Build is every statement that turns the model into what its header says.

ONE STATEMENT WHEN THE KIND DOES NOT CHANGE. BigQuery has `CREATE OR REPLACE TABLE` as well as `CREATE OR REPLACE VIEW`, and its replacement may change the column list -- both of which Postgres lacks, which is why the Postgres dialect drops a table to rebuild it and names a limit about view columns that does not exist here.

CHANGING KIND IS THE ONE CASE THAT NEEDS A DROP: `CREATE OR REPLACE VIEW` over an existing table is an error in BigQuery rather than a replacement, and its message is about a name that already exists rather than about a kind, so the drop is here where the reason can be written down.

func (Dialect) ColumnsOf added in v0.2.0

func (Dialect) ColumnsOf(ref string) string

ColumnsOf reads the dataset's INFORMATION_SCHEMA.

ONE VALUE, not a row set, so Conn keeps its two methods -- see the interface's comment. STRING_AGG with ORDER BY inside it: without the ORDER BY the order is whatever the scan produced, and the column list feeds a `MERGE ... UPDATE SET`, where a different order on two runs would be two different statements for one model.

A relation that is not there yields NULL, which Scalar returns as nil -- the same "nothing is there" KindOf gives, and the caller never asks for the columns of something it has just been told is absent.

func (Dialect) EnsureSchema

func (Dialect) EnsureSchema(schema string) []string

EnsureSchema makes the DATASET. BigQuery's `SCHEMA` is a dataset, and the word in the DDL is the one BigQuery uses.

func (Dialect) ExpireSchema added in v0.2.0

func (Dialect) ExpireSchema(schema string) string

ExpireSchema tells the dataset to throw its tables away after a day.

ONE DAY AND NOT AN HOUR: a conformance run against BigQuery takes ninety seconds, and an expiry a test could outlive would delete the table it is halfway through asserting on. A day is long enough that nothing legitimate meets it and short enough that a leak is gone by tomorrow.

ALTER and not an OPTIONS clause on the CREATE, so EnsureSchema stays the one statement production runs -- see dialect.Disposable for why that separation is not negotiable.

It applies to tables created AFTER it, which is why the caller runs it immediately after making the dataset and before building anything.

The dataset itself does not expire. BigQuery has no such option: a leak becomes an empty dataset rather than no dataset, and that is the residual this cannot remove.

func (Dialect) KindOf

func (Dialect) KindOf(ref string) string

KindOf reads the dataset's INFORMATION_SCHEMA.

TRANSLATED IN SQL, not in Go. BigQuery says `BASE TABLE` and `VIEW`; Postgres says `r` and `v`. Doing the mapping in each dialect's query means the three answers reaching Go are the same three everywhere, and dialect.KindFrom stays a function about drivers rather than about warehouses.

Anything that is not a VIEW is reported as a table, deliberately: an external or materialised view is not something this tool made, and answering "nothing is there" would send a CREATE at it.

func (Dialect) Literal

func (Dialect) Literal(s string) string

Literal escapes with a BACKSLASH, which is the whole difference.

Two measurements on 2026-10-08, both against the real warehouse:

  • a backslash is an ESCAPE here and a character on Postgres. `SELECT LENGTH('a\bc')` is 3 here and 4 there, so one left alone turns `accepted_values: ["a\bc"]` into a test that accepts a value nobody wrote.
  • a doubled quote is NOT an escape here. `'it”s'` is read as two literals written next to each other, and BigQuery refuses it: "concatenated string literals must be separated by whitespace". Postgres takes exactly that form, and it is what the first version of this function did -- copied from the Postgres one, passing every unit test of its output, and failing the conformance suite against the warehouse on the first value with an apostrophe in it.

ORDER MATTERS: the backslash goes first, or the one added for the quote is doubled by the line after it.

Not a raw string (`r'…'`): a raw string cannot contain the quote that closes it, so the one escape it removes is the one still needed.

func (Dialect) Name

func (Dialect) Name() string

Name is also what the reference extractor is given, so it has to be the string `refs` switches on.

func (Dialect) Open

func (Dialect) Open(ctx context.Context, project string) (dialect.Conn, error)

Open connects, with the project ID where other dialects take a DSN.

Credentials come from Application Default Credentials and from nowhere else: on a workload identity that is the pod's own identity, which is what the gateway's BigQuery sink already relies on. A key file in a project directory is the thing this avoids.

func (Dialect) Placeholder added in v0.5.0

func (Dialect) Placeholder(_ int, name string) string

Placeholder is `@name`: BigQuery binds by name. See dialect.Binder.

Jump to

Keyboard shortcuts

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