Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions sqlmesh/core/engine_adapter/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,26 @@ def create_mapping_schema(
bq_table = self._get_table(table)
columns = create_mapping_schema(bq_table.schema)

if (
include_pseudo_columns
and bq_table.time_partitioning
and not bq_table.time_partitioning.field
):
columns["_PARTITIONTIME"] = exp.DataType.build("TIMESTAMP", dialect="bigquery")
if bq_table.time_partitioning.type_ == "DAY":
columns["_PARTITIONDATE"] = exp.DataType.build("DATE")
if include_pseudo_columns:
if bq_table.time_partitioning and not bq_table.time_partitioning.field:
columns["_PARTITIONTIME"] = exp.DataType.build("TIMESTAMP", dialect="bigquery")
if bq_table.time_partitioning.type_ == "DAY":
columns["_PARTITIONDATE"] = exp.DataType.build("DATE")
if bq_table.table_id.endswith("*"):
columns["_TABLE_SUFFIX"] = exp.DataType.build("STRING", dialect="bigquery")
if (
bq_table.external_data_configuration is not None
and bq_table.external_data_configuration.source_format
in (
"CSV",
"NEWLINE_DELIMITED_JSON",
"AVRO",
"PARQUET",
"ORC",
"DATASTORE_BACKUP",
)
):
columns["_FILE_NAME"] = exp.DataType.build("STRING", dialect="bigquery")

return columns

Expand Down