Skip to content

Commit 055562b

Browse files
authored
Feat: handle additional pseudocolumn types in bigquery when resolving… (#5085)
1 parent 7b88251 commit 055562b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

sqlmesh/core/engine_adapter/bigquery.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,26 @@ def create_mapping_schema(
324324
bq_table = self._get_table(table)
325325
columns = create_mapping_schema(bq_table.schema)
326326

327-
if (
328-
include_pseudo_columns
329-
and bq_table.time_partitioning
330-
and not bq_table.time_partitioning.field
331-
):
332-
columns["_PARTITIONTIME"] = exp.DataType.build("TIMESTAMP", dialect="bigquery")
333-
if bq_table.time_partitioning.type_ == "DAY":
334-
columns["_PARTITIONDATE"] = exp.DataType.build("DATE")
327+
if include_pseudo_columns:
328+
if bq_table.time_partitioning and not bq_table.time_partitioning.field:
329+
columns["_PARTITIONTIME"] = exp.DataType.build("TIMESTAMP", dialect="bigquery")
330+
if bq_table.time_partitioning.type_ == "DAY":
331+
columns["_PARTITIONDATE"] = exp.DataType.build("DATE")
332+
if bq_table.table_id.endswith("*"):
333+
columns["_TABLE_SUFFIX"] = exp.DataType.build("STRING", dialect="bigquery")
334+
if (
335+
bq_table.external_data_configuration is not None
336+
and bq_table.external_data_configuration.source_format
337+
in (
338+
"CSV",
339+
"NEWLINE_DELIMITED_JSON",
340+
"AVRO",
341+
"PARQUET",
342+
"ORC",
343+
"DATASTORE_BACKUP",
344+
)
345+
):
346+
columns["_FILE_NAME"] = exp.DataType.build("STRING", dialect="bigquery")
335347

336348
return columns
337349

0 commit comments

Comments
 (0)