Skip to main content

Google BigQuery Reference

Authentication options and data type handling for BigQuery connections.

Authentication

Authentication uses a Service Account Key or Application Default Credentials (ADC) — including Workload Identity Federation (WIF), the GCE metadata server, and gcloud auth application-default login. The account needs the BigQuery Job User and BigQuery Data Viewer roles.

VariableExampleDescription
DATACONTRACT_BIGQUERY_ACCOUNT_INFO_JSON_PATH~/service-access-key.jsonService Account key JSON file used by test. If unset, ADC/WIF is used.
DATACONTRACT_BIGQUERY_BILLING_PROJECTmy-compute-projectOptional. Project to bill query jobs to. Requires bigquery.jobUser on the billing project and bigquery.dataViewer on the data project.

project and dataset come from the contract's servers block. datacontract import bigquery always uses ADC — set GOOGLE_APPLICATION_CREDENTIALS to point it at a key file.

Data types

Importing

datacontract import bigquery maps BigQuery types as follows; the original BigQuery type is kept as physicalType. An unknown type fails the import with an error.

BigQuery typelogicalType
STRINGstring (maxLength if declared)
BYTESarray
INTEGER, INT64integer
FLOAT, FLOAT64number
NUMERIC, BIGNUMERICnumber (precision/scale as custom properties)
BOOLEAN, BOOLboolean
TIMESTAMP, DATETIMEtimestamp
DATEdate
TIMEtime
GEOGRAPHY, JSONobject
INTERVALstring
RECORD, STRUCTobject with nested properties
RANGEarray with typed items
any type with mode REPEATEDarray with typed items

Fields with mode REQUIRED become required: true. Tables, external tables, and snapshots become schema physicalType: table; views and materialized views become view.

Testing

BigQuery supports native type introspection: the declared physicalType is checked against the actual column type from the BigQuery API. Timezone variants of timestamps are interchangeable; parameters (precision, length) are only enforced when the contract declares them. If the physicalType cannot be interpreted as a BigQuery type, the check falls back to the logical type category comparison.

Logical type mapping

When no physicalType is declared, the CLI derives the native type from the logicalType — for example in datacontract export sql and the dbt exports. This table is generated from the converter in the CLI's code:

logicalTypeBigQuery type
stringSTRING
integerINTEGER
numberNUMERIC
booleanBOOL
dateDATE
timestampTIMESTAMP
timeTIME
objectSTRUCT<>
arrayARRAY<STRING>