Skip to content

feat(firestore): refactor pipeline API for uniform stage options#14322

Open
bhshkh wants to merge 3 commits intogoogleapis:mainfrom
bhshkh:feat/fspq-stage-options
Open

feat(firestore): refactor pipeline API for uniform stage options#14322
bhshkh wants to merge 3 commits intogoogleapis:mainfrom
bhshkh:feat/fspq-stage-options

Conversation

@bhshkh
Copy link
Copy Markdown
Contributor

@bhshkh bhshkh commented Apr 1, 2026

Design decision here

Overview
This PR standardizes the API surface for the Firestore Pipeline builder in the Go SDK, ensuring idiomatic conformance and aligning closely with cross-platform design paradigms (Java/Node.js). It replaces complex stage-specific configuration structs with a universal functional option pattern and introduces typed slice constants for varied expressions.

Key Features and API Changes:

  • Universal RawOptions Escape Hatch:
    Introduced RawOptions to serve as a universal pass-through for backend options that might not be natively modeled by the Go SDK (e.g., RawOptions{"limit": 5, "distance_field": "dist"}). This deprecates intermediate parameter structs like PipelineFindNearestOptions across pipeline stages.

  • Standardized Variadic Arguments with Slices:
    Methods that formerly relied on raw variadic argument unpacking (e.g. ...Ordering, ...any) have been updated to accept typed slices. To preserve clean query ergonomics, we introduced domain-specific helper constructors (Orders(), Fields(), Accumulators(), Selectables()).

    • Pipeline.Sort(Orders(Ascending(FieldOf("f")), Descending(FieldOf("__name__"))))
    • Pipeline.Aggregate(Accumulators(Count(DocumentID).As("total")))
    • Pipeline.Select(Fields("a", "b"))
  • Functional Stage Options Migration:
    Implemented standard functional options for specialized stage modifiers:

    • WithFindNearestLimit(), WithFindNearestDistanceField()
    • WithAggregateGroups()
    • WithUnnestIndexField()
    • WithExplainMode()

Internal Code Simplification & Testing:

  • Flattened Stage Hierarchy (baseStage removal):
    Removed the baseStage struct embedding across our internal pipeline stages. We replaced it with explicit options map[string]any fields within each stage and introduced a shared stageOptionsToProto(options) helper. This simplifies the internal struct hierarchy, removes opaque state inherited from struct embedding, and makes configuration serialization significantly more explicit and easier to trace inside each stage's toProto() implementation.
  • Pipeline Stage Proto Parsing:
    Refactored internal pipelineStage structures (newAggregateStage, newFindNearestStage, newSortStage, etc.) to reliably map the new RawOptions down to standard *pb.Value payloads.
  • Tests for AlwaysUseImplicitOrderBy:
    Added dedicated test cases (TestQuery_AlwaysUseImplicitOrderBy) to explicitly verify the behavior of the existing WithAlwaysUseImplicitOrderBy client toggle, ensuring it appropriately serializes implicit inequality fields and __name__ into the OrderBy proto requests.
  • Integration Suite Migration:
    Fully migrated the integration suite inside pipeline_integration_test.go and pipeline_test.go to assert against the newly stabilized RawOptions and slice-builder interfaces.

@bhshkh bhshkh requested review from a team as code owners April 1, 2026 16:17
@product-auto-label product-auto-label bot added the api: firestore Issues related to the Firestore API. label Apr 1, 2026
@bhshkh bhshkh enabled auto-merge (squash) April 1, 2026 16:19
@bhshkh bhshkh disabled auto-merge April 1, 2026 16:19
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Firestore Pipeline API by replacing specific settings structs with a unified options pattern using map[string]any and the StageOption interface. The changes involve updating method signatures for various pipeline stages and adding ergonomic helper functions like Fields and Accumulators. Review feedback highlights concerns regarding the integration tests, specifically the skipping of failing functional tests and the presence of commented-out test cases for features like MapKeys and ArrayFilter. These issues should be addressed to ensure the refactoring does not introduce regressions or leave the codebase with undocumented gaps in feature support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: firestore Issues related to the Firestore API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant