Skip to content

Commit f44c150

Browse files
committed
[run-tests] Fix get_table_schemas for views
1 parent d34b917 commit f44c150

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

bigquery_etl/dryrun.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ def __init__(
106106
dataset=None,
107107
table=None,
108108
billing_project=None,
109+
ignore_content=False,
109110
):
110111
"""Instantiate DryRun class."""
111112
self.sqlfile = sqlfile
112113
self.content = content
114+
self.ignore_content = ignore_content
113115
self.query_parameters = query_parameters
114116
self.strip_dml = strip_dml
115117
self.use_cloud_function = use_cloud_function
@@ -228,10 +230,13 @@ def get_sql(self):
228230
@cached_property
229231
def dry_run_result(self):
230232
"""Dry run the provided SQL file."""
231-
if self.content:
232-
sql = self.content
233+
if self.ignore_content:
234+
sql = None
233235
else:
234-
sql = self.get_sql()
236+
if self.content:
237+
sql = self.content
238+
elif self.content != "":
239+
sql = self.get_sql()
235240

236241
query_parameters = []
237242
if self.query_parameters:
@@ -595,6 +600,7 @@ def validate_schema(self):
595600
client=self.client,
596601
id_token=self.id_token,
597602
partitioned_by=partitioned_by,
603+
filename=basename(self.sqlfile),
598604
)
599605

600606
# This check relies on the new schema being deployed to prod

bigquery_etl/schema/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from google.cloud.bigquery import SchemaField
1414

1515
from .. import dryrun
16+
from ..config import ConfigLoader
1617

1718
SCHEMA_FILE = "schema.yaml"
1819

@@ -58,24 +59,30 @@ def from_json(cls, json_schema):
5859
return cls(json_schema)
5960

6061
@classmethod
61-
def for_table(cls, project, dataset, table, partitioned_by=None, *args, **kwargs):
62+
def for_table(
63+
cls,
64+
project,
65+
dataset,
66+
table,
67+
partitioned_by=None,
68+
filename="query.sql",
69+
*args,
70+
**kwargs,
71+
):
6272
"""Get the schema for a BigQuery table."""
63-
query = f"SELECT * FROM `{project}.{dataset}.{table}`"
64-
65-
if partitioned_by:
66-
query += f" WHERE DATE(`{partitioned_by}`) = DATE('2020-01-01')"
67-
6873
try:
74+
sql_dir = ConfigLoader.get("default", "sql_dir")
6975
return cls(
7076
dryrun.DryRun(
71-
os.path.join(project, dataset, table, "query.sql"),
72-
query,
77+
os.path.join(sql_dir, project, dataset, table, filename),
7378
project=project,
7479
dataset=dataset,
7580
table=table,
81+
respect_skip=False,
82+
ignore_content=True,
7683
*args,
7784
**kwargs,
78-
).get_schema()
85+
).get_table_schema()
7986
)
8087
except Exception as e:
8188
print(f"Cannot get schema for {project}.{dataset}.{table}: {e}")

sql_generators/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ The directories in `sql_generators/` represent the generated queries and will co
99
Each `__init__.py` file needs to implement a `generate()` method that is configured as a [click command](https://click.palletsprojects.com/en/8.0.x/). The `bqetl` CLI will automatically add these commands to the `./bqetl query generate` command group.
1010

1111
After changes to a schema or adding new tables, the schema is automatically derived from the query and deployed the next day in DAG [bqetl_artifact_deployment](https://workflow.telemetry.mozilla.org/dags/bqetl_artifact_deployment/grid). Alternatively, it can be manually generated and deployed using `./bqetl generate all` and `./bqetl query schema deploy`.
12+

sql_generators/glean_usage/glean_app_ping_views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def _process_ping(ping_name):
149149
partitioned_by="submission_timestamp",
150150
use_cloud_function=use_cloud_function,
151151
id_token=id_token,
152+
filename="view.sql",
152153
)
153154
if schema.schema["fields"] != []:
154155
break

0 commit comments

Comments
 (0)