@@ -722,7 +722,15 @@ func TestIntegration_AggregationQueries(t *testing.T) {
722
722
for i := range keys {
723
723
keys [i ] = IncompleteKey ("SQChild" , parent )
724
724
}
725
- keys , err := client .PutMulti (ctx , keys , children )
725
+
726
+ // Create transaction with read before creating entities
727
+ readTime := time .Now ()
728
+ txBeforeCreate , err := client .NewTransaction (ctx , []TransactionOption {ReadOnly , WithReadTime (readTime )}... )
729
+ if err != nil {
730
+ t .Fatalf ("client.NewTransaction: %v" , err )
731
+ }
732
+
733
+ keys , err = client .PutMulti (ctx , keys , children )
726
734
if err != nil {
727
735
t .Fatalf ("client.PutMulti: %v" , err )
728
736
}
@@ -733,13 +741,22 @@ func TestIntegration_AggregationQueries(t *testing.T) {
733
741
}
734
742
}()
735
743
744
+ // Create transaction with read after creating entities
745
+ readTime = time .Now ()
746
+ txAfterCreate , err := client .NewTransaction (ctx , []TransactionOption {ReadOnly , WithReadTime (readTime )}... )
747
+ if err != nil {
748
+ t .Fatalf ("client.NewTransaction: %v" , err )
749
+ }
750
+
736
751
testCases := []struct {
737
- desc string
738
- aggQuery * AggregationQuery
739
- wantFailure bool
740
- wantErrMsg string
741
- wantAggResult AggregationResult
752
+ desc string
753
+ aggQuery * AggregationQuery
754
+ transactionOpts []TransactionOption
755
+ wantFailure bool
756
+ wantErrMsg string
757
+ wantAggResult AggregationResult
742
758
}{
759
+
743
760
{
744
761
desc : "Count Failure - Missing index" ,
745
762
aggQuery : NewQuery ("SQChild" ).Ancestor (parent ).Filter ("T>=" , now ).
@@ -757,6 +774,34 @@ func TestIntegration_AggregationQueries(t *testing.T) {
757
774
"count" : & pb.Value {ValueType : & pb.Value_IntegerValue {IntegerValue : 5 }},
758
775
},
759
776
},
777
+ {
778
+ desc : "Aggregations in transaction before creating entities" ,
779
+ aggQuery : NewQuery ("SQChild" ).Ancestor (parent ).Filter ("T=" , now ).
780
+ Transaction (txBeforeCreate ).
781
+ NewAggregationQuery ().
782
+ WithCount ("count" ).
783
+ WithSum ("I" , "sum" ).
784
+ WithAvg ("I" , "avg" ),
785
+ wantAggResult : map [string ]interface {}{
786
+ "count" : & pb.Value {ValueType : & pb.Value_IntegerValue {IntegerValue : 0 }},
787
+ "sum" : & pb.Value {ValueType : & pb.Value_IntegerValue {IntegerValue : 0 }},
788
+ "avg" : & pb.Value {ValueType : & pb.Value_NullValue {NullValue : structpb .NullValue_NULL_VALUE }},
789
+ },
790
+ },
791
+ {
792
+ desc : "Aggregations in transaction after creating entities" ,
793
+ aggQuery : NewQuery ("SQChild" ).Ancestor (parent ).Filter ("T=" , now ).
794
+ Transaction (txAfterCreate ).
795
+ NewAggregationQuery ().
796
+ WithCount ("count" ).
797
+ WithSum ("I" , "sum" ).
798
+ WithAvg ("I" , "avg" ),
799
+ wantAggResult : map [string ]interface {}{
800
+ "count" : & pb.Value {ValueType : & pb.Value_IntegerValue {IntegerValue : 8 }},
801
+ "sum" : & pb.Value {ValueType : & pb.Value_IntegerValue {IntegerValue : 28 }},
802
+ "avg" : & pb.Value {ValueType : & pb.Value_DoubleValue {DoubleValue : 3.5 }},
803
+ },
804
+ },
760
805
{
761
806
desc : "Multiple aggregations" ,
762
807
aggQuery : NewQuery ("SQChild" ).Ancestor (parent ).Filter ("T=" , now ).
0 commit comments