summaryrefslogtreecommitdiff
path: root/ext/librethinkdbxx/test/upstream/aggregation.yaml
diff options
context:
space:
mode:
Diffstat (limited to 'ext/librethinkdbxx/test/upstream/aggregation.yaml')
-rw-r--r--ext/librethinkdbxx/test/upstream/aggregation.yaml575
1 files changed, 575 insertions, 0 deletions
diff --git a/ext/librethinkdbxx/test/upstream/aggregation.yaml b/ext/librethinkdbxx/test/upstream/aggregation.yaml
new file mode 100644
index 00000000..1e0ec9c8
--- /dev/null
+++ b/ext/librethinkdbxx/test/upstream/aggregation.yaml
@@ -0,0 +1,575 @@
+desc: Tests that manipulation data in tables
+table_variable_name: tbl tbl2 tbl3 tbl4
+tests:
+
+ # Set up some data
+ - cd: r.range(100).for_each(tbl.insert({'id':r.row, 'a':r.row.mod(4)}))
+ rb: tbl.insert((0..99).map{ |i| { :id => i, :a => i % 4 } })
+ ot: {'deleted':0.0,'replaced':0.0,'unchanged':0.0,'errors':0.0,'skipped':0.0,'inserted':100}
+
+ - cd: r.range(100).for_each(tbl2.insert({'id':r.row, 'a':r.row.mod(4)}))
+ rb: tbl2.insert((0..99).map{ |i| { :id => i, :b => i % 4 } })
+ ot: {'deleted':0.0,'replaced':0.0,'unchanged':0.0,'errors':0.0,'skipped':0.0,'inserted':100}
+
+ - cd: r.range(100).for_each(tbl3.insert({'id':r.row, 'a':r.row.mod(4), 'b':{'c':r.row.mod(5)}}))
+ rb: tbl3.insert((0..99).map{ |i| { :id => i, :a => i % 4, :b => { :c => i % 5 } } })
+ ot: {'deleted':0.0,'replaced':0.0,'unchanged':0.0,'errors':0.0,'skipped':0.0,'inserted':100}
+
+ - def:
+ cd: time1 = 1375115782.24
+ js: time1 = 1375115782.24 * 1000
+
+ - def:
+ cd: time2 = 1375147296.68
+ js: time2 = 1375147296.68 * 1000
+
+ - cd:
+ - tbl4.insert({'id':0, 'time':r.epoch_time(time1)})
+ - tbl4.insert({'id':1, 'time':r.epoch_time(time2)})
+ ot: {'deleted':0.0,'replaced':0.0,'unchanged':0.0,'errors':0.0,'skipped':0.0,'inserted':1}
+
+ # GMR
+
+ - cd: tbl.sum('a')
+ ot: 150
+ - rb: tbl.map{|row| row['a']}.sum()
+ py: tbl.map(lambda row:row['a']).sum()
+ js: tbl.map(function(row){return row('a')}).sum()
+ ot: 150
+ - cd: tbl.group('a').sum('id')
+ ot:
+ cd: ({0:1200, 1:1225, 2:1250, 3:1275})
+ js: ([{'group':0,'reduction':1200},{'group':1,'reduction':1225},{'group':2,'reduction':1250},{'group':3,'reduction':1275}])
+ - cd: tbl.avg('a')
+ ot: 1.5
+ - rb: tbl.map{|row| row['a']}.avg()
+ py: tbl.map(lambda row:row['a']).avg()
+ js: tbl.map(function(row){return row('a')}).avg()
+ ot: 1.5
+ - cd: tbl.group('a').avg('id')
+ ot:
+ cd: {0:48, 1:49, 2:50, 3:51}
+ js: [{'group':0,'reduction':48},{'group':1,'reduction':49},{'group':2,'reduction':50},{'group':3,'reduction':51}]
+ - cd: tbl.min('a')['a']
+ js: tbl.min('a')('a')
+ ot: 0
+ - cd: tbl.order_by('id').min('a')
+ ot: {'a':0, 'id':0}
+ - rb: tbl.map{|row| row['a']}.min()
+ py: tbl.map(lambda row:row['a']).min()
+ js: tbl.map(function(row){return row('a')}).min()
+ ot: 0
+ - cd: tbl.group('a').min('id')
+ ot:
+ cd: {0:{'a':0, 'id':0}, 1:{'a':1, 'id':1}, 2:{'a':2, 'id':2}, 3:{'a':3, 'id':3}}
+ js: [{'group':0,'reduction':{'a':0, 'id':0}},{'group':1,'reduction':{'a':1, 'id':1}},{'group':2,'reduction':{'a':2, 'id':2}},{'group':3,'reduction':{'a':3, 'id':3}}]
+ - cd: tbl.order_by('id').max('a')
+ ot: {'a':3, 'id':3}
+ - rb: tbl.map{|row| row['a']}.max()
+ py: tbl.map(lambda row:row['a']).max()
+ js: tbl.map(function(row){return row('a')}).max()
+ ot: 3
+ - cd: tbl.group('a').max('id')
+ ot:
+ cd: {0:{'a':0, 'id':96}, 1:{'a':1, 'id':97}, 2:{'a':2, 'id':98}, 3:{'a':3, 'id':99}}
+ js: [{'group':0,'reduction':{'a':0, 'id':96}},{'group':1,'reduction':{'a':1, 'id':97}},{'group':2,'reduction':{'a':2, 'id':98}},{'group':3,'reduction':{'a':3, 'id':99}}]
+
+ - cd: tbl.min()
+ ot: {"a":0, "id":0}
+ - cd: tbl.group('a').min()
+ ot:
+ cd: {0:{"a":0, "id":0}, 1:{"a":1, "id":1}, 2:{"a":2, "id":2}, 3:{"a":3, "id":3}}
+ js: [{'group':0,'reduction':{"a":0,"id":0}},{'group':1,'reduction':{"a":1,"id":1}},{'group':2,'reduction':{"a":2,"id":2}},{'group':3,'reduction':{"a":3,"id":3}}]
+ - cd: tbl.max()
+ ot: {"a":3, "id":99}
+ - cd: tbl.group('a').max()
+ ot:
+ cd: {0:{'a':0, 'id':96}, 1:{'a':1, 'id':97}, 2:{'a':2, 'id':98}, 3:{'a':3, 'id':99}}
+ js: [{'group':0,'reduction':{"a":0,"id":96}},{'group':1,'reduction':{"a":1,"id":97}},{'group':2,'reduction':{"a":2,"id":98}},{'group':3,'reduction':{"a":3,"id":99}}]
+
+ - rb: tbl.sum{|row| row['a']}
+ py:
+ - tbl.sum(lambda row:row['a'])
+ - tbl.sum(r.row['a'])
+ js:
+ - tbl.sum(function(row){return row('a')})
+ - tbl.sum(r.row('a'))
+ ot: 150
+ - rb: tbl.map{|row| row['a']}.sum()
+ py: tbl.map(lambda row:row['a']).sum()
+ js: tbl.map(function(row){return row('a')}).sum()
+ ot: 150
+ - rb: tbl.group{|row| row['a']}.sum{|row| row['id']}
+ py: tbl.group(lambda row:row['a']).sum(lambda row:row['id'])
+ js: tbl.group(function(row){return row('a')}).sum(function(row){return row('id')})
+ ot:
+ cd: {0:1200, 1:1225, 2:1250, 3:1275}
+ js: [{'group':0,'reduction':1200},{'group':1,'reduction':1225},{'group':2,'reduction':1250},{'group':3,'reduction':1275}]
+ - rb:
+ - tbl.avg{|row| row['a']}
+ py:
+ - tbl.avg(lambda row:row['a'])
+ - tbl.avg(r.row['a'])
+ js:
+ - tbl.avg(function(row){return row('a')})
+ - tbl.avg(r.row('a'))
+ ot: 1.5
+ - rb: tbl.map{|row| row['a']}.avg()
+ py: tbl.map(lambda row:row['a']).avg()
+ js: tbl.map(function(row){return row('a')}).avg()
+ ot: 1.5
+ - rb: tbl.group{|row| row['a']}.avg{|row| row['id']}
+ py: tbl.group(lambda row:row['a']).avg(lambda row:row['id'])
+ js: tbl.group(function(row){return row('a')}).avg(function(row){return row('id')})
+ ot:
+ cd: {0:48, 1:49, 2:50, 3:51}
+ js: [{'group':0,'reduction':48},{'group':1,'reduction':49},{'group':2,'reduction':50},{'group':3,'reduction':51}]
+ - rb: tbl.order_by(r.desc('id')).min{|row| row['a']}
+ py:
+ - tbl.order_by(r.desc('id')).min(lambda row:row['a'])
+ - tbl.order_by(r.desc('id')).min(r.row['a'])
+ js:
+ - tbl.order_by(r.desc('id')).min(function(row){return row('a')})
+ - tbl.order_by(r.desc('id')).min(r.row('a'))
+ ot: {'a':0, 'id':96}
+ - rb:
+ - tbl.order_by(r.desc('id')).min{|row| row['a']}['a']
+ py:
+ - tbl.order_by(r.desc('id')).min(lambda row:row['a'])['a']
+ - tbl.order_by(r.desc('id')).min(r.row['a'])['a']
+ js:
+ - tbl.order_by(r.desc('id')).min(function(row){return row('a')})('a')
+ - tbl.order_by(r.desc('id')).min(r.row('a'))('a')
+ ot: 0
+ - rb: tbl.map{|row| row['a']}.min()
+ py: tbl.map(lambda row:row['a']).min()
+ js: tbl.map(function(row){return row('a')}).min()
+ ot: 0
+ - rb: tbl.group{|row| row['a']}.min{|row| row['id']}['id']
+ py: tbl.group(lambda row:row['a']).min(lambda row:row['id'])['id']
+ js: tbl.group(function(row){return row('a')}).min(function(row){return row('id')})('id')
+ ot:
+ cd: {0:0, 1:1, 2:2, 3:3}
+ js: [{'group':0,'reduction':0},{'group':1,'reduction':1},{'group':2,'reduction':2},{'group':3,'reduction':3}]
+ - rb:
+ - tbl.max{|row| row['a']}['a']
+ py:
+ - tbl.max(lambda row:row['a'])['a']
+ - tbl.max(r.row['a'])['a']
+ js:
+ - tbl.max(function(row){return row('a')})('a')
+ - tbl.max(r.row('a'))('a')
+ ot: 3
+ - rb: tbl.map{|row| row['a']}.max()
+ py: tbl.map(lambda row:row['a']).max()
+ js: tbl.map(function(row){return row('a')}).max()
+ ot: 3
+ - rb: tbl.group{|row| row['a']}.max{|row| row['id']}['id']
+ py: tbl.group(lambda row:row['a']).max(lambda row:row['id'])['id']
+ js: tbl.group(function(row){return row('a')}).max(function(row){return row('id')})('id')
+ ot:
+ cd: {0:96, 1:97, 2:98, 3:99}
+ js: [{'group':0,'reduction':96},{'group':1,'reduction':97},{'group':2,'reduction':98},{'group':3,'reduction':99}]
+
+ - rb: tbl.group{|row| row[:a]}.map{|row| row[:id]}.reduce{|a,b| a+b}
+ py: tbl.group(lambda row:row['a']).map(lambda row:row['id']).reduce(lambda a,b:a+b)
+ js: tbl.group(function(row){return row('a')}).map(function(row){return row('id')}).reduce(function(a,b){return a.add(b)})
+ ot:
+ cd: {0:1200, 1:1225, 2:1250, 3:1275}
+ js: [{'group':0,'reduction':1200},{'group':1,'reduction':1225},{'group':2,'reduction':1250},{'group':3,'reduction':1275}]
+
+ - rb: tbl.group{|row| row[:a]}.map{|row| row[:id]}.reduce{|a,b| a+b}
+ runopts:
+ group_format: 'raw'
+ py:
+ - tbl.group(lambda row:row['a']).map(lambda row:row['id']).reduce(lambda a,b:a+b)
+ - tbl.group(r.row['a']).map(r.row['id']).reduce(lambda a,b:a + b)
+ js:
+ - tbl.group(function(row){return row('a')}).map(function(row){return row('id')}).reduce(function(a,b){return a.add(b)})
+ - tbl.group(r.row('a')).map(r.row('id')).reduce(function(a,b){return a.add(b)})
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 1200], [1, 1225], [2, 1250], [3, 1275]]}
+
+ - cd: r.expr([{'a':1}]).filter(true).limit(1).group('a')
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[1, [{'a':1}]]]}
+
+ # GMR
+ - cd: tbl.group('a').type_of()
+ ot: "GROUPED_STREAM"
+ - cd: tbl.group('a').count().type_of()
+ ot: "GROUPED_DATA"
+ - cd: tbl.group('a').coerce_to('ARRAY').type_of()
+ ot: "GROUPED_DATA"
+
+ - rb: tbl.orderby(index:'id').filter{|row| row['id'].lt(10)}.group('a').map{|row| row['id']}.coerce_to('ARRAY')
+ py: tbl.order_by(index='id').filter(lambda row:row['id'] < 10).group('a').map(lambda row:row['id']).coerce_to('ARRAY')
+ js: tbl.orderBy({index:'id'}).filter(function(row){return row('id').lt(10)}).group('a').map(function(row){return row('id')}).coerce_to('ARRAY')
+ ot:
+ cd: {0:[0,4,8],1:[1,5,9],2:[2,6],3:[3,7]}
+ js: [{'group':0,'reduction':[0,4,8]},{'group':1,'reduction':[1,5,9]},{'group':2,'reduction':[2,6]},{'group':3,'reduction':[3,7]}]
+
+ - rb: tbl.filter{|row| row['id'].lt(10)}.group('a').count().do{|x| x*x}
+ py: tbl.filter(lambda row:row['id'] < 10).group('a').count().do(lambda x:x*x)
+ js: tbl.filter(function(row){return row('id').lt(10)}).group('a').count().do(function(x){return x.mul(x)})
+ ot:
+ cd: {0:9,1:9,2:4,3:4}
+ js: [{'group':0,'reduction':9},{'group':1,'reduction':9},{'group':2,'reduction':4},{'group':3,'reduction':4}]
+
+ - rb: tbl.union(tbl).group('a').map{|x| x['id']}.reduce{|a,b| a+b}
+ runopts:
+ group_format: 'raw'
+ py:
+ - tbl.union(tbl).group(lambda row:row['a']).map(lambda row:row['id']).reduce(lambda a,b:a + b)
+ - tbl.union(tbl).group(r.row['a']).map(r.row['id']).reduce(lambda a,b:a + b)
+ js:
+ - tbl.union(tbl).group(function(row){return row('a')}).map(function(row){return row('id')}).reduce(function(a,b){return a.add(b)})
+ - tbl.union(tbl).group(r.row('a')).map(r.row('id')).reduce(function(a,b){return a.add(b)})
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 2400], [1, 2450], [2, 2500], [3, 2550]]}
+
+ # GMR
+ - rb: tbl.coerce_to("array").union(tbl).group('a').map{|x| x['id']}.reduce{|a,b| a+b}
+ runopts:
+ group_format: 'raw'
+ py:
+ - tbl.coerce_to("array").union(tbl).group(lambda row:row['a']).map(lambda row:row['id']).reduce(lambda a,b:a + b)
+ - tbl.coerce_to("array").union(tbl).group(r.row['a']).map(r.row['id']).reduce(lambda a,b:a + b)
+ js:
+ - tbl.coerce_to("array").union(tbl).group(function(row){return row('a')}).map(function(row){return row('id')}).reduce(function(a,b){return a.add(b)})
+ - tbl.coerce_to("array").union(tbl).group(r.row('a')).map(r.row('id')).reduce(function(a,b){return a.add(b)})
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 2400], [1, 2450], [2, 2500], [3, 2550]]}
+
+ # GMR
+ - rb: tbl.union(tbl.coerce_to("array")).group('a').map{|x| x['id']}.reduce{|a,b| a+b}
+ runopts:
+ group_format: 'raw'
+ py:
+ - tbl.union(tbl.coerce_to("array")).group(lambda row:row['a']).map(lambda row:row['id']).reduce(lambda a,b:a + b)
+ - tbl.union(tbl.coerce_to("array")).group(r.row['a']).map(r.row['id']).reduce(lambda a,b:a + b)
+ js:
+ - tbl.union(tbl.coerce_to("array")).group(function(row){return row('a')}).map(function(row){return row('id')}).reduce(function(a,b){return a.add(b)})
+ - tbl.union(tbl.coerce_to("array")).group(r.row('a')).map(r.row('id')).reduce(function(a,b){return a.add(b)})
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 2400], [1, 2450], [2, 2500], [3, 2550]]}
+
+ - py:
+ - tbl.group(lambda row:row['a']).map(lambda row:row['id']).reduce(lambda a,b:a + b)
+ - tbl.group(r.row['a']).map(r.row['id']).reduce(lambda a,b:a + b)
+ js:
+ - tbl.group(function(row){return row('a')}).map(function(row){return row('id')}).reduce(function(a,b){return a.add(b)})
+ - tbl.group(r.row('a')).map(r.row('id')).reduce(function(a,b){return a.add(b)})
+ - tbl.group('a').map(r.row('id')).reduce(function(a,b){return a.add(b)})
+ rb: tbl.group('a').map{|x| x['id']}.reduce{|a,b| a+b}
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 1200], [1, 1225], [2, 1250], [3, 1275]]}
+
+ # undefined...
+ - js:
+ - tbl.group(function(row){})
+ - tbl.map(function(row){})
+ - tbl.reduce(function(row){})
+ - tbl.group(r.row('a')).group(function(row){})
+ - tbl.group(r.row('a')).map(function(row){})
+ - tbl.group(r.row('a')).reduce(function(row){})
+ - tbl.map(r.row('id')).group(function(row){})
+ - tbl.map(r.row('id')).map(function(row){})
+ - tbl.map(r.row('id')).reduce(function(row){})
+ - tbl.reduce(function(a,b){return a+b}).group(function(row){})
+ - tbl.reduce(function(a,b){return a+b}).map(function(row){})
+ - tbl.reduce(function(a,b){return a+b}).reduce(function(row){})
+ ot: err('ReqlDriverCompileError', 'Anonymous function returned `undefined`. Did you forget a `return`?', [0])
+
+ # GroupBy
+
+ # COUNT
+
+ - cd: tbl.group('a').count()
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 25], [1, 25], [2, 25], [3, 25]]}
+
+ # SUM
+ - cd: tbl.group('a').sum('id')
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 1200], [1, 1225], [2, 1250], [3, 1275]]}
+
+ # AVG
+ - cd: tbl.group('a').avg('id')
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 48], [1, 49], [2, 50], [3, 51]]}
+
+ # Pattern Matching
+ - rb: tbl3.group{|row| row['b']['c']}.count()
+ py: tbl3.group(lambda row:row['b']['c']).count()
+ js: tbl3.group(function(row){return row('b')('c')}).count()
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 20], [1, 20], [2, 20], [3, 20], [4, 20]]}
+
+ # Multiple keys
+ - rb: tbl.group('a', lambda {|row| row['id']%3}).count()
+ py: tbl.group('a', lambda row:row['id'].mod(3)).count()
+ js: tbl.group('a', function(row){return row('id').mod(3)}).count()
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[[0, 0], 9], [[0, 1], 8], [[0, 2], 8], [[1, 0], 8], [[1, 1], 9], [[1, 2], 8], [[2, 0], 8], [[2, 1], 8], [[2, 2], 9], [[3, 0], 9], [[3, 1], 8], [[3, 2], 8]]}
+
+ # Grouping by time
+ - rb: tbl4.group('time').coerce_to('array')
+ runopts:
+ time_format: 'raw'
+ ot:
+ rb: {{"$reql_type$":"TIME","epoch_time":1375115782.24,"timezone":"+00:00"}:[{"id":0,"time":{"$reql_type$":"TIME","epoch_time":1375115782.24,"timezone":"+00:00"}}],{"$reql_type$":"TIME","epoch_time":1375147296.68,"timezone":"+00:00"}:[{"id":1,"time":{"$reql_type$":"TIME","epoch_time":1375147296.68,"timezone":"+00:00"}}]}
+ py: {frozenset([('$reql_type$','TIME'),('timezone','+00:00'),('epoch_time',1375115782.24)]):[{'id':0,'time':{'timezone':'+00:00','$reql_type$':'TIME','epoch_time':1375115782.24}}],frozenset([('$reql_type$','TIME'),('timezone','+00:00'),('epoch_time',1375147296.68)]):[{'id':1,'time':{'timezone':'+00:00','$reql_type$':'TIME','epoch_time':1375147296.68}}]}
+ js: [{'group':{"$reql_type$":"TIME","epoch_time":1375115782240,"timezone":"+00:00"},'reduction':[{"id":0,"time":{"$reql_type$":"TIME","epoch_time":1375115782240,"timezone":"+00:00"}}]},{'group':{"$reql_type$":"TIME","epoch_time":1375147296680,"timezone":"+00:00"},'reduction':[{"id":1,"time":{"$reql_type$":"TIME","epoch_time":1375147296680,"timezone":"+00:00"}}]}]
+
+ # Distinct
+ - py: tbl.map(lambda row:row['a']).distinct().count()
+ js: tbl.map(function(row) { return row('a'); }).distinct().count()
+ rb: tbl.map{ |row| row[:a] }.distinct.count
+ ot: 4
+
+ - cd: tbl.distinct().type_of()
+ ot: "STREAM"
+
+ - cd: tbl.distinct().count()
+ ot: 100
+
+ - cd: tbl.distinct({index:'id'}).type_of()
+ py: tbl.distinct(index='id').type_of()
+ ot: "STREAM"
+
+ - cd: tbl.distinct({index:'id'}).count()
+ py: tbl.distinct(index='id').count()
+ ot: 100
+
+ - cd: tbl.index_create('a')
+ ot: {'created':1}
+
+ - rb: tbl.index_create('m', multi:true){|row| [row['a'], row['a']]}
+ ot: {'created':1}
+
+ - rb: tbl.index_create('m2', multi:true){|row| [1, 2]}
+ ot: {'created':1}
+
+ - cd: tbl.index_wait('a').pluck('index', 'ready')
+ ot: [{'index':'a','ready':true}]
+
+ - rb: tbl.index_wait('m').pluck('index', 'ready')
+ ot: [{'index':'m','ready':true}]
+
+ - rb: tbl.index_wait('m2').pluck('index', 'ready')
+ ot: [{'index':'m2','ready':true}]
+
+ - cd: tbl.between(0, 1, {index:'a'}).distinct().count()
+ py: tbl.between(0, 1, index='a').distinct().count()
+ ot: 25
+
+ - cd: tbl.between(0, 1, {index:'a'}).distinct({index:'id'}).count()
+ py: tbl.between(0, 1, index='a').distinct(index='id').count()
+ ot: 25
+
+ - rb: tbl.between(0, 1, {index:'m'}).count()
+ ot: 50
+
+ - rb: tbl.between(0, 1, {index:'m'}).distinct().count()
+ ot: 25
+
+ - rb: tbl.orderby({index:'m'}).count()
+ ot: 200
+
+ - rb: tbl.orderby({index:'m'}).distinct().count()
+ ot: 100
+
+ - rb: tbl.orderby({index:r.desc('m')}).count()
+ ot: 200
+
+ - rb: tbl.orderby({index:r.desc('m')}).distinct().count()
+ ot: 100
+
+ - rb: tbl.between(1, 3, {index:'m2'}).count()
+ ot: 200
+
+ - rb: tbl.between(1, 3, {index:'m2'}).distinct().count()
+ ot: 100
+
+ - rb: tbl.between(1, 3, {index:'m2'}).orderby(index:r.desc('m2')).distinct().count()
+ ot: 100
+
+ - rb: tbl.between(0, 1, {index:'m'}).count()
+ ot: 50
+
+ - rb: tbl.between(0, 1, {index:'m'}).distinct().count()
+ ot: 25
+
+ - cd: tbl.distinct({index:'a'}).type_of()
+ py: tbl.distinct(index='a').type_of()
+ ot: "STREAM"
+
+ - cd: tbl.distinct({index:'a'}).count()
+ py: tbl.distinct(index='a').count()
+ ot: 4
+
+ - cd: tbl.group()
+ ot: err('ReqlQueryLogicError', 'Cannot group by nothing.', [])
+
+ - py: tbl.group(index='id').count()
+ js: tbl.group({index:'id'}).count()
+ cd: tbl.group(index:'id').count
+ runopts:
+ group_format: 'raw'
+ ot: ({'$reql_type$':'GROUPED_DATA', 'data':[[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [16, 1], [17, 1], [18, 1], [19, 1], [20, 1], [21, 1], [22, 1], [23, 1], [24, 1], [25, 1], [26, 1], [27, 1], [28, 1], [29, 1], [30, 1], [31, 1], [32, 1], [33, 1], [34, 1], [35, 1], [36, 1], [37, 1], [38, 1], [39, 1], [40, 1], [41, 1], [42, 1], [43, 1], [44, 1], [45, 1], [46, 1], [47, 1], [48, 1], [49, 1], [50, 1], [51, 1], [52, 1], [53, 1], [54, 1], [55, 1], [56, 1], [57, 1], [58, 1], [59, 1], [60, 1], [61, 1], [62, 1], [63, 1], [64, 1], [65, 1], [66, 1], [67, 1], [68, 1], [69, 1], [70, 1], [71, 1], [72, 1], [73, 1], [74, 1], [75, 1], [76, 1], [77, 1], [78, 1], [79, 1], [80, 1], [81, 1], [82, 1], [83, 1], [84, 1], [85, 1], [86, 1], [87, 1], [88, 1], [89, 1], [90, 1], [91, 1], [92, 1], [93, 1], [94, 1], [95, 1], [96, 1], [97, 1], [98, 1], [99, 1]]})
+
+ - py: tbl.group(index='a').count()
+ js: tbl.group({index:'a'}).count()
+ rb: tbl.group(index:'a').count
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[0, 25], [1, 25], [2, 25], [3, 25]]}
+
+ - py: tbl.group('a', index='id').count()
+ js: tbl.group('a', {index:'id'}).count()
+ rb: tbl.group('a', index:'id').count
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[[0, 0], 1], [[0, 4], 1], [[0, 8], 1], [[0, 12], 1], [[0, 16], 1], [[0, 20], 1], [[0, 24], 1], [[0, 28], 1], [[0, 32], 1], [[0, 36], 1], [[0, 40], 1], [[0, 44], 1], [[0, 48], 1], [[0, 52], 1], [[0, 56], 1], [[0, 60], 1], [[0, 64], 1], [[0, 68], 1], [[0, 72], 1], [[0, 76], 1], [[0, 80], 1], [[0, 84], 1], [[0, 88], 1], [[0, 92], 1], [[0, 96], 1], [[1, 1], 1], [[1, 5], 1], [[1, 9], 1], [[1, 13], 1], [[1, 17], 1], [[1, 21], 1], [[1, 25], 1], [[1, 29], 1], [[1, 33], 1], [[1, 37], 1], [[1, 41], 1], [[1, 45], 1], [[1, 49], 1], [[1, 53], 1], [[1, 57], 1], [[1, 61], 1], [[1, 65], 1], [[1, 69], 1], [[1, 73], 1], [[1, 77], 1], [[1, 81], 1], [[1, 85], 1], [[1, 89], 1], [[1, 93], 1], [[1, 97], 1], [[2, 2], 1], [[2, 6], 1], [[2, 10], 1], [[2, 14], 1], [[2, 18], 1], [[2, 22], 1], [[2, 26], 1], [[2, 30], 1], [[2, 34], 1], [[2, 38], 1], [[2, 42], 1], [[2, 46], 1], [[2, 50], 1], [[2, 54], 1], [[2, 58], 1], [[2, 62], 1], [[2, 66], 1], [[2, 70], 1], [[2, 74], 1], [[2, 78], 1], [[2, 82], 1], [[2, 86], 1], [[2, 90], 1], [[2, 94], 1], [[2, 98], 1], [[3, 3], 1], [[3, 7], 1], [[3, 11], 1], [[3, 15], 1], [[3, 19], 1], [[3, 23], 1], [[3, 27], 1], [[3, 31], 1], [[3, 35], 1], [[3, 39], 1], [[3, 43], 1], [[3, 47], 1], [[3, 51], 1], [[3, 55], 1], [[3, 59], 1], [[3, 63], 1], [[3, 67], 1], [[3, 71], 1], [[3, 75], 1], [[3, 79], 1], [[3, 83], 1], [[3, 87], 1], [[3, 91], 1], [[3, 95], 1], [[3, 99], 1]]}
+
+ - py: tbl.group('a', index='a').count()
+ js: tbl.group('a', {index:'a'}).count()
+ rb: tbl.group('a', index:'a').count
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[[0, 0], 25], [[1, 1], 25], [[2, 2], 25], [[3, 3], 25]]}
+
+ - rb: tbl.group('a', lambda {|row| 'f'}, lambda {|row| []}, lambda {|row| [{}, [0], null, 0]}, multi:true).count
+ py: tbl.group('a', lambda row:'f', lambda row:[], lambda row:[{}, [0], null, 0], multi=True).count()
+ js: tbl.group('a', function(row){return 'f';}, function(row){return [];}, function(row){return [{}, [0], null, 0];}, {multi:true}).count()
+ runopts:
+ group_format: 'raw'
+ ot: {'$reql_type$':'GROUPED_DATA', 'data':[[[0, "f", null, [0]], 25], [[0, "f", null, null], 25], [[0, "f", null, 0], 25], [[0, "f", null, {}], 25], [[1, "f", null, [0]], 25], [[1, "f", null, null], 25], [[1, "f", null, 0], 25], [[1, "f", null, {}], 25], [[2, "f", null, [0]], 25], [[2, "f", null, null], 25], [[2, "f", null, 0], 25], [[2, "f", null, {}], 25], [[3, "f", null, [0]], 25], [[3, "f", null, null], 25], [[3, "f", null, 0], 25], [[3, "f", null, {}], 25]]}
+
+ - cd: tbl.group('a').count().ungroup()
+ ot: [{'group':0, 'reduction':25}, {'group':1, 'reduction':25}, {'group':2, 'reduction':25}, {'group':3, 'reduction':25}]
+
+ - cd: tbl.group('a').ungroup()['group']
+ js: tbl.group('a').ungroup()('group')
+ ot: [0, 1, 2, 3]
+
+ - py: tbl.order_by(index='id').limit(16).group('a','a').map(r.row['id']).sum().ungroup()
+ js: tbl.order_by({index:'id'}).limit(16).group('a','a').map(r.row('id')).sum().ungroup()
+ rb: tbl.order_by(index:'id').limit(16).group('a','a').map{|row| row['id']}.sum().ungroup()
+ ot: [{'group':[0,0],'reduction':24},{'group':[1,1],'reduction':28},{'group':[2,2],'reduction':32},{'group':[3,3],'reduction':36}]
+
+ - cd: tbl.group('a', null).count().ungroup()
+ ot: [{'group':[0,null],'reduction':25},{'group':[1,null],'reduction':25},{'group':[2,null],'reduction':25},{'group':[3,null],'reduction':25}]
+
+ - py: tbl.group('a', lambda row:[1,'two'], multi=True).count().ungroup()
+ js: tbl.group('a', function(row){return [1,'two']},{multi:true}).count().ungroup()
+ rb: tbl.group('a', lambda {|row| [1,'two']}, multi:true).count().ungroup()
+ ot: [{'group':[0,1],'reduction':25},{'group':[0,'two'],'reduction':25},{'group':[1,1],'reduction':25},{'group':[1,'two'],'reduction':25},{'group':[2,1],'reduction':25},{'group':[2,'two'],'reduction':25},{'group':[3,1],'reduction':25},{'group':[3,'two'],'reduction':25}]
+
+ # proper test for seq.count()
+ - cd: tbl.count()
+ ot: 100
+
+ - js: tbl.filter(r.row('a').ne(1).and(r.row('id').gt(10))).update({'b':r.row('a').mul(10)})
+ py: tbl.filter(r.row['a'].ne(1).and_(r.row['id'].gt(10))).update({'b':r.row['a'] * 10})
+ rb: tbl.filter{|row| row['a'].ne(1).and(row['id'].gt(10))}.update{|row| {'b'=>row['a'] * 10}}
+ ot: partial({'errors':0, 'replaced':67})
+
+ - cd: tbl.group('b').count()
+ ot:
+ cd: {null:33, 0:22, 20:22, 30:23}
+ js: [{"group":null, "reduction":33}, {"group":0, "reduction":22}, {"group":20, "reduction":22}, {"group":30, "reduction":23}]
+
+ - cd: tbl.group('a').sum('b')
+ ot:
+ cd: {0:0, 2:440, 3:690}
+ js: [{"group":0, "reduction":0}, {"group":2, "reduction":440}, {"group":3, "reduction":690}]
+
+ - cd: tbl.group('a').avg('b')
+ ot:
+ cd: {0:0, 2:20, 3:30}
+ js: [{"group":0, "reduction":0}, {"group":2, "reduction":20}, {"group":3, "reduction":30}]
+
+ - cd: tbl.order_by('id').group('a').min('b')
+ ot:
+ cd: {0:{"a":0, "b":0, "id":12}, 2:{"a":2, "b":20, "id":14}, 3:{"a":3, "b":30, "id":11}}
+ js: [{"group":0, "reduction":{"a":0, "b":0, "id":12}}, {"group":2, "reduction":{"a":2, "b":20, "id":14}}, {"group":3, "reduction":{"a":3, "b":30, "id":11}}]
+
+ - cd: tbl.order_by('id').group('a').min('id')
+ ot:
+ cd: {0:{"a":0, "id":0}, 1:{"a":1, "id":1}, 2:{"a":2, "id":2}, 3:{"a":3, "id":3}}
+ js: [{"group":0, "reduction":{"a":0, "id":0}}, {"group":1, "reduction":{"a":1, "id":1}}, {"group":2, "reduction":{"a":2, "id":2}}, {"group":3, "reduction":{"a":3, "id":3}}]
+
+ - cd: tbl.order_by('id').group('a').max('b')
+ ot:
+ cd: {0:{"a":0, "b":0, "id":12}, 2:{"a":2, "b":20, "id":14}, 3:{"a":3, "b":30, "id":11}}
+ js: [{"group":0, "reduction":{"a":0,"b":0, "id":12}}, {"group":2, "reduction":{"a":2, "b":20, "id":14}}, {"group":3, "reduction":{"a":3, "b":30, "id":11}}]
+
+ - cd: tbl.min()
+ ot: {'a':0,'id':0}
+ - py: tbl.min(index='id')
+ rb: tbl.min(index:'id')
+ js: tbl.min({index:'id'})
+ ot: {'a':0,'id':0}
+ - py: tbl.min(index='a')
+ rb: tbl.min(index:'a')
+ js: tbl.min({index:'a'})
+ ot: {'a':0,'id':0}
+
+ - cd: tbl.max().without('b')
+ ot: {'a':3,'id':99}
+ - py: tbl.max(index='id').without('b')
+ rb: tbl.max(index:'id').without('b')
+ js: tbl.max({index:'id'}).without('b')
+ ot: {'a':3,'id':99}
+ - py: tbl.max(index='a').without('b')
+ rb: tbl.max(index:'a').without('b')
+ js: tbl.max({index:'a'}).without('b')
+ ot: {'a':3,'id':99}
+
+
+ # Infix
+
+ - cd: r.group([ 1, 1, 2 ], r.row).count().ungroup()
+ rb: r.group([ 1, 1, 2 ]) {|row| row}.count().ungroup()
+ ot: [ {'group': 1, 'reduction': 2}, {'group': 2, 'reduction': 1} ]
+ - cd:
+ - r.count([ 1, 2 ])
+ - r.count([ 1, 2 ], r.row.gt(0))
+ rb:
+ - r.count([ 1, 2 ])
+ - r.count([ 1, 2 ]) {|row| row.gt(0)}
+ ot: 2
+ - cd:
+ - r.sum([ 1, 2 ])
+ - r.sum([ 1, 2 ], r.row)
+ rb: r.sum([ 1, 2 ])
+ ot: 3
+ - cd:
+ - r.avg([ 1, 2 ])
+ - r.avg([ 1, 2 ], r.row)
+ rb: r.avg([ 1, 2 ])
+ ot: 1.5
+ - cd:
+ - r.min([ 1, 2 ])
+ - r.min([ 1, 2 ], r.row)
+ rb: r.min([ 1, 2 ])
+ ot: 1
+ - cd:
+ - r.max([ 1, 2 ])
+ - r.max([ 1, 2 ], r.row)
+ rb: r.max([ 1, 2 ])
+ ot: 2
+ - cd: r.distinct([ 1, 1 ])
+ ot: [ 1 ]
+ - cd:
+ - r.contains([ 1, 2 ])
+ - r.contains([ 1, 2 ], r.row.gt(0))
+ rb:
+ - r.contains([ 1, 2 ])
+ - r.contains([ 1, 2 ]) {|row| row.gt(0)}
+ ot: true