Skip to content

feat(cli): add --dry-run to views create-all - #641

Open
leninworld wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
leninworld:feat-638-views-dry-run
Open

leninworld wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
leninworld:feat-638-views-dry-run

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

This PR addresses part of issue #638 (the --dry-run prerequisite, acceptance criterion 1).

Part of #638

Summary

bq-agent-sdk views create-all submits CREATE OR REPLACE VIEW jobs straight away, so a setup guide (or a person) can't see what it will do before it changes BigQuery. On #638, @caohy1988 agreed to a small --dry-run PR first: "Preview and apply should share one ordered plan, and a test should confirm the preview never creates a BigQuery client."

What changed

  • views.py:
    • New private ViewManager._view_plan(): runs the registry collision check and returns the ordered (key, denied_columns) list, per-event views first, then cross-event views. It renders no SQL and never touches the client.
    • New public ViewManager.plan_all_views(): builds one entry per view from _view_plan() with key, name, target (project.dataset.view), the rendered sql and denied_columns (non-empty means create_all_views() skips it).
    • create_all_views() now loops over _view_plan(). The loop body is unchanged: skipped views get the same warning, and each view still goes through create_view() inside the per-view try, so one view that fails to render or create is logged and the others still deploy.
  • cli.py: views create-all --dry-run builds the ViewManager the same way (an invalid --denied-column still exits 2), prints the plan and creates nothing. JSON and text output give dry_run, created: false, action: "CREATE OR REPLACE VIEW", views (with SQL) and skipped. --format table prints one row per view (key, name, target, action, denied columns) without the SQL.
  • SDK.md (Python ViewManager section and CLI reference) and a CHANGELOG [Unreleased] entry.

Tests

  • tests/test_views.py: the plan lists every registered key in order with get_view_sql() / get_view_name() / target values; create_all_views() issues its queries in plan order; the denied-column fixture skips exactly the expected set and create_view() refuses each skipped key; plan_all_views() never calls make_bq_client; a view whose SQL fails to render is left out while the rest are still created.
  • tests/test_cli.py: views create-all --dry-run runs end to end with the real ViewManager while make_bq_client is patched to fail, exits 0, never creates a client and lists every view in plan order with CREATE OR REPLACE VIEW SQL; --dry-run --denied-column=attributes reports the skipped views; --dry-run --denied-column=bogus exits 2; --format table gives one row per view and no SQL.
  • The 8 new plan and dry-run tests fail on main; the render-failure test passes on both, since it pins the behaviour this change keeps.
  • pytest -q -n 8 tests: 12,316 passed, 93 skipped (rebased on current main).
  • pyink --config pyproject.toml --check and isort --check-only pass on the touched Python files.

Limits

  • This covers only the --dry-run prerequisite. The skill itself, the Streamlit walkthrough and the README links from Feature request: Agent Skill for end-to-end BQAA SDK & dashboard setup #638 are not in this PR.
  • The preview lists what create-all would submit; it doesn't check whether the views already exist or whether the caller has permission to create them.
  • views create (one view) has no --dry-run yet.
Part of GoogleCloudPlatform#638. ViewManager.plan_all_views() returns the ordered plan that create_all_views() follows; views create-all --dry-run prints it without creating a BigQuery client.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant