@@ -41,65 +41,76 @@ func (s *RethinkSuite) TestAggregationDistinct(c *test.C) {
4141 c .Assert (response , test .HasLen , 5 )
4242}
4343
44- // func (s *RethinkSuite) TestAggregationGroupedMapReduce(c *test.C) {
45- // var response []interface{}
46- // query := Expr(objList).GroupedMapReduce(
47- // func(row RqlTerm) RqlTerm {
48- // return row.Field("id").Mod(2).Eq(0)
49- // },
50- // func(row RqlTerm) RqlTerm {
51- // return row.Field("num")
52- // },
53- // func(acc, num RqlTerm) RqlTerm {
54- // return acc.Add(num)
55- // },
56- // 0,
57- // )
58- // r, err := query.Run(sess)
59- // c.Assert(err, test.IsNil)
60-
61- // err = r.ScanAll(&response)
62-
63- // c.Assert(err, test.IsNil)
64- // c.Assert(response, JsonEquals, []interface{}{
65- // map[string]interface{}{"reduction": 135, "group": false},
66- // map[string]interface{}{"reduction": 70, "group": true},
67- // })
68- // }
69-
70- // func (s *RethinkSuite) TestAggregationGroupedMapReduceTable(c *test.C) {
71- // // Ensure table + database exist
72- // DbCreate("test").Exec(sess)
73- // Db("test").TableCreate("TestAggregationGroupedMapReduceTable").Exec(sess)
74-
75- // // Insert rows
76- // err := Db("test").Table("TestAggregationGroupedMapReduceTable").Insert(objList).Exec(sess)
77- // c.Assert(err, test.IsNil)
78-
79- // var response []interface{}
80- // query := Db("test").Table("TestAggregationGroupedMapReduceTable").GroupedMapReduce(
81- // func(row RqlTerm) RqlTerm {
82- // return row.Field("id").Mod(2).Eq(0)
83- // },
84- // func(row RqlTerm) RqlTerm {
85- // return row.Field("num")
86- // },
87- // func(acc, num RqlTerm) RqlTerm {
88- // return acc.Add(num)
89- // },
90- // 0,
91- // )
92- // r, err := query.Run(sess)
93- // c.Assert(err, test.IsNil)
94-
95- // err = r.ScanAll(&response)
96-
97- // c.Assert(err, test.IsNil)
98- // c.Assert(response, JsonEquals, []interface{}{
99- // map[string]interface{}{"reduction": 135, "group": false},
100- // map[string]interface{}{"reduction": 70, "group": true},
101- // })
102- // }
44+ func (s * RethinkSuite ) TestAggregationGroupMapReduce (c * test.C ) {
45+ var response []interface {}
46+ query := Expr (objList ).Group (func (row RqlTerm ) RqlTerm {
47+ return row .Field ("id" ).Mod (2 ).Eq (0 )
48+ }).Map (func (row RqlTerm ) RqlTerm {
49+ return row .Field ("num" )
50+ }).Reduce (func (acc , num RqlTerm ) RqlTerm {
51+ return acc .Add (num )
52+ })
53+ r , err := query .Run (sess )
54+ c .Assert (err , test .IsNil )
55+
56+ err = r .ScanAll (& response )
57+
58+ c .Assert (err , test .IsNil )
59+ c .Assert (response , JsonEquals , []interface {}{
60+ map [string ]interface {}{"reduction" : 135 , "group" : false },
61+ map [string ]interface {}{"reduction" : 70 , "group" : true },
62+ })
63+ }
64+
65+ func (s * RethinkSuite ) TestAggregationGroupMapReduceUngroup (c * test.C ) {
66+ var response []interface {}
67+ query := Expr (objList ).Group (func (row RqlTerm ) RqlTerm {
68+ return row .Field ("id" ).Mod (2 ).Eq (0 )
69+ }).Map (func (row RqlTerm ) RqlTerm {
70+ return row .Field ("num" )
71+ }).Reduce (func (acc , num RqlTerm ) RqlTerm {
72+ return acc .Add (num )
73+ }).Ungroup ().OrderBy ("reduction" )
74+ r , err := query .Run (sess )
75+ c .Assert (err , test .IsNil )
76+
77+ err = r .ScanAll (& response )
78+
79+ c .Assert (err , test .IsNil )
80+ c .Assert (response , JsonEquals , []interface {}{
81+ map [string ]interface {}{"reduction" : 70 , "group" : true },
82+ map [string ]interface {}{"reduction" : 135 , "group" : false },
83+ })
84+ }
85+
86+ func (s * RethinkSuite ) TestAggregationGroupMapReduceTable (c * test.C ) {
87+ // Ensure table + database exist
88+ DbCreate ("test" ).Exec (sess )
89+ Db ("test" ).TableCreate ("TestAggregationGroupedMapReduceTable" ).Exec (sess )
90+
91+ // Insert rows
92+ err := Db ("test" ).Table ("TestAggregationGroupedMapReduceTable" ).Insert (objList ).Exec (sess )
93+ c .Assert (err , test .IsNil )
94+
95+ var response []interface {}
96+ query := Db ("test" ).Table ("TestAggregationGroupedMapReduceTable" ).Group (func (row RqlTerm ) RqlTerm {
97+ return row .Field ("id" ).Mod (2 ).Eq (0 )
98+ }).Map (func (row RqlTerm ) RqlTerm {
99+ return row .Field ("num" )
100+ }).Reduce (func (acc , num RqlTerm ) RqlTerm {
101+ return acc .Add (num )
102+ })
103+ r , err := query .Run (sess )
104+ c .Assert (err , test .IsNil )
105+
106+ err = r .ScanAll (& response )
107+
108+ c .Assert (err , test .IsNil )
109+ c .Assert (response , JsonEquals , []interface {}{
110+ map [string ]interface {}{"reduction" : 135 , "group" : false },
111+ map [string ]interface {}{"reduction" : 70 , "group" : true },
112+ })
113+ }
103114
104115func (s * RethinkSuite ) TestAggregationGroupCount (c * test.C ) {
105116 var response []interface {}
0 commit comments