Skip to content

Commit 2173383

Browse files
committed
refactor: improve partitioning code
1 parent a17bc14 commit 2173383

File tree

8 files changed

+409
-417
lines changed

8 files changed

+409
-417
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.42",
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 & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,9 @@ import { initializeLatestView } from "./initializeLatestView";
4444
import { logger, LogLevel } from "../logger";
4545

4646
export { RawChangelogSchema, RawChangelogViewSchema } from "./schema";
47-
48-
export interface FirestoreBigQueryEventHistoryTrackerConfig {
49-
datasetId: string;
50-
tableId: string;
51-
firestoreInstanceId?: 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-
useMaterializedView?: boolean;
67-
useIncrementalMaterializedView?: boolean;
68-
maxStaleness?: string;
69-
refreshIntervalMinutes?: number;
70-
logLevel?: LogLevel | string;
71-
}
47+
import type { Config } from "./types";
48+
import { PartitioningConfig } from "./partitioning/config";
49+
export type { Config } from "./types";
7250

7351
/**
7452
* An FirestoreEventHistoryTracker that exports data to BigQuery.
@@ -85,12 +63,15 @@ export class FirestoreBigQueryEventHistoryTracker
8563
{
8664
bq: bigquery.BigQuery;
8765
_initialized: boolean = false;
66+
partitioningConfig: PartitioningConfig;
8867

89-
constructor(public config: FirestoreBigQueryEventHistoryTrackerConfig) {
68+
constructor(public config: Config) {
9069
this.bq = new bigquery.BigQuery();
9170

9271
this.bq.projectId = config.bqProjectId || process.env.PROJECT_ID;
9372

73+
this.partitioningConfig = new PartitioningConfig(this.config.partitioning);
74+
9475
if (!this.config.datasetLocation) {
9576
this.config.datasetLocation = "us";
9677
}
@@ -106,7 +87,7 @@ export class FirestoreBigQueryEventHistoryTracker
10687
await this.initialize();
10788
}
10889

109-
const partitionHandler = new Partitioning(this.config);
90+
const partitionHandler = new Partitioning(this.partitioningConfig);
11091

11192
const rows = events.map((event) => {
11293
const partitionValue = partitionHandler.getPartitionValue(event);
@@ -348,7 +329,7 @@ export class FirestoreBigQueryEventHistoryTracker
348329
const dataset = this.bigqueryDataset();
349330
const table = dataset.table(changelogName);
350331
const [tableExists] = await table.exists();
351-
const partitioning = new Partitioning(this.config, table);
332+
const partitioning = new Partitioning(this.partitioningConfig, table);
352333
const clustering = new Clustering(this.config, table);
353334

354335
if (tableExists) {

0 commit comments

Comments
 (0)