I have various highly nested json objects. I am wondering whether to store these as STRUCT
s in BigQuery or as a STRING
. If storing it as a string, then I can use JSON_EXTRACT
where necessary to get what I need. I have a few questions on using the following approach:
STRUCT
instead of a string give?Finally, I wasn't able to find any place in the documentation that gives examples of how to query STRUCT
s. The only place I could find was https://cloud.google.com/bigquery/docs/nested-repeated. Are there examples in the documentation (or elsewhere) on querying nested fields? Additionally, why is the term RECORD
and STRUCT
used interchangeably on this page?
Note that the json will not be repeated at the root level, i.e., it will look like {...}
and not [{...},{...}]
.
As a reference, in Redshift you would (as of this question) store json as a string and use the json-functions to manipulate it: https://stackoverflow.com/a/32731374/651174.
The other common way JSON data is stored in BigQuery is as STRING data type. For example: Storing nested data as plain string requires no pre-defined schema, but it will bring you headaches in the future:
You can load newline delimited JSON data from Cloud Storage into a new table or partition, or append to or overwrite an existing table or partition. When your data is loaded into BigQuery, it is converted into columnar format for Capacitor (BigQuery's storage format).
To change how BigQuery parses JSON data, specify additional options in the Cloud Console, the bq command-line tool, the API, or the client libraries. (Optional) The maximum number of bad records that BigQuery can ignore when running the job. If the number of bad records exceeds this value, an invalid error is returned in the job result.
Each JSON object must be on a separate line in the file. If you use gzip compression , BigQuery cannot read the data in parallel. Loading compressed JSON data into BigQuery is slower than loading uncompressed data.
I usually do both:
My 3 steps:
Then, in case of schema change:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With