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

Conversation

CorieW
Copy link
Member

@CorieW CorieW commented May 16, 2025

Resolves #2303

  • Tested

@CorieW CorieW force-pushed the @invertase/bqe-time-partition-fix branch from 96b6af6 to 17fb4e9 Compare May 16, 2025 00:32
@cabljac cabljac requested a review from Copilot May 16, 2025 08:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the partitioning logic to retain the partition value on delete events by sourcing it from the old data rather than the new event data.

  • Uses the new ChangeType import to differentiate between DELETE and non-DELETE events.
  • Applies a conditional to select the appropriate field value for partitioning.
Comments suppressed due to low confidence (1)

firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/partitioning.ts:202

  • [nitpick] Consider adding an inline comment explaining why event.oldData is used for DELETE events. This will improve clarity and maintainability for future developers.
event.operation === ChangeType.DELETE ? event.oldData[firestoreFieldName] : event.data[firestoreFieldName];

@CorieW CorieW force-pushed the @invertase/bqe-time-partition-fix branch 3 times, most recently from 687952e to ee64adf Compare May 18, 2025 23:30
@CorieW CorieW marked this pull request as ready for review May 18, 2025 23:31
@cabljac cabljac requested a review from Copilot May 19, 2025 08:43
Copy link
Contributor

@cabljac cabljac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm as a fix, we will need to bump the change tracker package version?

@github-project-automation github-project-automation bot moved this to Changes Requested [PR] in [Cloud] Extensions + Functions May 19, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that when a Firestore delete event occurs without new data, the BigQuery partition value is derived from the old data.

  • Imports ChangeType and updates getPartitionValue to use oldData for delete operations.
  • Adds a guard to early return when both data and oldData are null.
  • Adjusts the fieldValue assignment based on the event’s operation.
Comments suppressed due to low confidence (2)

firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/partitioning.ts:209

  • Using !fieldValue treats any falsy value (e.g., 0) as missing. If the partition field might legitimately be falsy, use a nullish check (fieldValue == null) instead.
if (!fieldName || !fieldValue) {

firestore-bigquery-export/firestore-bigquery-change-tracker/src/bigquery/partitioning.ts:196

  • Add a unit test for the delete path to verify that the partition value is correctly pulled from oldData when event.data is null.
getPartitionValue(event: FirestoreDocumentChangeEvent) {

@CorieW CorieW force-pushed the @invertase/bqe-time-partition-fix branch from ee64adf to 71229e3 Compare May 19, 2025 08:52
@CorieW CorieW requested a review from a team as a code owner May 19, 2025 08:52
Copy link
Contributor

@cabljac cabljac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@github-project-automation github-project-automation bot moved this from Changes Requested [PR] to Approved [PR] in [Cloud] Extensions + Functions May 19, 2025
@cabljac cabljac merged commit d4fc959 into next May 19, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [firestore-bigquery-export] Time unit partition field not assigned in BQ for delete operations
2 participants