Repository navigation
Conversation
Ford544
left a comment
There was a problem hiding this comment.
Task metadata is currently returned empty for dry runs because the metadata included for real runs largely does not apply to them (job_id is not populated and byte counts are only approximations). You suggest adding completely new kinds of information there (referenced tables and schema), just for dry runs - could you elaborate on what, in your view, makes those particular fields useful and worth including here?
If we do decide to include them, it would be preferable to also add them to real runs, for consistency - otherwise the same field (metadata) has completely different contents for real and dry runs, which would be confusing.
The convertFieldType() fix is good but it does not concern dry run statistics specifically. I suggest moving it to a seperate PR.
| case "INT64": | ||
| return dataform.Field.Primitive.INTEGER; | ||
| case "NUMERIC": | ||
| case "BIGNUMERIC": |
There was a problem hiding this comment.
This is a good fix, but not directly related to the PR's main purpose. I would suggest seperating it into a different PR.
There was a problem hiding this comment.
Moved to #2446, along with its tests and the ESLint rule.
| const statistics = jobMetadata?.statistics?.query || {}; | ||
| return { | ||
| bigquery: { | ||
| // Left unset when not reported, so a missing count isn't reported as 0. |
There was a problem hiding this comment.
For real (non-dry) runs, totalBytesProcessed is set to 0 (see L578), so this would be an inconsistency. I would prefer to stick with the current behavior here.
There was a problem hiding this comment.
Done in 7abe968: a count BigQuery doesn't report is now 0, as in real runs.
|
Thanks for the review, @Ford544. Why these fields? The dry-run job Dataform already submits returns them, so keeping them is nearly free, and the change is additive for
Consistency. Agreed. Dry and real runs now share one extraction, so
|
|
/gcbrun |
Ford544
left a comment
There was a problem hiding this comment.
Thanks for making the changes and explaining the rationale behind including referencedTables and schema.
rafal-hawrylak
left a comment
There was a problem hiding this comment.
Assertion check queries are skipped in dry runs, so their task still prints metadata: {}. Can we note that so the SELECT row is not read as covering assertions?
This PR adds new output fields, so feat(cli) fits better than fix(cli). A shorter title would also help.
| // documents it for dry runs only; real runs may include it for some | ||
| // statements, but not reliably. Uses Dataform's lossy Field representation: | ||
| // e.g. RANGE becomes UNKNOWN, and nullability and type parameters aren't kept. | ||
| repeated Field schema = 5; |
There was a problem hiding this comment.
Could we name this schema_fields? A list of Field is called fields in TableMetadata and schema_fields in jit.proto, and schema means the dataset in the Target entries right next to it. The name is hard to change once released.
There was a problem hiding this comment.
Renamed to schema_fields (schemaFields in --json). The jit.proto precedent and the clash with Target.schema are good reasons.
Dry runs now return metadata built from the job resource returned on creation (bytes processed, referenced tables, result schema) instead of reading the results stream, which fails with "Not found: Job" for dry runs and was turned into empty metadata by a workaround. Adds referenced_tables and schema to BigqueryMetadata, fixes duplicate case labels in convertFieldType() so BIGNUMERIC, JSON and INTERVAL get their own primitives, and enables ESLint's no-duplicate-case. Fixes dataform-co#2432
Real runs now report referenced_tables and schema whenever BigQuery's job statistics include them, using the same extraction as dry runs. Dry runs report a total_bytes_processed BigQuery didn't supply as 0, like real runs.
7abe968 to
b121632
Compare
|
Thanks for the review, @rafal-hawrylak.
I also rebased onto |
Fixes #2432.
Problem
dataform run --dry-run --jsonreturns"metadata": {}for successful dry-run tasks, even when BigQuery supplies statistics.createQueryJobreads every job throughgetQueryResultsStream(), but BigQuery doesn't save dry-run jobs, so the stream fails withNot found: Joband a workaround resolves empty results. The statistics (JobStatistics2) were already in the job resource returned on creation.Changes
query()does the same for dry runs. Cancellation is still checked.BigqueryMetadatagainsreferenced_tables = 4andschema_fields = 5, filled in with the existingtotal_bytes_processedfor dry runs. A byte count BigQuery doesn't report is0, as for real runs.job_idstays empty, since dry-run jobs aren't saved.referenced_tablesandschema_fieldstoo, sometadatameans the same thing in both modes: whatever BigQuery's job statistics report. Both modes use one extraction (jobStatisticsMetadata()), and real runs keepjob_idandtotal_bytes_billed. The job metadata was already being fetched, so this adds no requests.Example
metadata({low, high, unsigned}is how--jsonalready prints int64 values):{ "bigquery": { "totalBytesProcessed": { "low": 2650191, "high": 0, "unsigned": false }, "referencedTables": [{ "database": "bigquery-public-data", "schema": "samples", "name": "shakespeare" }], "schemaFields": [{ "name": "word", "primitive": "STRING" }, { "name": "c", "primitive": "INTEGER" }] } }Behavior
Dry-run errors detected at job creation still propagate, and nothing uses dry-run metadata to decide anything. Against real BigQuery, the released 3.1.5 CLI and this branch gave identical statuses and errors in the cases I tested (tables, views, operations,
MERGE/INSERT/INSERT_OVERWRITEincrementals, pre-operations). The one difference: dry runs no longer make the results request, so its own failures can't fail a task.What BigQuery reported in the cases I tested, by statement and mode (observed, not guaranteed):
referencedTables(dry / real)schemaFields(dry / real)CREATE VIEWSELECT(e.g. aSELECToperation)INSERT,MERGEDECLARE …; SELECT …SELECT's)INSERT_OVERWRITE)totalBytesProcessedis reported in every case, but for a dry run of a script starting with DDL it's0(a lower bound). For real scripts, referenced tables are only reported on the child jobs. BigQuery documents the schema as "present only for successful dry run of non-legacy SQL queries", so the real-run ✅ cells are observed, undocumented behavior, and consumers shouldn't rely on them.0may be an incomplete estimate. An accuracy field would be a small follow-up.referencedTables: []means none were reported. A query reading a view lists the view's underlying tables, not the view (in my tests,SELECTfrom a view reported only its source table). BigQuery reports views in a separatereferencedLogicalViewsfield, which could be a small follow-up.schemaFieldsis BigQuery's result schema in Dataform's lossyFieldform (e.g.RANGEbecomesUNKNOWN), not necessarily the destination table's. The proto comments say this too. It's namedschema_fields, like theFieldlist injit.proto, becauseschemameans the dataset inTarget.metadata: {}and theSELECTrow doesn't apply to them. In real runs they report like anySELECT.SELECTplus pre-operations), as before. A real run instead executes the wrapper script, so the task that creates the dataset reports neither field. Later runs into that dataset aren't wrapped.Tests
cli/api/dbadapters/bigquery_test.tsadds 10 tests. In the 8 dry-run tests, the mock's results stream fails withNot found: Job, like BigQuery's for dry runs. The 2 real-run tests cover full statistics and aMERGE-like job without a schema or byte counts. Eight fail onmain: statistics mapping (nested/repeated fields,RANGE), missing statistics, int64 precision through--json, retries, and both real-run tests. Two pass onmaintoo and guard existing behavior: error propagation and cancellation.tests/api/schemas.spec.tsnow gives the wrapper and validation query different metadata, therun --dry-run --jsonintegration test checksmetadata.bigqueryagainst real BigQuery, and therun --jsontest checks that real runs report both fields. It doesn't check their contents, since the real-run schema is undocumented.Unit tests, ESLint and Prettier pass. Integration tests pass against a personal project, except
bigquery.spec > search, which fails identically onmain(missingINFORMATION_SCHEMApermission). Real runs still report job IDs, bytes billed and runtime errors as before. The fullrune2e suite passes.🤖 Generated with Claude Code