summaryrefslogtreecommitdiff
path: root/ext/librethinkdbxx/test/upstream/joins.yaml
blob: 80ffed504dcaa4615b65949c14d9b73c455365d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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})