Commit 18946f1
authored
Fspq fix stages (#14253)
Java stages for reference:
https://github.com/googleapis/java-firestore/blob/6e30a6c11efe5d428607bfd78f82ba7b49497bd9/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java
Node stages for reference:
https://github.com/googleapis/google-cloud-node/blob/c26967ca277fdab196ea94f5561e4f451ac1ec8a/handwritten/firestore/dev/src/pipelines/pipelines.ts
1. Java allows the user to pass in Fields into remove fields. E.g. user
can do in Java `.removeFields(field("published"), field("genre"),
field("nestedField"))` but in Go user cannot do
`RemoveFields(FieldOf("published"), FieldOf("genre"),
FieldOf("nestedField"))`. This PR fixes this by allowing FieldOf in
RemoveFields args
2. Change unnest signature to a more Go idiomatic one
1. Idiomatic Go Design: Replaced the struct pointer (*UnnestOptions)
with a variadic slice of interfaces (...UnnestOption). This standardizes
developer ergonomics and aligns with other areas of the Firestore Go
SDK.
2. Cleaner Zero-value Defaults: Callers are no longer forced to pass nil
if they don't wish to supply specific configuration arguments.
3. Better Hygeine & Robustness: Internal logic initializes default
underlying representations implicitly without requiring users to
instantiate or check nil pointer values.
3. Refactored the Sample stage
The changes to the sample stage from `SampleSpec` to `Sampler`, and
`SampleByDocuments` to `ByDocuments` were driven by idiomatic Go design
principles regarding readability and removing structural redundancy:
1. Reducing Stuttering in Code
In the previous API, calling a sample operation resulted in a redundant
"stutter" in the code:
```go
// Old Way: Read "Sample" "Sample By Documents"
pipeline.Sample(SampleByDocuments(10))
```
By removing the redundant "Sample" prefix in the builder function name,
the code now reads much more cleanly like a sentence
```go
// New Way: Read "Sample" "By Documents"
pipeline.Sample(ByDocuments(10))
```
2. Conciseness and Clarity
Renaming `SampleSpec` to `Sampler` represents idiomatic Go naming
conventions. Interfaces or types that perform a single conceptual action
or "sample" elements are standardly suffixed with `-er` (like `Reader`,
`Writer`, `Sampler`) rather than `-Spec`.
3. Exposing `ByPercentage` consistently
In addition to rewriting `SampleByDocuments` to `ByDocuments`, the new
API now cleanly supports `ByPercentage` directly too:
```go
// Old Way:
pipeline.Sample(&SampleSpec{Size: 0.6, Mode: SampleModePercent})
// New Way:
pipeline.Sample(ByPercentage(0.6))
```
This is much more expressive than forced instantiation for percentage
configurations.
5. Refactored the rawstage
The `RawStage` refactoring represents a significant shift from a builder
pattern (which is Java-idiomatic) to a direct method invocation with
variadic arguments (which is Go-idiomatic). Here is a detailed breakdown
of the rationale:
1. Removing Public API Bloat
In the previous implementation, `RawStage` was a publicly exported
struct (`type RawStage struct`). This forced the SDK to export a
constructor `NewRawStage()`, and builder methods like `WithArguments()`
and `WithOptions()`.
The new API makes `rawStage` internal (lowercase `r`). The user now
simply calls a direct method on the pipeline (`pipeline.RawStage(...)`).
There are no superfluous constructors or builder methods exposed on the
documentation surface.
2. Idiomatic Go (Direct Method Calls)
Go prefers passing configuring arguments directly into a method rather
than instantiating builder objects. Compare the old chained
instantiation against the new design:
Old Way (Java Builder style):
```go
client.Pipeline().Collection("books").
RawStage(
NewRawStage("limit").WithArguments(3),
)
```
New Way (Idiomatic Go):
```go
client.Pipeline().Collection("books").RawStage("limit", []any{3})
```
The new syntax is much shorter, easier to read, and accurately describes
the intent without boilerplate.
3. Streamlining Options with Variadics
The new method `RawStage(name string, args []any, opts
...RawStageOptions)` safely takes variadic pointers for options. If no
options are needed, the caller simply omits them. If they are needed,
they can supply any amount of `RawStageOptions` without calling unique
chain builders.
4. Architectural Alignment across the SDK
This aligns `RawStage` with the rest of the module's recent refactors
(shifting `SampleSpec` to `Sampler`, and `*UnnestOptions` to
`...UnnestOption`). It unifies the builder's syntax so developers
maintain a standard mental model when chained expressions are invoked.
6. Refactored the AddFields, RemoveFields and Select stages to expect at
least one arg similar to Java and Node1 parent 5bf0cf4 commit 18946f1
File tree
5 files changed
+124
-94
lines changed- firestore
5 files changed
+124
-94
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
| 326 | + | |
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
330 | | - | |
| 330 | + | |
| 331 | + | |
331 | 332 | | |
332 | 333 | | |
333 | 334 | | |
| |||
364 | 365 | | |
365 | 366 | | |
366 | 367 | | |
367 | | - | |
| 368 | + | |
368 | 369 | | |
369 | 370 | | |
370 | 371 | | |
371 | | - | |
| 372 | + | |
| 373 | + | |
372 | 374 | | |
373 | 375 | | |
374 | 376 | | |
| |||
377 | 379 | | |
378 | 380 | | |
379 | 381 | | |
| 382 | + | |
380 | 383 | | |
381 | 384 | | |
382 | 385 | | |
383 | | - | |
| 386 | + | |
384 | 387 | | |
385 | 388 | | |
386 | 389 | | |
387 | | - | |
| 390 | + | |
| 391 | + | |
388 | 392 | | |
389 | 393 | | |
390 | 394 | | |
| |||
487 | 491 | | |
488 | 492 | | |
489 | 493 | | |
490 | | - | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
491 | 500 | | |
492 | 501 | | |
493 | 502 | | |
494 | | - | |
495 | | - | |
496 | | - | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
497 | 539 | | |
498 | 540 | | |
499 | 541 | | |
| |||
504 | 546 | | |
505 | 547 | | |
506 | 548 | | |
507 | | - | |
| 549 | + | |
508 | 550 | | |
509 | 551 | | |
510 | 552 | | |
511 | | - | |
| 553 | + | |
| 554 | + | |
512 | 555 | | |
513 | 556 | | |
514 | 557 | | |
| |||
521 | 564 | | |
522 | 565 | | |
523 | 566 | | |
524 | | - | |
| 567 | + | |
525 | 568 | | |
526 | 569 | | |
527 | 570 | | |
| |||
533 | 576 | | |
534 | 577 | | |
535 | 578 | | |
536 | | - | |
| 579 | + | |
537 | 580 | | |
538 | 581 | | |
539 | 582 | | |
540 | | - | |
| 583 | + | |
| 584 | + | |
541 | 585 | | |
542 | 586 | | |
543 | 587 | | |
| |||
584 | 628 | | |
585 | 629 | | |
586 | 630 | | |
587 | | - | |
| 631 | + | |
588 | 632 | | |
589 | 633 | | |
590 | 634 | | |
591 | | - | |
| 635 | + | |
592 | 636 | | |
593 | 637 | | |
594 | 638 | | |
595 | 639 | | |
596 | | - | |
| 640 | + | |
597 | 641 | | |
598 | 642 | | |
599 | 643 | | |
600 | | - | |
601 | | - | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
602 | 654 | | |
603 | 655 | | |
604 | 656 | | |
605 | 657 | | |
606 | | - | |
607 | | - | |
| 658 | + | |
| 659 | + | |
608 | 660 | | |
609 | 661 | | |
610 | 662 | | |
611 | 663 | | |
612 | | - | |
| 664 | + | |
613 | 665 | | |
614 | 666 | | |
615 | | - | |
| 667 | + | |
616 | 668 | | |
617 | 669 | | |
618 | 670 | | |
619 | | - | |
| 671 | + | |
620 | 672 | | |
621 | 673 | | |
622 | 674 | | |
623 | | - | |
| 675 | + | |
624 | 676 | | |
625 | 677 | | |
626 | 678 | | |
| |||
709 | 761 | | |
710 | 762 | | |
711 | 763 | | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
| 764 | + | |
718 | 765 | | |
719 | 766 | | |
720 | 767 | | |
721 | 768 | | |
722 | | - | |
| 769 | + | |
723 | 770 | | |
724 | 771 | | |
725 | 772 | | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
726 | 789 | | |
727 | 790 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
502 | | - | |
| 502 | + | |
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
| |||
510 | 510 | | |
511 | 511 | | |
512 | 512 | | |
513 | | - | |
| 513 | + | |
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| |||
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
585 | | - | |
| 585 | + | |
586 | 586 | | |
587 | 587 | | |
588 | 588 | | |
| |||
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
607 | | - | |
| 607 | + | |
608 | 608 | | |
609 | 609 | | |
610 | 610 | | |
| |||
797 | 797 | | |
798 | 798 | | |
799 | 799 | | |
800 | | - | |
| 800 | + | |
801 | 801 | | |
802 | 802 | | |
803 | 803 | | |
| |||
0 commit comments