简体   繁体   English

将来自“Export Collections to BigQuery”firebase 扩展的 JSON 数据转换为行列格式

[英]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.我目前正在使用将Export Collections to BigQuery Firebase 扩展。

This is a Firebase Function that periodically updates Firestore Collections to BigQuery.这是一个 Firebase 函数,它会定期将 Firestore 集合更新为 BigQuery。

This is great, but it seems to put Firestore Document Data into a "data" column inside BigQuery.这很棒,但似乎将 Firestore 文档数据放入 BigQuery 内的“数据”列中。

My question, how would I go about getting this JSON out of the data column into separate columns in BigQuery.我的问题是,我将如何将这个 JSON 从数据列中提取到 BigQuery 中的单独列中。 Luckily my JSON/Firestore documents are not nested and are flat and I intend to keep it that way.幸运的是,我的 JSON/Firestore 文档不是嵌套的并且是扁平的,我打算保持这种状态。

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.我知道https://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions但我正在努力寻找正确的 SQL 查询来实现这一点。

    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.是我能够用来从数据列中提取 JSON 并将其格式化为不同列的方法。

Thanks rtenha!谢谢你!

You should be able to use JSON_EXTRACT_SCALAR to "column-ize" your data.您应该能够使用JSON_EXTRACT_SCALAR来“列化”您的数据。

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.考虑按原样保留您的 firebase '源' 数据,然后创建一个视图来解析 json 以提供可用的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM