fix: support bigquery array of struct type for dbt#1374
Open
sahmed1991 wants to merge 3 commits into
Open
Conversation
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.
Summary
Problem
datacontract import dbt (BigQuery adapter) failed with Unsupported type ARRAY<STRUCT<>> in bigquery json definition because map_type_from_bigquery only understood bare BigQuery type names, not compound types like ARRAY<STRUCT<...>>, STRUCT, STRING(100), or NUMERIC(10, 2).
Changes
datacontract/imports/bigquery_importer.py
Added parse_bigquery_type(str) -> ParsedBigQueryType — a proper recursive descent parser that handles arbitrary nesting, empty struct bodies (STRUCT<>), whitespace, anonymous struct fields, and parameterised inner types.
datacontract/imports/dbt_importer.py
Tests
New file tests/test_import_bigquery_type_parser.py (54 tests) covers:
*tests/test_import_dbt.py: added 4 end-to-end tests that build an in-memory dbt BigQuery manifest and assert the importer produces the correct nested ODCS structure for ARRAY<STRUCT<>>, ARRAY<STRUCT<field ...>>, STRUCT<...> columns, and a regression guard for scalar columns.
Verification
uv run pytest)uv run ruff check --fix && uv run ruff format)