This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zhangyang-zerotierone/ext/librethinkdbxx/test/upstream/joins.yaml
2017-11-02 07:05:11 -07:00

134 lines
6.0 KiB
YAML

desc: Tests that manipulation data in tables
table_variable_name: tbl, tbl2, senders, receivers, messages, otbl, otbl2
tests:
# Setup some more tables
- py: r.db('test').table_create('test3', primary_key='foo')
rb: r.db('test').table_create('test3', {:primary_key=>'foo'})
js: r.db('test').tableCreate('test3', {'primaryKey':'foo'})
ot: partial({'tables_created':1})
- def: tbl3 = r.db('test').table('test3')
- py: tbl.insert(r.range(0, 100).map({'id':r.row, 'a':r.row % 4}))
rb: tbl.insert(r.range(0, 100).map{|row| {'id':row, a:row % 4}})
js: tbl.insert(r.range(0, 100).map(function (row) { return {'id':row, 'a':row.mod(4)}; }))
ot: partial({'errors':0, 'inserted':100})
- py: tbl2.insert(r.range(0, 100).map({'id':r.row, 'b':r.row % 4}))
rb: tbl2.insert(r.range(0, 100).map{|row| {'id':row, b:row % 4}})
js: tbl2.insert(r.range(0, 100).map(function (row) { return {'id':row, 'b':row.mod(4)}; }))
ot: partial({'errors':0, 'inserted':100})
- py: tbl3.insert(r.range(0, 100).map({'foo':r.row, 'b':r.row % 4}))
rb: tbl3.insert(r.range(0, 100).map{|row| {'foo':row, b:row % 4}})
js: tbl3.insert(r.range(0, 100).map(function (row) { return {'foo':row, 'b':row.mod(4)}; }))
ot: partial({'errors':0, 'inserted':100})
- py: otbl.insert(r.range(1,100).map({'id': r.row, 'a': r.row}))
- py: otbl2.insert(r.range(1,100).map({'id': r.row, 'b': 2 * r.row}))
# Inner-Join
- def:
py: ij = tbl.inner_join(tbl2, lambda x,y:x['a'] == y['b']).zip()
js: ij = tbl.innerJoin(tbl2, function(x, y) { return x('a').eq(y('b')); }).zip()
rb: ij = tbl.inner_join(tbl2){ |x, y| x[:a].eq y[:b] }.zip
- cd: ij.count()
ot: 2500
- py: ij.filter(lambda row:row['a'] != row['b']).count()
js: ij.filter(function(row) { return row('a').ne(row('b')); }).count()
rb: ij.filter{ |row| row[:a].ne row[:b] }.count
ot: 0
# Outer-Join
- def:
py: oj = tbl.outer_join(tbl2, lambda x,y:x['a'] == y['b']).zip()
js: oj = tbl.outerJoin(tbl2, function(x, y) { return x('a').eq(y('b')); }).zip()
rb: oj = tbl.outer_join(tbl2){ |x, y| x[:a].eq y[:b] }.zip
- cd: oj.count()
ot: 2500
- py: oj.filter(lambda row:row['a'] != row['b']).count()
js: oj.filter(function(row) { return row('a').ne(row('b')); }).count()
rb: oj.filter{ |row| row[:a].ne row[:b] }.count
ot: 0
# Ordered eq_join
- py: blah = otbl.order_by("id").eq_join(r.row['id'], otbl2, ordered=True).zip()
ot: [{'id': i, 'a': i, 'b': i * 2} for i in range(1, 100)]
- py: blah = otbl.order_by(r.desc("id")).eq_join(r.row['id'], otbl2, ordered=True).zip()
ot: [{'id': i, 'a': i, 'b': i * 2} for i in range(99, 0, -1)]
- py: blah = otbl.order_by("id").eq_join(r.row['a'], otbl2, ordered=True).zip()
ot: [{'id': i, 'a': i, 'b': i * 2} for i in range(1, 100)]
# Eq-Join
- cd: tbl.eq_join('a', tbl2).zip().count()
ot: 100
- cd: tbl.eq_join('fake', tbl2).zip().count()
ot: 0
- py: tbl.eq_join(lambda x:x['a'], tbl2).zip().count()
rb: tbl.eq_join(lambda{|x| x['a']}, tbl2).zip().count()
js: tbl.eq_join(function(x) { return x('a'); }, tbl2).zip().count()
ot: 100
- py: tbl.eq_join(lambda x:x['fake'], tbl2).zip().count()
rb: tbl.eq_join(lambda{|x| x['fake']}, tbl2).zip().count()
js: tbl.eq_join(function(x) { return x('fake'); }, tbl2).zip().count()
ot: 0
- py: tbl.eq_join(lambda x:null, tbl2).zip().count()
rb: tbl.eq_join(lambda{|x| null}, tbl2).zip().count()
js: tbl.eq_join(function(x) { return null; }, tbl2).zip().count()
ot: 0
- py: tbl.eq_join(lambda x:x['a'], tbl2).count()
rb: tbl.eq_join(lambda {|x| x[:a]}, tbl2).count()
js: tbl.eq_join(function(x) { return x('a'); }, tbl2).count()
ot: 100
# eqjoin where id isn't a primary key
- cd: tbl.eq_join('a', tbl3).zip().count()
ot: 100
- py: tbl.eq_join(lambda x:x['a'], tbl3).count()
rb: tbl.eq_join(lambda {|x| x[:a]}, tbl3).count()
js: tbl.eq_join(function(x) { return x('a'); }, tbl3).count()
ot: 100
# eq_join with r.row
- py: tbl.eq_join(r.row['a'], tbl2).count()
js: tbl.eq_join(r.row('a'), tbl2).count()
ot: 100
# test an inner-join condition where inner-join differs from outer-join
- def: left = r.expr([{'a':1},{'a':2},{'a':3}])
- def: right = r.expr([{'b':2},{'b':3}])
- py: left.inner_join(right, lambda l, r:l['a'] == r['b']).zip()
js: left.innerJoin(right, function(l, r) { return l('a').eq(r('b')); }).zip()
rb: left.inner_join(right){ |lt, rt| lt[:a].eq(rt[:b]) }.zip
ot: [{'a':2,'b':2},{'a':3,'b':3}]
# test an outer-join condition where outer-join differs from inner-join
- py: left.outer_join(right, lambda l, r:l['a'] == r['b']).zip()
js: left.outerJoin(right, function(l, r) { return l('a').eq(r('b')); }).zip()
rb: left.outer_join(right){ |lt, rt| lt[:a].eq(rt[:b]) }.zip
ot: [{'a':1},{'a':2,'b':2},{'a':3,'b':3}]
- rb: senders.insert({id:1, sender:'Sender One'})['inserted']
ot: 1
- rb: receivers.insert({id:1, receiver:'Receiver One'})['inserted']
ot: 1
- rb: messages.insert([{id:10, sender_id:1, receiver_id:1, msg:'Message One'}, {id:20, sender_id:1, receiver_id:1, msg:'Message Two'}, {id:30, sender_id:1, receiver_id:1, msg:'Message Three'}])['inserted']
ot: 3
- rb: messages.orderby(index:'id').eq_join('sender_id', senders).without({right:{id:true}}).zip.eq_join('receiver_id', receivers).without({right:{id:true}}).zip
ot: [{'id':10,'msg':'Message One','receiver':'Receiver One','receiver_id':1,'sender':'Sender One','sender_id':1},{'id':20,'msg':'Message Two','receiver':'Receiver One','receiver_id':1,'sender':'Sender One','sender_id':1},{'id':30,'msg':'Message Three','receiver':'Receiver One','receiver_id':1,'sender':'Sender One','sender_id':1}]
# Clean up
- cd: r.db('test').table_drop('test3')
ot: partial({'tables_dropped':1})