Skip to content

Commit a2e7397

Browse files
authored
Support deploying syndicated views to stage (#8532)
* Support for deploying syndicated views to stage * Don't publish or replace references of syndicate views in stage deploys * Address review feedback * test app store view deploys * get schemas for tables that aren't in the repo * undo app store test * Address review feedback
1 parent ad634b6 commit a2e7397

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

bigquery_etl/cli/stage.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,18 @@ def _view_dependencies(artifact_files, sql_dir):
310310
if not path.exists():
311311
path.mkdir(parents=True, exist_ok=True)
312312
# don't create schema for wildcard and metadata tables
313+
# Create schemas for syndicated tables, stable, live tables and other
314+
# tables not managed by bigquery-etl by doing a dryrun.
315+
# The stage project doesn't have access to prod tables (e.g when referenced)
316+
# so we need to create the schema here and deploy it.
313317
if "*" not in name and name != "INFORMATION_SCHEMA":
314-
partitioned_by = "submission_timestamp"
318+
partitioned_by = None
319+
320+
if any(
321+
dataset.endswith(suffix) for suffix in ("_live", "_stable")
322+
):
323+
partitioned_by = "submission_timestamp"
324+
315325
schema = Schema.for_table(
316326
project=project,
317327
dataset=dataset,
@@ -321,11 +331,11 @@ def _view_dependencies(artifact_files, sql_dir):
321331
)
322332
schema.to_yaml_file(path / SCHEMA_FILE)
323333

324-
if not file_exists_for_dependency:
325-
(path / QUERY_SCRIPT).write_text(
326-
"# Table stub generated by stage deploy"
327-
)
328-
view_dependencies.add(path / QUERY_SCRIPT)
334+
if not file_exists_for_dependency:
335+
(path / QUERY_SCRIPT).write_text(
336+
"# Table stub generated by stage deploy"
337+
)
338+
view_dependencies.add(path / QUERY_SCRIPT)
329339

330340
# extract UDF references from view definition
331341
raw_routines = read_routine_dir()

bigquery_etl/view/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ def publish(self, target_project=None, dry_run=False, client=None):
426426

427427
if not self.metadata:
428428
print(f"Missing metadata for {self.path}")
429-
430-
table.description = self.metadata.description
431-
table.friendly_name = self.metadata.friendly_name
429+
else:
430+
table.description = self.metadata.description
431+
table.friendly_name = self.metadata.friendly_name
432432

433433
if table.labels != self.labels:
434434
labels = self.labels.copy()

0 commit comments

Comments
 (0)