Skip to content

Commit d6e2938

Browse files
authored
Merge pull request #334 from FirebasePrivate/fz/bigquery-collection-group
Add TABLE_ID parameter to BigQuery export extension
2 parents 40710db + 01aa8c5 commit d6e2938

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

firestore-bigquery-export/POSTINSTALL.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ You can test out this extension right away:
1313
1. Query your **raw changelog table**, which should contain a single log of creating the `bigquery-mirror-test` document.
1414

1515
```
16-
SELECT * FROM `${param:PROJECT_ID}.${param:DATASET_ID}.${param:COLLECTION_PATH}_raw_changelog`
16+
SELECT * FROM `${param:PROJECT_ID}.${param:DATASET_ID}.${param:TABLE_ID}_raw_changelog`
1717
```
1818
1919
1. Query your **latest view**, which should return the latest change event for the only document present -- `bigquery-mirror-test`.
2020
2121
```
22-
SELECT * FROM `${param:PROJECT_ID}.${param:DATASET_ID}.${param:COLLECTION_PATH}_raw_latest`
22+
SELECT * FROM `${param:PROJECT_ID}.${param:DATASET_ID}.${param:TABLE_ID}_raw_latest`
2323
```
2424
2525
1. Delete the `bigquery-mirror-test` document from [Cloud Firestore](https://console.firebase.google.com/project/${param:PROJECT_ID}/database/firestore/data).
@@ -28,7 +28,7 @@ The `bigquery-mirror-test` document will disappear from the **latest view** and
2828
1. You can check the changelogs of a single document with this query:
2929
3030
```
31-
SELECT * FROM `${param:PROJECT_ID}.${param:DATASET_ID}.${param:COLLECTION_PATH}_raw_changelog`
31+
SELECT * FROM `${param:PROJECT_ID}.${param:DATASET_ID}.${param:TABLE_ID}_raw_changelog`
3232
WHERE document_name = "bigquery-mirror-test"
3333
ORDER BY TIMESTAMP ASC
3434
```
@@ -37,12 +37,12 @@ The `bigquery-mirror-test` document will disappear from the **latest view** and
3737
3838
Whenever a document is created, updated, imported, or deleted in the specified collection, this extension sends that update to BigQuery. You can then run queries on this mirrored dataset which contains the following resources:
3939
40-
+ **raw changelog table:** [`${param:DATASET_ID}_raw_changelog`](https://console.cloud.google.com/bigquery?project=${param:PROJECT_ID}&p=${param:PROJECT_ID}&d=${param:DATASET_ID}&t=${param:COLLECTION_PATH}_raw_changelog&page=table)
41-
+ **latest view:** [`${param:DATASET_ID}_raw_latest`](https://console.cloud.google.com/bigquery?project=${param:PROJECT_ID}&p=${param:PROJECT_ID}&d=${param:DATASET_ID}&t=${param:COLLECTION_PATH}_raw_latest&page=table)
40+
+ **raw changelog table:** [`${param:TABLE_ID}_raw_changelog`](https://console.cloud.google.com/bigquery?project=${param:PROJECT_ID}&p=${param:PROJECT_ID}&d=${param:DATASET_ID}&t=${param:TABLE_ID}_raw_changelog&page=table)
41+
+ **latest view:** [`${param:TABLE_ID}_raw_latest`](https://console.cloud.google.com/bigquery?project=${param:PROJECT_ID}&p=${param:PROJECT_ID}&d=${param:DATASET_ID}&t=${param:TABLE_ID}_raw_latest&page=table)
4242
4343
To review the schema for these two resources, click the **Schema** tab for each resource in BigQuery.
4444
45-
Note that this extension only listens for _document_ changes in the collection, but not changes in any _subcollection_. You can, though, install additional instances of this extension to specifically listen to a subcollection or other collections in your database.
45+
Note that this extension only listens for _document_ changes in the collection, but not changes in any _subcollection_. You can, though, install additional instances of this extension to specifically listen to a subcollection or other collections in your database. Or if you have the same subcollection across documents in a given collection, you can use `{wildcard}` notation to listen to all those subcollections (for example: `chats/{chatid}/posts`).
4646
4747
### _(Optional)_ Import existing documents
4848

firestore-bigquery-export/PREINSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The extension creates and updates a [dataset](https://cloud.google.com/bigquery/
77

88
Whenever a document is created, updated, deleted, or imported in the specified collection, this extension sends that update to BigQuery. You can then run queries on this mirrored dataset.
99

10-
Note that this extension only listens for _document_ changes in the collection, but not changes in any _subcollection_. You can, though, install additional instances of this extension to specifically listen to a subcollection or other collections in your database.
10+
Note that this extension only listens for _document_ changes in the collection, but not changes in any _subcollection_. You can, though, install additional instances of this extension to specifically listen to a subcollection or other collections in your database. Or if you have the same subcollection across documents in a given collection, you can use `{wildcard}` notation to listen to all those subcollections (for example: `chats/{chatid}/posts`).
1111

1212
### Additional setup
1313

firestore-bigquery-export/extension.yaml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ params:
8585
type: string
8686
label: Collection path
8787
description: >-
88-
What is the path of the the collection that you would like to export?
89-
default: extensions
90-
example: extensions
88+
What is the path of the collection that you would like to export?
89+
You may use `{wildcard}` notation to match a subcollection of all documents in a collection
90+
(for example: `chatrooms/{chatid}/posts`).
91+
default: posts
92+
example: posts
9193
validationRegex: "^[^/]+(/[^/]+/[^/]+)*$"
9294
validationErrorMessage: Must be a valid Cloud Firestore collection
9395
required: true
@@ -98,10 +100,25 @@ params:
98100
description: >-
99101
What ID would you like to use for your BigQuery dataset? This
100102
extension will create the dataset, if it doesn't already exist.
101-
validationRegex: ^[a-zA-Z0-9_]+$
103+
validationRegex: "^[a-zA-Z0-9_]+$"
102104
validationErrorMessage: >
103-
Dataset IDs must be alphanumeric (plus underscores) and must be no more than
105+
BigQuery dataset IDs must be alphanumeric (plus underscores) and must be no more than
104106
1024 characters.
105-
default: exported_collection
106-
example: exported_collection
107+
default: firestore_export
108+
example: firestore_export
109+
required: true
110+
111+
- param: TABLE_ID
112+
type: string
113+
label: Table ID
114+
description: >-
115+
What identifying prefix would you like to use for your table and view
116+
inside your BigQuery dataset? This extension will create the table and view,
117+
if they don't already exist.
118+
validationRegex: "^[a-zA-Z0-9_]+$"
119+
validationErrorMessage: >
120+
BigQuery table IDs must be alphanumeric (plus underscores) and must be no more than
121+
1024 characters.
122+
default: posts
123+
example: posts
107124
required: true

firestore-bigquery-export/functions/lib/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1818
exports.default = {
1919
collectionPath: process.env.COLLECTION_PATH,
2020
datasetId: process.env.DATASET_ID,
21+
tableId: process.env.TABLE_ID,
2122
location: process.env.LOCATION,
2223
initialized: false
2324
};

firestore-bigquery-export/functions/lib/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ const functions = require("firebase-functions");
2929
const firestore_bigquery_change_tracker_1 = require("@firebaseextensions/firestore-bigquery-change-tracker");
3030
const logs = require("./logs");
3131
const util_1 = require("./util");
32-
const eventTracker = new firestore_bigquery_change_tracker_1.FirestoreBigQueryEventHistoryTracker(config_1.default);
32+
const eventTracker = new firestore_bigquery_change_tracker_1.FirestoreBigQueryEventHistoryTracker({
33+
collectionPath: config_1.default.tableId,
34+
datasetId: config_1.default.datasetId,
35+
initialized: false,
36+
suppressWarnings: false,
37+
});
3338
logs.init();
3439
exports.fsexportbigquery = functions.handler.firestore.document.onWrite((change, context) => __awaiter(void 0, void 0, void 0, function* () {
3540
logs.start();

firestore-bigquery-export/functions/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
export default {
1818
collectionPath: process.env.COLLECTION_PATH,
1919
datasetId: process.env.DATASET_ID,
20+
tableId: process.env.TABLE_ID,
2021
location: process.env.LOCATION,
2122
initialized: false
2223
};

firestore-bigquery-export/functions/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import {
2424
import * as logs from "./logs";
2525
import { getChangeType } from "./util";
2626

27-
const eventTracker: FirestoreEventHistoryTracker = new FirestoreBigQueryEventHistoryTracker(config);
27+
const eventTracker: FirestoreEventHistoryTracker = new FirestoreBigQueryEventHistoryTracker({
28+
collectionPath: config.tableId, // TODO: rename collectionPath.
29+
datasetId: config.datasetId,
30+
initialized: false, // TODO: Remove this config.
31+
suppressWarnings: false, // TODO: Remove this config.
32+
});
2833

2934
logs.init();
3035

0 commit comments

Comments
 (0)