2525import static com .google .firebase .firestore .pipeline .Function .euclideanDistance ;
2626import static com .google .firebase .firestore .pipeline .Function .gt ;
2727import static com .google .firebase .firestore .pipeline .Function .logicalMax ;
28- import static com .google .firebase .firestore .pipeline .Function .logicalMin ;
2928import static com .google .firebase .firestore .pipeline .Function .lt ;
3029import static com .google .firebase .firestore .pipeline .Function .lte ;
3130import static com .google .firebase .firestore .pipeline .Function .mapGet ;
@@ -227,7 +226,7 @@ public void aggregateResultsCountAll() {
227226 firestore
228227 .pipeline ()
229228 .collection (randomCol )
230- .aggregate (AggregateExpr .countAll ().as ("count" ))
229+ .aggregate (AggregateExpr .countAll ().alias ("count" ))
231230 .execute ();
232231 assertThat (waitFor (execute ).getResults ())
233232 .comparingElementsUsing (DATA_CORRESPONDENCE )
@@ -243,9 +242,9 @@ public void aggregateResultsMany() {
243242 .collection (randomCol )
244243 .where (Function .eq ("genre" , "Science Fiction" ))
245244 .aggregate (
246- AggregateExpr .countAll ().as ("count" ),
247- AggregateExpr .avg ("rating" ).as ("avgRating" ),
248- Field .of ("rating" ).max ().as ("maxRating" ))
245+ AggregateExpr .countAll ().alias ("count" ),
246+ AggregateExpr .avg ("rating" ).alias ("avgRating" ),
247+ Field .of ("rating" ).max ().alias ("maxRating" ))
249248 .execute ();
250249 assertThat (waitFor (execute ).getResults ())
251250 .comparingElementsUsing (DATA_CORRESPONDENCE )
@@ -261,7 +260,7 @@ public void groupAndAccumulateResults() {
261260 .collection (randomCol )
262261 .where (lt (Field .of ("published" ), 1984 ))
263262 .aggregate (
264- AggregateStage .withAccumulators (AggregateExpr .avg ("rating" ).as ("avgRating" ))
263+ AggregateStage .withAccumulators (AggregateExpr .avg ("rating" ).alias ("avgRating" ))
265264 .withGroups ("genre" ))
266265 .where (gt ("avgRating" , 4.3 ))
267266 .sort (Field .of ("avgRating" ).descending ())
@@ -304,9 +303,9 @@ public void minAndMaxAccumulations() {
304303 .pipeline ()
305304 .collection (randomCol )
306305 .aggregate (
307- AggregateExpr .countAll ().as ("count" ),
308- Field .of ("rating" ).max ().as ("maxRating" ),
309- Field .of ("published" ).min ().as ("minPublished" ))
306+ AggregateExpr .countAll ().alias ("count" ),
307+ Field .of ("rating" ).max ().alias ("maxRating" ),
308+ Field .of ("published" ).min ().alias ("minPublished" ))
310309 .execute ();
311310 assertThat (waitFor (execute ).getResults ())
312311 .comparingElementsUsing (DATA_CORRESPONDENCE )
@@ -443,9 +442,10 @@ public void arrayContainsAllWorks() {
443442 @ Test
444443 public void arrayLengthWorks () {
445444 Task <PipelineSnapshot > execute =
446- randomCol
445+ firestore
447446 .pipeline ()
448- .select (Field .of ("tags" ).arrayLength ().as ("tagsCount" ))
447+ .collection (randomCol )
448+ .select (Field .of ("tags" ).arrayLength ().alias ("tagsCount" ))
449449 .where (eq ("tagsCount" , 3 ))
450450 .execute ();
451451 assertThat (waitFor (execute ).getResults ()).hasSize (10 );
@@ -462,7 +462,7 @@ public void arrayConcatWorks() {
462462 .select (
463463 Field .of ("tags" )
464464 .arrayConcat (ImmutableList .of ("newTag1" , "newTag2" ))
465- .as ("modifiedTags" ))
465+ .alias ("modifiedTags" ))
466466 .limit (1 )
467467 .execute ();
468468 assertThat (waitFor (execute ).getResults ())
@@ -476,9 +476,10 @@ public void arrayConcatWorks() {
476476 @ Test
477477 public void testStrConcat () {
478478 Task <PipelineSnapshot > execute =
479- randomCol
479+ firestore
480480 .pipeline ()
481- .select (Field .of ("author" ).strConcat (" - " , Field .of ("title" )).as ("bookInfo" ))
481+ .collection (randomCol )
482+ .select (Field .of ("author" ).strConcat (" - " , Field .of ("title" )).alias ("bookInfo" ))
482483 .limit (1 )
483484 .execute ();
484485 assertThat (waitFor (execute ).getResults ())
@@ -490,8 +491,9 @@ public void testStrConcat() {
490491 @ Test
491492 public void testStartsWith () {
492493 Task <PipelineSnapshot > execute =
493- randomCol
494+ firestore
494495 .pipeline ()
496+ .collection (randomCol )
495497 .where (startsWith ("title" , "The" ))
496498 .select ("title" )
497499 .sort (Field .of ("title" ).ascending ())
@@ -508,8 +510,9 @@ public void testStartsWith() {
508510 @ Test
509511 public void testEndsWith () {
510512 Task <PipelineSnapshot > execute =
511- randomCol
513+ firestore
512514 .pipeline ()
515+ .collection (randomCol )
513516 .where (endsWith ("title" , "y" ))
514517 .select ("title" )
515518 .sort (Field .of ("title" ).descending ())
@@ -524,9 +527,10 @@ public void testEndsWith() {
524527 @ Test
525528 public void testLength () {
526529 Task <PipelineSnapshot > execute =
527- randomCol
530+ firestore
528531 .pipeline ()
529- .select (Field .of ("title" ).charLength ().as ("titleLength" ), Field .of ("title" ))
532+ .collection (randomCol )
533+ .select (Field .of ("title" ).charLength ().alias ("titleLength" ), Field .of ("title" ))
530534 .where (gt ("titleLength" , 20 ))
531535 .sort (Field .of ("title" ).ascending ())
532536 .execute ();
@@ -543,9 +547,10 @@ public void testLength() {
543547 @ Ignore ("Not supported yet" )
544548 public void testToLowercase () {
545549 Task <PipelineSnapshot > execute =
546- randomCol
550+ firestore
547551 .pipeline ()
548- .select (Field .of ("title" ).toLower ().as ("lowercaseTitle" ))
552+ .collection (randomCol )
553+ .select (Field .of ("title" ).toLower ().alias ("lowercaseTitle" ))
549554 .limit (1 )
550555 .execute ();
551556 assertThat (waitFor (execute ).getResults ())
@@ -557,9 +562,10 @@ public void testToLowercase() {
557562 @ Ignore ("Not supported yet" )
558563 public void testToUppercase () {
559564 Task <PipelineSnapshot > execute =
560- randomCol
565+ firestore
561566 .pipeline ()
562- .select (Field .of ("author" ).toLower ().as ("uppercaseAuthor" ))
567+ .collection (randomCol )
568+ .select (Field .of ("author" ).toLower ().alias ("uppercaseAuthor" ))
563569 .limit (1 )
564570 .execute ();
565571 assertThat (waitFor (execute ).getResults ())
@@ -571,10 +577,11 @@ public void testToUppercase() {
571577 @ Ignore ("Not supported yet" )
572578 public void testTrim () {
573579 Task <PipelineSnapshot > execute =
574- randomCol
580+ firestore
575581 .pipeline ()
576- .addFields (strConcat (" " , Field .of ("title" ), " " ).as ("spacedTitle" ))
577- .select (Field .of ("spacedTitle" ).trim ().as ("trimmedTitle" ))
582+ .collection (randomCol )
583+ .addFields (strConcat (" " , Field .of ("title" ), " " ).alias ("spacedTitle" ))
584+ .select (Field .of ("spacedTitle" ).trim ().alias ("trimmedTitle" ))
578585 .limit (1 )
579586 .execute ();
580587 assertThat (waitFor (execute ).getResults ())
@@ -590,7 +597,12 @@ public void testTrim() {
590597 @ Test
591598 public void testLike () {
592599 Task <PipelineSnapshot > execute =
593- randomCol .pipeline ().where (Function .like ("title" , "%Guide%" )).select ("title" ).execute ();
600+ firestore
601+ .pipeline ()
602+ .collection (randomCol )
603+ .where (Function .like ("title" , "%Guide%" ))
604+ .select ("title" )
605+ .execute ();
594606 assertThat (waitFor (execute ).getResults ())
595607 .comparingElementsUsing (DATA_CORRESPONDENCE )
596608 .containsExactly (ImmutableMap .of ("title" , "The Hitchhiker's Guide to the Galaxy" ));
@@ -599,27 +611,36 @@ public void testLike() {
599611 @ Test
600612 public void testRegexContains () {
601613 Task <PipelineSnapshot > execute =
602- randomCol .pipeline ().where (Function .regexContains ("title" , "(?i)(the|of)" )).execute ();
614+ firestore
615+ .pipeline ()
616+ .collection (randomCol )
617+ .where (Function .regexContains ("title" , "(?i)(the|of)" ))
618+ .execute ();
603619 assertThat (waitFor (execute ).getResults ()).hasSize (5 );
604620 }
605621
606622 @ Test
607623 public void testRegexMatches () {
608624 Task <PipelineSnapshot > execute =
609- randomCol .pipeline ().where (Function .regexContains ("title" , ".*(?i)(the|of).*" )).execute ();
625+ firestore
626+ .pipeline ()
627+ .collection (randomCol )
628+ .where (Function .regexContains ("title" , ".*(?i)(the|of).*" ))
629+ .execute ();
610630 assertThat (waitFor (execute ).getResults ()).hasSize (5 );
611631 }
612632
613633 @ Test
614634 public void testArithmeticOperations () {
615635 Task <PipelineSnapshot > execute =
616- randomCol
636+ firestore
617637 .pipeline ()
638+ .collection (randomCol )
618639 .select (
619- add (Field .of ("rating" ), 1 ).as ("ratingPlusOne" ),
620- subtract (Field .of ("published" ), 1900 ).as ("yearsSince1900" ),
621- Field .of ("rating" ).multiply (10 ).as ("ratingTimesTen" ),
622- Field .of ("rating" ).divide (2 ).as ("ratingDividedByTwo" ))
640+ add (Field .of ("rating" ), 1 ).alias ("ratingPlusOne" ),
641+ subtract (Field .of ("published" ), 1900 ).alias ("yearsSince1900" ),
642+ Field .of ("rating" ).multiply (10 ).alias ("ratingTimesTen" ),
643+ Field .of ("rating" ).divide (2 ).alias ("ratingDividedByTwo" ))
623644 .limit (1 )
624645 .execute ();
625646 assertThat (waitFor (execute ).getResults ())
@@ -635,8 +656,9 @@ public void testArithmeticOperations() {
635656 @ Test
636657 public void testComparisonOperators () {
637658 Task <PipelineSnapshot > execute =
638- randomCol
659+ firestore
639660 .pipeline ()
661+ .collection (randomCol )
640662 .where (
641663 and (
642664 gt ("rating" , 4.2 ),
@@ -656,8 +678,9 @@ public void testComparisonOperators() {
656678 @ Test
657679 public void testLogicalOperators () {
658680 Task <PipelineSnapshot > execute =
659- randomCol
681+ firestore
660682 .pipeline ()
683+ .collection (randomCol )
661684 .where (
662685 or (
663686 and (gt ("rating" , 4.5 ), eq ("genre" , "Science Fiction" )),
@@ -676,13 +699,14 @@ public void testLogicalOperators() {
676699 @ Test
677700 public void testChecks () {
678701 Task <PipelineSnapshot > execute =
679- randomCol
702+ firestore
680703 .pipeline ()
704+ .collection (randomCol )
681705 .where (not (Field .of ("rating" ).isNan ()))
682706 .select (
683- Field .of ("rating" ).isNull ().as ("ratingIsNull" ),
684- Field .of ("rating" ).eq (Constant .nullValue ()).as ("ratingEqNull" ),
685- not (Field .of ("rating" ).isNan ()).as ("ratingIsNotNan" ))
707+ Field .of ("rating" ).isNull ().alias ("ratingIsNull" ),
708+ Field .of ("rating" ).eq (Constant .nullValue ()).alias ("ratingEqNull" ),
709+ not (Field .of ("rating" ).isNan ()).alias ("ratingIsNotNan" ))
686710 .limit (1 )
687711 .execute ();
688712 assertThat (waitFor (execute ).getResults ())
@@ -698,12 +722,13 @@ public void testChecks() {
698722 @ Ignore ("Not supported yet" )
699723 public void testLogicalMax () {
700724 Task <PipelineSnapshot > execute =
701- randomCol
725+ firestore
702726 .pipeline ()
727+ .collection (randomCol )
703728 .where (Field .of ("author" ).eq ("Douglas Adams" ))
704729 .select (
705- Field .of ("rating" ).logicalMax (4.5 ).as ("max_rating" ),
706- logicalMax (Field .of ("published" ), 1900 ).as ("max_published" ))
730+ Field .of ("rating" ).logicalMax (4.5 ).alias ("max_rating" ),
731+ logicalMax (Field .of ("published" ), 1900 ).alias ("max_published" ))
707732 .execute ();
708733 assertThat (waitFor (execute ).getResults ())
709734 .comparingElementsUsing (DATA_CORRESPONDENCE )
@@ -714,12 +739,7 @@ public void testLogicalMax() {
714739 @ Ignore ("Not supported yet" )
715740 public void testLogicalMin () {
716741 Task <PipelineSnapshot > execute =
717- randomCol
718- .pipeline ()
719- .select (
720- Field .of ("rating" ).logicalMin (4.5 ).as ("min_rating" ),
721- logicalMin (Field .of ("published" ), 1900 ).as ("min_published" ))
722- .execute ();
742+ firestore .pipeline ().collection (randomCol ).sort (Field .of ("rating" ).ascending ()).execute ();
723743 assertThat (waitFor (execute ).getResults ())
724744 .comparingElementsUsing (DATA_CORRESPONDENCE )
725745 .containsExactly (ImmutableMap .of ("min_rating" , 4.2 , "min_published" , 1900 ));
@@ -728,9 +748,10 @@ public void testLogicalMin() {
728748 @ Test
729749 public void testMapGet () {
730750 Task <PipelineSnapshot > execute =
731- randomCol
751+ firestore
732752 .pipeline ()
733- .select (Field .of ("awards" ).mapGet ("hugo" ).as ("hugoAward" ), Field .of ("title" ))
753+ .collection (randomCol )
754+ .select (Field .of ("awards" ).mapGet ("hugo" ).alias ("hugoAward" ), Field .of ("title" ))
734755 .where (eq ("hugoAward" , true ))
735756 .execute ();
736757 assertThat (waitFor (execute ).getResults ())
@@ -745,14 +766,15 @@ public void testDistanceFunctions() {
745766 double [] sourceVector = {0.1 , 0.1 };
746767 double [] targetVector = {0.5 , 0.8 };
747768 Task <PipelineSnapshot > execute =
748- randomCol
769+ firestore
749770 .pipeline ()
771+ .collection (randomCol )
750772 .select (
751- cosineDistance (Constant .vector (sourceVector ), targetVector ).as ("cosineDistance" ),
773+ cosineDistance (Constant .vector (sourceVector ), targetVector ).alias ("cosineDistance" ),
752774 Function .dotProduct (Constant .vector (sourceVector ), targetVector )
753- .as ("dotProductDistance" ),
775+ .alias ("dotProductDistance" ),
754776 euclideanDistance (Constant .vector (sourceVector ), targetVector )
755- .as ("euclideanDistance" ))
777+ .alias ("euclideanDistance" ))
756778 .limit (1 )
757779 .execute ();
758780 assertThat (waitFor (execute ).getResults ())
@@ -767,8 +789,9 @@ public void testDistanceFunctions() {
767789 @ Test
768790 public void testNestedFields () {
769791 Task <PipelineSnapshot > execute =
770- randomCol
792+ firestore
771793 .pipeline ()
794+ .collection (randomCol )
772795 .where (eq ("awards.hugo" , true ))
773796 .select ("title" , "awards.hugo" )
774797 .execute ();
@@ -782,13 +805,14 @@ public void testNestedFields() {
782805 @ Test
783806 public void testMapGetWithFieldNameIncludingNotation () {
784807 Task <PipelineSnapshot > execute =
785- randomCol
808+ firestore
786809 .pipeline ()
810+ .collection (randomCol )
787811 .where (eq ("awards.hugo" , true ))
788812 .select (
789813 "title" ,
790814 Field .of ("nestedField.level.1" ),
791- mapGet ("nestedField" , "level.1" ).mapGet ("level.2" ).as ("nested" ))
815+ mapGet ("nestedField" , "level.1" ).mapGet ("level.2" ).alias ("nested" ))
792816 .execute ();
793817 assertThat (waitFor (execute ).getResults ())
794818 .comparingElementsUsing (DATA_CORRESPONDENCE )
@@ -806,8 +830,9 @@ public void testMapGetWithFieldNameIncludingNotation() {
806830 @ Test
807831 public void testListEquals () {
808832 Task <PipelineSnapshot > execute =
809- randomCol
833+ firestore
810834 .pipeline ()
835+ .collection (randomCol )
811836 .where (eq ("tags" , ImmutableList .of ("philosophy" , "crime" , "redemption" )))
812837 .execute ();
813838 assertThat (waitFor (execute ).getResults ())
@@ -818,8 +843,9 @@ public void testListEquals() {
818843 @ Test
819844 public void testMapEquals () {
820845 Task <PipelineSnapshot > execute =
821- randomCol
846+ firestore
822847 .pipeline ()
848+ .collection (randomCol )
823849 .where (eq ("awards" , ImmutableMap .of ("nobel" , true , "nebula" , false )))
824850 .execute ();
825851 assertThat (waitFor (execute ).getResults ())
0 commit comments