5
5
import os
6
6
import re
7
7
import sys
8
+ import traceback
8
9
from functools import partial
9
10
from multiprocessing .pool import Pool
10
11
from typing import List , Set , Tuple
53
54
is_flag = True ,
54
55
default = False ,
55
56
)
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
+ )
56
64
@click .option (
57
65
"--respect-skip/--ignore-skip" ,
58
66
help = "Respect or ignore query skip configuration. Default is --respect-skip." ,
@@ -67,6 +75,7 @@ def dryrun(
67
75
paths : List [str ],
68
76
use_cloud_function : bool ,
69
77
validate_schemas : bool ,
78
+ validate_union_schemas : bool ,
70
79
respect_skip : bool ,
71
80
project : str ,
72
81
):
@@ -112,9 +121,10 @@ def dryrun(
112
121
113
122
sql_file_valid = partial (
114
123
_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 ,
118
128
credentials = credentials ,
119
129
id_token = id_token ,
120
130
)
@@ -133,7 +143,13 @@ def dryrun(
133
143
134
144
135
145
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 ,
137
153
) -> Tuple [bool , str ]:
138
154
"""Dry run the SQL file."""
139
155
result = DryRun (
@@ -151,4 +167,15 @@ def _sql_file_valid(
151
167
success = False
152
168
return success , sqlfile
153
169
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
+
154
181
return result .is_valid (), sqlfile
0 commit comments