Skip to content

Commit c2e01b4

Browse files
committed
refactor: improve partitioning code
1 parent ed34bd6 commit c2e01b4

File tree

8 files changed

+409
-408
lines changed

8 files changed

+409
-408
lines changed

firestore-bigquery-export/firestore-bigquery-change-tracker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "github.com/firebase/extensions.git",
66
"directory": "firestore-bigquery-export/firestore-bigquery-change-tracker"
77
},
8-
"version": "1.1.38",
8+
"version": "2.0.0",
99
"description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
1010
"main": "./lib/index.js",
1111
"scripts": {

firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/index.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import * as admin from "firebase-admin";
1716
import * as bigquery from "@google-cloud/bigquery";
1817
import { DocumentReference } from "firebase-admin/firestore";
1918
import * as traverse from "traverse";
@@ -45,25 +44,9 @@ import { tableRequiresUpdate, viewRequiresUpdate } from "./checkUpdates";
4544
import { parseErrorMessage, waitForInitialization } from "./utils";
4645

4746
export { RawChangelogSchema, RawChangelogViewSchema } from "./schema";
48-
49-
export interface FirestoreBigQueryEventHistoryTrackerConfig {
50-
datasetId: string;
51-
tableId: string;
52-
datasetLocation?: string | undefined;
53-
transformFunction?: string | undefined;
54-
timePartitioning?: string | undefined;
55-
timePartitioningField?: string | undefined;
56-
timePartitioningFieldType?: string | undefined;
57-
timePartitioningFirestoreField?: string | undefined;
58-
clustering: string[] | null;
59-
databaseId?: string | undefined;
60-
wildcardIds?: boolean;
61-
bqProjectId?: string | undefined;
62-
backupTableId?: string | undefined;
63-
useNewSnapshotQuerySyntax?: boolean;
64-
skipInit?: boolean;
65-
kmsKeyName?: string | undefined;
66-
}
47+
import type { Config } from "./types";
48+
import { PartitioningConfig } from "./partitioning/config";
49+
export type { Config } from "./types";
6750

6851
/**
6952
* An FirestoreEventHistoryTracker that exports data to BigQuery.
@@ -80,12 +63,15 @@ export class FirestoreBigQueryEventHistoryTracker
8063
{
8164
bq: bigquery.BigQuery;
8265
_initialized: boolean = false;
66+
partitioningConfig: PartitioningConfig;
8367

84-
constructor(public config: FirestoreBigQueryEventHistoryTrackerConfig) {
68+
constructor(public config: Config) {
8569
this.bq = new bigquery.BigQuery();
8670

8771
this.bq.projectId = config.bqProjectId || process.env.PROJECT_ID;
8872

73+
this.partitioningConfig = new PartitioningConfig(this.config.partitioning);
74+
8975
if (!this.config.datasetLocation) {
9076
this.config.datasetLocation = "us";
9177
}
@@ -96,7 +82,7 @@ export class FirestoreBigQueryEventHistoryTracker
9682
await this.initialize();
9783
}
9884

99-
const partitionHandler = new Partitioning(this.config);
85+
const partitionHandler = new Partitioning(this.partitioningConfig);
10086

10187
const rows = events.map((event) => {
10288
const partitionValue = partitionHandler.getPartitionValue(event);
@@ -327,7 +313,7 @@ export class FirestoreBigQueryEventHistoryTracker
327313
const dataset = this.bigqueryDataset();
328314
const table = dataset.table(changelogName);
329315
const [tableExists] = await table.exists();
330-
const partitioning = new Partitioning(this.config, table);
316+
const partitioning = new Partitioning(this.partitioningConfig, table);
331317
const clustering = new Clustering(this.config, table);
332318

333319
if (tableExists) {

0 commit comments

Comments
 (0)