Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADAP-1073] [Bug] Not able preview structs when the struct is null #1055

Closed
2 tasks done
jeremyyeo opened this issue Dec 12, 2023 · 1 comment
Closed
2 tasks done
Assignees
Labels
bug Something isn't working High Severity bug with significant impact that should be resolved in a reasonable timeframe

Comments

@jeremyyeo
Copy link
Contributor

jeremyyeo commented Dec 12, 2023

Is this a new bug in dbt-bigquery?

  • I believe this is a new bug in dbt-bigquery
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

If we have a struct column that contains null then dbt show runs into an unhandled error.

Expected Behavior

We should gracefully handle this error.

Steps To Reproduce

  1. Create 2 tables:
create or replace table dbt_jyeo.json_error as select struct<k json>(to_json(struct(1 as a))) as v;
insert into dbt_jyeo.json_error values (struct<k json>(null));
select * from dbt_jyeo.json_error;

create or replace table dbt_jyeo.json_okay as select struct<k json>(to_json(struct(1 as a))) as v;
insert into dbt_jyeo.json_okay values (struct<k json>(to_json(null)));
select * from dbt_jyeo.json_okay;
  1. Try to preview with dbt:
$ dbt show --inline "select * from dbt_jyeo.json_error"

22:18:25  Running with dbt=1.7.3
22:18:26  Registered adapter: bigquery=1.7.2
22:18:27  Found 0 sources, 0 exposures, 0 metrics, 447 macros, 0 groups, 0 semantic models
22:18:27  
22:18:27  Concurrency: 1 threads (target='bq')
22:18:27  
22:18:30  Unhandled error while executing 
the JSON object must be str, bytes or bytearray, not NoneType
22:18:30  Encountered an error:
Runtime Error
  the JSON object must be str, bytes or bytearray, not NoneType

$ dbt show --inline "select * from dbt_jyeo.json_okay"

22:18:54  Running with dbt=1.7.3
22:18:55  Registered adapter: bigquery=1.7.2
22:18:56  Found 0 sources, 0 exposures, 0 metrics, 447 macros, 0 groups, 0 semantic models
22:18:56  
22:18:56  Concurrency: 1 threads (target='bq')
22:18:56  
22:18:59  Previewing inline node:
| v               |
| --------------- |
| {"k": {"a": 1}} |
| {"k": null}     |
  1. Try previewing in BQ:

image

image

Notice the null in italic in the first screenshot.

So it depends how the null gets into the data - if it's on the outer struct level itself (i.e. the data is literally null) vs a null that is within a json object itself (i.e. the data is a json type of which the value is null) is when we run into this error.

Relevant log output

No response

Environment

- OS: macOS
- Python: Python 3.11.2
- dbt-core: 1.7.3
- dbt-bigquery: 1.7.2

Additional Context

Last time we ran into something similar (#972) - it was due to the underlying bigquery python client so wont surprise me if it's more of the same.

Potential workaround for now is to check if null and coerce it into to_json(null):

$ dbt show --inline "select ifnull(v.k, to_json(null)) from dbt_jyeo.json_error"
22:28:53  Running with dbt=1.7.3
22:28:54  Registered adapter: bigquery=1.7.2
22:28:55  Found 0 sources, 0 exposures, 0 metrics, 447 macros, 0 groups, 0 semantic models
22:28:55  
22:28:55  Concurrency: 1 threads (target='bq')
22:28:55  
22:28:58  Previewing inline node:
| f0_      |
| -------- |
| {"a": 1} |
|          |
@jeremyyeo jeremyyeo added bug Something isn't working triage labels Dec 12, 2023
@github-actions github-actions bot changed the title [Bug] Not able preview structs when the struct is null [ADAP-1073] [Bug] Not able preview structs when the struct is null Dec 12, 2023
@colin-rogers-dbt
Copy link
Contributor

Underlying issue is with bigquery python client: googleapis/python-bigquery#1500

@colin-rogers-dbt colin-rogers-dbt self-assigned this Dec 19, 2023
@dbeatty10 dbeatty10 removed the triage label Dec 20, 2023
@martynydbt martynydbt added the High Severity bug with significant impact that should be resolved in a reasonable timeframe label Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working High Severity bug with significant impact that should be resolved in a reasonable timeframe
Projects
None yet
Development

No branches or pull requests

5 participants