Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have bqetl query commands fail if they don't find a matching query #4662

Merged
merged 7 commits into from
Dec 8, 2023
10 changes: 10 additions & 0 deletions bigquery_etl/cli/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ def info(ctx, name, sql_dir, project_id, cost, last_updated):
ignore=["derived_view_schemas", "stable_views"],
)
query_files = paths_matching_name_pattern(name, ctx.obj["TMP_DIR"], project_id)
if query_files == []:
raise click.ClickException(f"No queries matching `{name}` were found.")

for query_file in query_files:
query_file_path = Path(query_file)
Expand Down Expand Up @@ -719,6 +721,8 @@ def backfill(
ignore=["derived_view_schemas", "stable_views", "country_code_lookup"],
)
query_files = paths_matching_name_pattern(name, ctx.obj["TMP_DIR"], project_id)
if query_files == []:
raise click.ClickException(f"No queries matching `{name}` were found.")

for query_file in query_files:
query_file_path = Path(query_file)
Expand Down Expand Up @@ -895,6 +899,8 @@ def run(
ignore=["derived_view_schemas", "stable_views", "country_code_lookup"],
)
query_files = paths_matching_name_pattern(name, ctx.obj["TMP_DIR"], project_id)
if query_files == []:
raise click.ClickException(f"No queries matching `{name}` were found.")

_run_query(
query_files,
Expand Down Expand Up @@ -1992,6 +1998,8 @@ def deploy(
query_files = paths_matching_name_pattern(
name, ctx.obj["TMP_DIR"], project_id, ["query.*"]
)
if not query_files:
raise click.ClickException(f"No queries matching `{name}` were found.")

def _deploy(query_file):
if respect_dryrun_skip and str(query_file) in DryRun.skipped_files():
Expand Down Expand Up @@ -2253,6 +2261,8 @@ def validate_schema(
ignore=["derived_view_schemas", "stable_views"],
)
query_files = paths_matching_name_pattern(name, ctx.obj["TMP_DIR"], project_id)
if query_files == []:
raise click.ClickException(f"No queries matching `{name}` were found.")

_validate_schema = partial(
_validate_schema_from_path,
Expand Down
9 changes: 7 additions & 2 deletions tests/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,10 @@ def test_run_query_write_to_table(

@pytest.mark.integration
def test_run_query_no_query_file(self):
result = subprocess.check_output([ENTRYPOINT_SCRIPT, "query"])
assert b"No files matching:" in result
with pytest.raises(subprocess.CalledProcessError) as e:
subprocess.run(
[ENTRYPOINT_SCRIPT, "query"],
check=True,
capture_output=True,
)
assert b"No queries matching" in e.value.stderr