feat(streamer): align CSV columns by header name for append/upsert (UNTESTED on Composer)#138
Draft
demenech wants to merge 1 commit into
Draft
feat(streamer): align CSV columns by header name for append/upsert (UNTESTED on Composer)#138demenech wants to merge 1 commit into
demenech wants to merge 1 commit into
Conversation
The CSV streamer preserved the source file's column order and BigQuery loaded it positionally against the schema, so an append/upsert whose file had reordered, added, or omitted columns shifted data into the wrong column (or failed). Add a field_order option: when set, each output row is emitted in schema order, pulling each field from the source by sanitized header name (missing -> NULL, extras dropped). date_formats stays valid (keyed by the same field index). The DAG passes the descriptor's field order. Enables non-destructive column merge on append/upsert. Validated locally on the CSV path (reordered/added/missing + sanitized headers); needs a dev-Composer run for full BigQuery integration coverage.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The issue
The CSV streamer preserves the source file's column order, and BigQuery then loads it
positionally against the schema (BQ maps CSV columns by ordinal, not header name). So an
append/upsert whose file has reordered, added, or omitted columns shifts data into the
wrong column — or fails the load. This blocks non-destructive column changes on append/upsert:
column in its exact order;
ALLOW_FIELD_ADDITIONis already set on append loads, so BigQuery can add a new column — butonly if the streamed CSV is aligned to the schema by name first. That alignment is what's
missing.
The proposed fix
Add a
field_orderoption to the streamer. When set, each output row is emitted in schemafield order, pulling each column from the source by sanitized header name:
date_formatsstays valid because it's keyed by the descriptor field index, which equals theoutput order. When
field_orderisNone, the legacy positional behaviour is unchanged. TheDAG passes the descriptor's field order.
Header names are sanitized the same way the schema descriptor's field names are (BigQuery-safe),
so e.g.
Price (GBP)in the file matches thePrice_GBPschema field.Files:
aircan/dependencies/cloud/storage.py(_stream_csv),aircan/dags/pipeline_ckan_to_bigquery.py(passesfield_order).Why (frontend context)
The dx-helm-neso frontend now merges the uploaded file's schema with the stored one on
append/upsert (existing columns kept + locked, new columns appended). Today the FE blocks
reorder / mid-insert / missing because the deployed positional load can't handle them safely.
This change makes those layouts load correctly by name; once it's deployed, the FE flips its
capability flags and stops blocking them (no UI rewrite).
How to validate (dev Composer → BigQuery)
Against an existing datastore table, run append/upsert with files that:
Price (GBP)vsPrice_GBP) → matched by name.Confirm row counts and per-column values in BigQuery after each.
Not covered here
The create-with-upload double-load is a separate issue (ckanext-aircan
notifydedupe +frontend create-collapse) — not this PR.