Skip to content

Commit 43930ec

Browse files
committed
feat(dryrun): Add --validate-union-schemas option (DENG-7746).
1 parent 56f30f6 commit 43930ec

File tree

3 files changed

+388
-70
lines changed

3 files changed

+388
-70
lines changed

bigquery_etl/cli/dryrun.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import re
77
import sys
8+
import traceback
89
from functools import partial
910
from multiprocessing.pool import Pool
1011
from typing import List, Set, Tuple
@@ -53,6 +54,13 @@
5354
is_flag=True,
5455
default=False,
5556
)
57+
@click.option(
58+
"--validate_union_schemas",
59+
"--validate-union-schemas",
60+
help="Require any subqueries being unioned to have exactly matching schemas.",
61+
is_flag=True,
62+
default=False,
63+
)
5664
@click.option(
5765
"--respect-skip/--ignore-skip",
5866
help="Respect or ignore query skip configuration. Default is --respect-skip.",
@@ -67,6 +75,7 @@ def dryrun(
6775
paths: List[str],
6876
use_cloud_function: bool,
6977
validate_schemas: bool,
78+
validate_union_schemas: bool,
7079
respect_skip: bool,
7180
project: str,
7281
):
@@ -112,9 +121,10 @@ def dryrun(
112121

113122
sql_file_valid = partial(
114123
_sql_file_valid,
115-
use_cloud_function,
116-
respect_skip,
117-
validate_schemas,
124+
use_cloud_function=use_cloud_function,
125+
respect_skip=respect_skip,
126+
validate_schemas=validate_schemas,
127+
validate_union_schemas=validate_union_schemas,
118128
credentials=credentials,
119129
id_token=id_token,
120130
)
@@ -133,7 +143,13 @@ def dryrun(
133143

134144

135145
def _sql_file_valid(
136-
use_cloud_function, respect_skip, validate_schemas, sqlfile, credentials, id_token
146+
sqlfile,
147+
use_cloud_function,
148+
respect_skip,
149+
validate_schemas,
150+
validate_union_schemas,
151+
credentials,
152+
id_token,
137153
) -> Tuple[bool, str]:
138154
"""Dry run the SQL file."""
139155
result = DryRun(
@@ -151,4 +167,15 @@ def _sql_file_valid(
151167
success = False
152168
return success, sqlfile
153169

170+
if validate_union_schemas:
171+
try:
172+
success = result.validate_union_schemas()
173+
except Exception:
174+
click.echo(
175+
f"Failed to validate union schemas in {sqlfile}:\n{traceback.format_exc(limit=0)}",
176+
err=True,
177+
)
178+
success = False
179+
return success, sqlfile
180+
154181
return result.is_valid(), sqlfile

0 commit comments

Comments
 (0)