Commit c40e42f
authored
feat(firestore): pipeline subqueries (#14365)
**Overview**
This PR introduces support for pipeline subqueries, variable
definitions, and joins in the Go Firestore SDK, achieving strict 1:1
feature parity with the Java SDK's pipeline APIs
googleapis/java-firestore#2323.
**What are Subqueries?**
In Firestore pipelines, subqueries allow you to embed an entire pipeline
execution as a value within a single stage of an outer pipeline. This is
incredibly powerful for performing complex "join-like" operations across
different collections.
For example, while querying a restaurants collection, you can use a
subquery to fetch, filter, and aggregate all documents from a nested
reviews subcollection, and embed that aggregated result (e.g.,
average_rating) directly into the restaurant document being returned.
Subqueries can be
evaluated into either an array of results (ToArrayExpression()) or a
single scalar value (ToScalarExpression()).
**Key Features & API Additions:**
* **Subqueries (Joins):**
* Implemented the Subcollection(path string) package-level function to
instantiate relative-scope pipelines.
* Added ToScalarExpression() and ToArrayExpression() methods on Pipeline
to explicitly convert subqueries into expressions, allowing them to be
seamlessly embedded inside stages like AddFields and Where.
* **Variable Definition & References:**
* Introduced the Define pipeline stage and the AliasedExpressions
variadic helper to ergonomically bind values to variables.
* Added Variable("name") and CurrentDocument() top-level functions to
reference bound values in subsequent pipeline stages.
* **Field Access & Overloading:**
* Implemented GetField (accepting any to support both string and
Expression arguments, mirroring Java's method overloading).
**Type Safety & Defensive Constraints:**
* Strict Aliasing: Expression.As() now explicitly returns
*AliasedExpression (similar to Java:
https://github.com/googleapis/java-firestore/blob/0c8188520dfbada0d3fef0719e4f95fc231306be/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java#L6608-L6621)
rather than a generic Selectable interface, and the Define stage
strictly requires []*AliasedExpression.
* Pipeline Scope Validation: Added validation to ensure relative-scope
pipelines (e.g., those created via Subcollection) cannot be executed
directly or passed into a Union() stage. Attempts to do so now return
descriptive errors identical to the Java SDK's IllegalStateException and
IllegalArgumentException.1 parent 9886dcf commit c40e42f
9 files changed
Lines changed: 462 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| |||
227 | 229 | | |
228 | 230 | | |
229 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
230 | 241 | | |
231 | 242 | | |
232 | 243 | | |
| |||
242 | 253 | | |
243 | 254 | | |
244 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
245 | 265 | | |
246 | 266 | | |
247 | 267 | | |
| |||
877 | 897 | | |
878 | 898 | | |
879 | 899 | | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
880 | 904 | | |
881 | 905 | | |
882 | 906 | | |
| |||
913 | 937 | | |
914 | 938 | | |
915 | 939 | | |
916 | | - | |
| 940 | + | |
917 | 941 | | |
918 | 942 | | |
919 | 943 | | |
920 | | - | |
| 944 | + | |
921 | 945 | | |
922 | 946 | | |
923 | 947 | | |
924 | | - | |
| 948 | + | |
925 | 949 | | |
926 | 950 | | |
927 | 951 | | |
928 | | - | |
| 952 | + | |
929 | 953 | | |
930 | 954 | | |
931 | 955 | | |
| |||
941 | 965 | | |
942 | 966 | | |
943 | 967 | | |
944 | | - | |
| 968 | + | |
945 | 969 | | |
946 | 970 | | |
947 | 971 | | |
948 | 972 | | |
949 | | - | |
| 973 | + | |
950 | 974 | | |
951 | 975 | | |
952 | | - | |
| 976 | + | |
953 | 977 | | |
954 | 978 | | |
955 | 979 | | |
| |||
1242 | 1266 | | |
1243 | 1267 | | |
1244 | 1268 | | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
319 | 323 | | |
320 | 324 | | |
321 | 325 | | |
| |||
506 | 510 | | |
507 | 511 | | |
508 | 512 | | |
509 | | - | |
| 513 | + | |
510 | 514 | | |
511 | 515 | | |
512 | 516 | | |
| |||
645 | 649 | | |
646 | 650 | | |
647 | 651 | | |
| 652 | + | |
648 | 653 | | |
649 | 654 | | |
650 | 655 | | |
| |||
755 | 760 | | |
756 | 761 | | |
757 | 762 | | |
758 | | - | |
| 763 | + | |
759 | 764 | | |
760 | 765 | | |
761 | 766 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
394 | 405 | | |
395 | 406 | | |
396 | 407 | | |
397 | 408 | | |
398 | 409 | | |
399 | 410 | | |
400 | 411 | | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
401 | 428 | | |
402 | 429 | | |
403 | 430 | | |
| |||
912 | 939 | | |
913 | 940 | | |
914 | 941 | | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
915 | 952 | | |
916 | 953 | | |
917 | 954 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
0 commit comments