Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Patch for dbt show for a model with a struct column containing a json datatype#974

Merged
colin-rogers-dbt merged 7 commits into
mainfrom
mwinkler/json-show-patch
Oct 23, 2023
Merged

Patch for dbt show for a model with a struct column containing a json datatype#974
colin-rogers-dbt merged 7 commits into
mainfrom
mwinkler/json-show-patch

Conversation

@matt-winkler
Copy link
Copy Markdown
Contributor

@matt-winkler matt-winkler commented Oct 21, 2023

resolves #972

Problem

dbt show --select currently breaks when attempted on a json field because of this bigquery python client issue

Solution

Patch as suggested by @dbeatty10

# Override broken json deserializer for dbt show --inline
def _json_from_json(value, _):
    """NOOP string -> string coercion"""
    return json.loads(value)

bigquery._helpers._CELLDATA_FROM_JSON["JSON"] = _json_from_json

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc)

@matt-winkler matt-winkler requested a review from a team as a code owner October 21, 2023 21:48
@cla-bot cla-bot Bot added the cla:yes label Oct 21, 2023
@dbeatty10 dbeatty10 added the triage:ready-for-review Externally contributed PR has functional approval, ready for code review from Core engineering label Oct 23, 2023
@dbeatty10
Copy link
Copy Markdown
Contributor

@cla-bot check

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Oct 23, 2023

The cla-bot has been summoned, and re-checked this pull request!

Comment thread .changes/unreleased/Fixes-20231021-154237.yaml Outdated
Comment thread dbt/adapters/bigquery/connections.py
@@ -0,0 +1,6 @@
kind: Fixes
body: Patch for json inline --show
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you generated a second changelog instead of updating this one, you can just delete this file

matt-winkler and others added 3 commits October 23, 2023 10:27
Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>
Comment thread tests/functional/adapter/dbt_show/test_dbt_show.py
Copy link
Copy Markdown
Contributor

@mikealfare mikealfare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one minor comment that doesn't affect functionality. I'm providing an approval so that you can merge following that update.

@dbeatty10 dbeatty10 changed the title patch for --show with json Patch for dbt show for a model with a json column Oct 23, 2023
@dbeatty10 dbeatty10 changed the title Patch for dbt show for a model with a json column Patch for dbt show for a model with a struct column containing a json datatype Oct 23, 2023
@colin-rogers-dbt colin-rogers-dbt enabled auto-merge (squash) October 23, 2023 17:34
@colin-rogers-dbt colin-rogers-dbt merged commit 6a3f458 into main Oct 23, 2023
@colin-rogers-dbt colin-rogers-dbt deleted the mwinkler/json-show-patch branch October 23, 2023 17:35
@@ -0,0 +1,6 @@
kind: Fixes
body: Patch for json inline --show
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
body: Patch for json inline --show
body: Patch for `dbt show` for `json` within a `struct`

github-actions Bot pushed a commit that referenced this pull request Oct 23, 2023
…`json` datatype (#974)

* patch for --show with json

* update matts handle in changelog

* Update dbt/adapters/bigquery/connections.py

Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>

* add json struct functional test

* remove old change log

* add comment to test

---------

Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>
Co-authored-by: Colin <colin.rogers@dbtlabs.com>
(cherry picked from commit 6a3f458)
colin-rogers-dbt pushed a commit that referenced this pull request Oct 23, 2023
…`json` datatype (#974) (#976)

* patch for --show with json

* update matts handle in changelog

* Update dbt/adapters/bigquery/connections.py

Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>

* add json struct functional test

* remove old change log

* add comment to test

---------

Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>
Co-authored-by: Colin <colin.rogers@dbtlabs.com>
(cherry picked from commit 6a3f458)

Co-authored-by: matt-winkler <75497565+matt-winkler@users.noreply.github.com>
github-actions Bot pushed a commit that referenced this pull request Oct 24, 2023
…`json` datatype (#974)

* patch for --show with json

* update matts handle in changelog

* Update dbt/adapters/bigquery/connections.py

Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>

* add json struct functional test

* remove old change log

* add comment to test

---------

Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>
Co-authored-by: Colin <colin.rogers@dbtlabs.com>
(cherry picked from commit 6a3f458)
colin-rogers-dbt pushed a commit that referenced this pull request Oct 25, 2023
…`json` datatype (#974) (#978)

* patch for --show with json

* update matts handle in changelog

* Update dbt/adapters/bigquery/connections.py

Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>

* add json struct functional test

* remove old change log

* add comment to test

---------

Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>
Co-authored-by: Colin <colin.rogers@dbtlabs.com>
(cherry picked from commit 6a3f458)

Co-authored-by: matt-winkler <75497565+matt-winkler@users.noreply.github.com>
tatiana added a commit to astronomer/astronomer-cosmos that referenced this pull request Apr 29, 2025
…xes (#1719)

While the initial x.x.0 versions of dbt adapters may have compatibility
issues with certain dependencies, I observed that these
incompatibilities are progressively addressed in later patch releases.
The issue reported in #1709 appears to stem from dbt-bigquery accessing
a protected member `google.cloud.bigquery._helpers._CELLDATA_FROM_JSON`,
which was removed in `google-cloud-bigquery 3.31.0`. This access I
believe was introduced in
[dbt-bigquery#974](dbt-labs/dbt-bigquery#974)
and later removed in
[dbt-bigquery#1061](dbt-labs/dbt-bigquery#1061),
with the fix subsequently back-ported to the 1.7 series via
[dbt-bigquery#1074](dbt-labs/dbt-bigquery#1074).
Therefore, I believe that relying on the latest patch versions is a
better approach to avoid such issues, rather than individually resolving
discrepancies. This PR aligns with that strategy.


closes: #1709

---------

Co-authored-by: Tatiana Al-Chueyr <tatiana.alchueyr@gmail.com>
pankajkoti added a commit to astronomer/astronomer-cosmos that referenced this pull request Apr 29, 2025
…xes (#1719)

While the initial x.x.0 versions of dbt adapters may have compatibility
issues with certain dependencies, I observed that these
incompatibilities are progressively addressed in later patch releases.
The issue reported in #1709 appears to stem from dbt-bigquery accessing
a protected member `google.cloud.bigquery._helpers._CELLDATA_FROM_JSON`,
which was removed in `google-cloud-bigquery 3.31.0`. This access I
believe was introduced in
[dbt-bigquery#974](dbt-labs/dbt-bigquery#974)
and later removed in
[dbt-bigquery#1061](dbt-labs/dbt-bigquery#1061),
with the fix subsequently back-ported to the 1.7 series via
[dbt-bigquery#1074](dbt-labs/dbt-bigquery#1074).
Therefore, I believe that relying on the latest patch versions is a
better approach to avoid such issues, rather than individually resolving
discrepancies. This PR aligns with that strategy.


closes: #1709

---------

Co-authored-by: Tatiana Al-Chueyr <tatiana.alchueyr@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla:yes triage:ready-for-review Externally contributed PR has functional approval, ready for code review from Core engineering

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ADAP-950] [Bug] dbt show doesn't work with json structs

4 participants