I'm currently using the Export Collections to BigQuery Firebase Extension.
This is a Firebase Function that periodically updates Firestore Collections to BigQuery.
This is great, but it seems to put Firestore Document Data into a "data" column inside BigQuery.
My question, how would I go about getting this JSON out of the data column into separate columns in BigQuery. Luckily my JSON/Firestore documents are not nested and are flat and I intend to keep it that way.
Any advice would be great. I'm aware of https://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions but am struggling to find the right SQL query to achieve this.
SELECT
JSON_EXTRACT(data, "$.user") AS user
FROM `firebase-project.firestore_export.name-of-firestore-collection`
is what I able to use to pull JSON from the data column and format it into different columns.
Thanks rtenha!
You should be able to use JSON_EXTRACT_SCALAR to "column-ize" your data.
with data as (select '{ "name" : "Jakob", "age" : "6" }' as my_json)
select
JSON_EXTRACT_SCALAR(my_json,'$.name') as name,
JSON_EXTRACT_SCALAR(my_json,'$.age') as age
from data
Consider keeping your firebase 'source' data as is, then create a view that parses the json to give you useable columns.
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