You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 03a9b37
Browse filesBrowse the repository at this point in the historyBrowse files
`finops_query_history` was failing 100% on BigQuery with
`Unrecognized name: error_message at [11:5]`. Telemetry traced it to one
session looping 76 times over 2.5 hours. Three separate bugs in the BQ
query-history template plus a broader region-locking issue across the
whole finops module.
Fixes in `packages/opencode/src/altimate/native/finops/query-history.ts`
BIGQUERY_HISTORY_SQL:
- `error_message` does not exist as a top-level column in
INFORMATION_SCHEMA.JOBS. Replace with `error_result.message AS error_message`.
- `error_result.reason AS error_code` in place of the previous hardcoded NULL
(more useful and matches the struct that actually exists).
- `total_rows` is a PARTITIONS column, not JOBS. Replace with
`CAST(NULL AS INT64) AS rows_produced` so the downstream summary loop
doesn't error.
- BQ's `state` returns `'DONE'`, not `'SUCCESS'`. `getQueryHistory()` counts
any `execution_status != 'SUCCESS'` as a failure, so bare
`state AS execution_status` was flagging every completed BQ job as failed.
Derive `CASE WHEN error_result IS NULL THEN 'SUCCESS' ELSE 'FAILED' END`
to match the other warehouse templates.
Multi-region support across all 5 finops modules:
- All BQ `INFORMATION_SCHEMA` queries were hardcoded to
`` `region-US.INFORMATION_SCHEMA.*` ``, making the tools unusable for
non-US BigQuery projects. Replace with `{region}` placeholder and
interpolate from the connection's configured `location` at runtime.
- New shared helper `finops/bq-utils.ts` exposes `sanitizeBqRegion`
(allowlist `[a-z0-9-]`, trim hyphens, cap at 64 chars, fall back to `us`),
`interpolateBqRegion` (uses `replaceAll` so future JOIN-across-views
templates stay safe), and `bqRegionFor(warehouse)`.
- Covers query-history, credit-analyzer (3 templates), warehouse-advisor
(2 templates), role-access, and unused-resources.
Snowflake and Databricks paths are untouched. The new `bqRegion?` parameter
is optional on every build helper and only consumed inside
`whType === "bigquery"` branches; regression tests assert Snowflake and
Databricks SQL still contains `QUERY_HISTORY` / `system.query.history` and
never `region-`.
Tests:
- New `schema-finops-dbt.test.ts` assertions: column-level regression guards
(no bare `error_message`/`total_rows`/`state as execution_status`), a
table-driven test that no finops BQ template contains `region-US`,
region-threading tests for all 5 build helpers, sanitizer coverage
(injection, hyphen-trim, length cap, non-string), Snowflake/Databricks
regression guards. 75 pass (up from 66).
- New `finops-bigquery-e2e.test.ts`: skipIf-gated against
`ALTIMATE_CODE_CONN_BIGQUERY_TEST`, mirrors the Snowflake pattern.
Verifies shape, no SQL parse errors, derived `execution_status`,
error_count math, and a bad-region graceful-failure path. 10/10 pass
against real BigQuery (US region).
- Full altimate suite: 2917/2917 pass (was 2908). Typecheck clean.
Reviewed via /consensus:code-review by GPT-5.4, Gemini 3.1 Pro, and
DeepSeek V3.2 — all three APPROVE on round 1 after incorporating their
MAJOR findings (missing tests, missed files, sanitizer hardening).
Closes#738
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
0 commit comments