Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the JSON data from the "Export Collections to BigQuery" firebase extension into row column format

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.

like image 490
Trevor Lazarus Avatar asked Jan 21 '26 03:01

Trevor Lazarus


2 Answers

    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!

like image 52
Trevor Lazarus Avatar answered Jan 23 '26 12:01

Trevor Lazarus


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.

like image 35
rtenha Avatar answered Jan 23 '26 12:01

rtenha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!