Table to Storage: SQL file
Last updated
Last updated
To run a Table to Storage data operation, you first need to prepare a SQL query that will extract the data to export.
The SQL file must contain a BigQuery standard SQL query. You can write it directly in the BigQuery query editor and then save it into a .sql file.
This query will be executed when the data operation is launched, and the result will be stored in the JSON file specified in your configuration.
For a GBQ to Firestore data pipeline, you must at least select a firestore_path column
In order to use the Python script to load the data into Firestore, the SQL that extracts it must follow a specific pattern.
timestamp
type: timestamp
optional
For your different use cases, it can be interesting to have the last calculation date of your dataset to Firestore. This column is optional but recommanded.
firestore_path
type: string
mandatory
Variable read by the Python code to build the target path of documents and collections in Firestore. Each category and sub-category must be separated by a pipe "|". ⚠ Remember to remove the "|" that could be in the variables that are used as path names, or it would be interpreted as a category separator! ⚠ The Firestore path is a succession of collections and documents. You must at all costs end up on a collection of documents. The defined path must therefore contain an even number of categories and sub-categories. See a screenshot of an exemple below.
other variables
type: string
optional
The other variables are the ones you want to display in your firestore document.
You can define as many variable as you like, as described in the first example below.
We'll even see below how to create sub categories with the second example.
You will get a BigQuery Result like this:
And after loading it into Firestore (see next pages for the next steps), you create collections and documents as specified in the firestore_path column and get data like this in Firestore:
You can also create a list in the document using a "data" column, created using the BigQuery ARRAY_AGG(STRUCT()) functions.
data
type: struct of string or struct of struct of string
mandatory
Allows you to create a list of sub-elements that correspond N times to the element (for example for a product, you can create a list of sales sorted by date)
The SQL is more complex. Here is an example:
The result looks like this in Firestore: