Skip to content

fix(firestore-bigquery-change-tracker): keep partition value on delete using old data #2424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "github.com/firebase/extensions.git",
"directory": "firestore-bigquery-export/firestore-bigquery-change-tracker"
},
"version": "1.1.41",
"version": "1.1.42",
"description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
"main": "./lib/index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { FirestoreBigQueryEventHistoryTrackerConfig } from ".";
import { FirestoreDocumentChangeEvent } from "..";
import { ChangeType, FirestoreDocumentChangeEvent } from "..";
import * as firebase from "firebase-admin";

import * as logs from "../logs";
import * as bigquery from "@google-cloud/bigquery";
import * as functions from "firebase-functions";
import { getNewPartitionField } from "./schema";
import { BigQuery, TableMetadata } from "@google-cloud/bigquery";

import { PartitionFieldType } from "../types";

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

const firestoreFieldName = this.config.timePartitioningFirestoreField;
const fieldName = this.config.timePartitioningField;
const fieldValue = event.data[firestoreFieldName];
const fieldValue =
event.operation === ChangeType.DELETE
? event.oldData[firestoreFieldName]
: event.data[firestoreFieldName];

if (!fieldName || !fieldValue) {
return {};
Expand Down
Loading