Skip to content

fix(firestore-bigquery-export): fixed reference path #2437

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions firestore-bigquery-export/scripts/import/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ async function processDocuments(
// Apply partition boundaries from the serialized query
// These define the range of documents this worker should process
if (serializableQuery.startAt?.values?.[0]?.referenceValue) {
const startPath = serializableQuery.startAt.values[0].referenceValue;
query = query.startAt(firebase.firestore().doc(startPath));
// strip off the full resource name, keep only the part after "/documents/"
const resourceName = serializableQuery.startAt.values[0].referenceValue;
const relativePath = resourceName.split("/documents/")[1];
query = query.startAt(firebase.firestore().doc(relativePath));
}
if (serializableQuery.endAt?.values?.[0]?.referenceValue) {
const endPath = serializableQuery.endAt.values[0].referenceValue;
query = query.endBefore(firebase.firestore().doc(endPath));
// similarly strip to relative path
const resourceName = serializableQuery.endAt.values[0].referenceValue;
const relativePath = resourceName.split("/documents/")[1];
Comment on lines +54 to +60
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

If resourceName does not contain /documents/, split("/documents/")[1] will be undefined, causing doc(undefined) to fail. Consider validating the split result or using a more robust extraction (e.g., const idx = resourceName.indexOf('/documents/'); if (idx === -1) throw ...; const relativePath = resourceName.substring(idx + 11);).

Copilot uses AI. Check for mistakes.

Comment on lines 49 to +60
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] The logic to strip the /documents/ prefix is duplicated for startAt and endAt. Extract this into a helper function (e.g. getRelativePath(resourceName)) to reduce repetition and improve clarity.

Copilot uses AI. Check for mistakes.

query = query.endBefore(firebase.firestore().doc(relativePath));
}
if (serializableQuery.offset) {
query = query.offset(serializableQuery.offset);
Expand Down