Documentation
¶
Overview ¶
Package bigquery builds models on Google BigQuery.
Index ¶
- type Dialect
- func (d Dialect) Build(m model.Model, current dialect.Kind) ([]string, error)
- func (Dialect) EnsureSchema(schema string) []string
- func (Dialect) KindOf(ref string) string
- func (Dialect) Literal(s string) string
- func (Dialect) Name() string
- func (Dialect) Open(ctx context.Context, project string) (dialect.Conn, error)
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 ¶
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) EnsureSchema ¶
EnsureSchema makes the DATASET. BigQuery's `SCHEMA` is a dataset, and the word in the DDL is the one BigQuery uses.
func (Dialect) KindOf ¶
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 ¶
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 ¶
Name is also what the reference extractor is given, so it has to be the string `refs` switches on.
func (Dialect) Open ¶
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.