Skip to content

Commit d4fc959

Browse files
CorieWcabljac
authored andcommitted
fix(firestore-bigquery-change-tracker): keep partition value on delete using old data
1 parent ef43b25 commit d4fc959

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
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.41",
8+
"version": "1.1.42",
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/partitioning.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { FirestoreBigQueryEventHistoryTrackerConfig } from ".";
2-
import { FirestoreDocumentChangeEvent } from "..";
2+
import { ChangeType, FirestoreDocumentChangeEvent } from "..";
33
import * as firebase from "firebase-admin";
44

55
import * as logs from "../logs";
66
import * as bigquery from "@google-cloud/bigquery";
77
import * as functions from "firebase-functions";
88
import { getNewPartitionField } from "./schema";
99
import { BigQuery, TableMetadata } from "@google-cloud/bigquery";
10-
1110
import { PartitionFieldType } from "../types";
1211

1312
export class Partitioning {
@@ -195,11 +194,16 @@ export class Partitioning {
195194
Delete changes events have no data, return early as cannot partition on empty data.
196195
**/
197196
getPartitionValue(event: FirestoreDocumentChangeEvent) {
198-
if (!event.data) return {};
197+
// When old data is disabled and the operation is delete
198+
// the data and old data will be null
199+
if (event.data == null && event.oldData == null) return {};
199200

200201
const firestoreFieldName = this.config.timePartitioningFirestoreField;
201202
const fieldName = this.config.timePartitioningField;
202-
const fieldValue = event.data[firestoreFieldName];
203+
const fieldValue =
204+
event.operation === ChangeType.DELETE
205+
? event.oldData[firestoreFieldName]
206+
: event.data[firestoreFieldName];
203207

204208
if (!fieldName || !fieldValue) {
205209
return {};

0 commit comments

Comments
 (0)