BigQuery DDL¶
Overview¶
The BigQuery DDL generator produces native Google BigQuery
CREATE TABLE statements from a LinkML schema. It extends the SQL DDL generator with
BigQuery-specific types (ARRAY<T>, STRUCT<...>, TIMESTAMP) and supports
BigQuery table options such as time/range partitioning, clustering, and table descriptions
via LinkML annotations.
Note
This generator requires the sqlalchemy-bigquery optional dependency.
Install it with: pip install 'linkml[bigquery]'
Example Output¶
Given a schema with a Person class, the generator produces DDL like:
CREATE TABLE `Person` (
id STRING NOT NULL,
name STRING,
age INT64,
aliases ARRAY<STRING>
);
BigQuery Annotations¶
You can control BigQuery-specific table options via slot/class annotations:
bigquery_type— override the column type (e.g.TIMESTAMP)bigquery_partition_by— field name to use for time/range partitioningbigquery_partition_type—DAY,HOUR,MONTH,YEAR, orRANGEbigquery_cluster_by— comma-separated field names for clusteringbigquery_description— table-level description string
Docs¶
Command Line¶
gen-bigquery¶
Generate BigQuery DDL representation
gen-bigquery [OPTIONS] YAMLFILE
Options
- --dataset <dataset>¶
BigQuery dataset prefix
- -V, --version¶
Show the version and exit.
- -f, --format <format>¶
Output format
- Default:
'bigquery'- Options:
bigquery
- --metadata, --no-metadata¶
Include metadata in output
- Default:
True
- --useuris, --metauris¶
Use class and slot URIs over model uris
- Default:
True
- -im, --importmap <importmap>¶
Import mapping file
- --log_level <log_level>¶
Logging level
- Default:
'WARNING'- Options:
CRITICAL | ERROR | WARNING | INFO | DEBUG
- -v, --verbose¶
Verbosity. Takes precedence over –log_level.
- --mergeimports, --no-mergeimports¶
Merge imports into source file (default=mergeimports)
- --stacktrace, --no-stacktrace¶
Print a stack trace when an error occurs
- Default:
False
Arguments
- YAMLFILE¶
Required argument
Code¶
- class linkml.generators.bigquerygen.BigQueryGenerator(schema: str | ~typing.TextIO | ~linkml_runtime.linkml_model.meta.SchemaDefinition | Generator | ~pathlib.Path, schemaview: ~linkml_runtime.utils.schemaview.SchemaView | None = None, format: str | None = None, metadata: bool = True, useuris: bool | None = None, log_level: int | None = 30, mergeimports: bool | None = True, source_file_date: str | None = None, source_file_size: int | None = None, logger: ~logging.Logger | None = None, verbose: bool | None = None, output: str | None = None, namespaces: ~linkml_runtime.utils.namespaces.Namespaces | None = None, directory_output: bool = False, base_dir: str = None, metamodel_name_map: dict[str, str] = None, importmap: str | ~collections.abc.Mapping[str, str] | None = None, emit_prefixes: set[str] = <factory>, metamodel: ~linkml.utils.schemaloader.SchemaLoader = None, stacktrace: bool = False, include: str | ~pathlib.Path | ~linkml_runtime.linkml_model.meta.SchemaDefinition | None = None, use_inherits: bool = False, dialect: str = 'sqlite', inject_primary_keys: bool = False, use_foreign_keys: bool = False, rename_foreign_keys: bool = False, direct_mapping: bool = False, relative_slot_num: bool = False, default_length_oracle: int = 4096, generate_abstract_class_ddl: bool = True, autogenerate_index: bool = True, dataset: str | None = None)[source]¶
A Generator for BigQuery CREATE TABLE DDL.
Produces native BigQuery DDL including ARRAY<T>, STRUCT<…>, PARTITION BY, CLUSTER BY, and OPTIONS clauses.
Usage:
gen = BigQueryGenerator("schema.yaml") print(gen.serialize())