<commit_before>desc: Tests that manipulation data in tables
tests:

    # Set up some data
    - cd: r.db('test').table_create('test1')
      ot: ({'created':1})
      def: tbl = r.db('test').table('test1')

    - cd: r.db('test').table_create('test2')
      ot: ({'created':1})
      def: tbl2 = r.db('test').table('test2')

    - cd: r.db('test').table_create('test3')
      ot: ({'created':1})
      def: tbl3 = r.db('test').table('test3')

    - py: tbl.insert([{'id':i, 'a':i%4} for i in xrange(100)])
      js: |
        tbl.insert(function(){
            var res = []
            for (var i = 0; i < 100; i++) {
                res.push({id:i, 'a':i%4});
            }
            return res;
        }())
      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})

    - py: tbl2.insert([{'id':i, 'b':i%4} for i in xrange(100)])
      js: |
        tbl2.insert(function(){
            var res = []
            for (var i = 0; i < 100; i++) {
                res.push({id:i, 'b':i%4});
            }
            return res;
        }())
      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})

    - py: tbl3.insert([{'id':i, 'a':i%4, 'b':{'c':i%5}} for i in xrange(100)])
      js: |
        tbl3.insert(function(){
            var res = []
            for (var i = 0; i < 100; i++) {
                res.push({id:i, 'a':i%4, 'b':{'c':i%5}});
            }
            return res;
        }())
      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})

    # Map-Reduce
    - py:
        - tbl.map(lambda row:row['id']).reduce(lambda a,b:a+b)
        - tbl.map(r.row['id']).reduce(lambda a,b:a+b)
      js:
        - tbl.map(function(row) { return row('id'); }).reduce(function(a,b) { return a.add(b); })
        - tbl.map(r.row('id')).reduce(function(a,b) { return a.add(b); })
      rb: tbl.map{ |row| row[:id] }.reduce{ |a, b| a + b }
      ot: 4950

    # Concat-map
    - py: tbl.concat_map(lambda row:[])
      js: tbl.concatMap(function(row) { return []; })
      rb: tbl.concat_map{ |row| [] }
      ot: ([])
    - def:
        py: ccm = tbl.concat_map(lambda row:[row['a'], (row['a'] + 1) % 4])
        js: ccm = tbl.concatMap(function(row) { return [row('a'), row('a').add(1).mod(4)]; })
        rb: ccm = tbl.concat_map{ |row| [row[:a], (row[:a] + 1) % 4] }
    - cd: ccm.count()
      ot: 200
    - py: ccm.reduce(lambda a,b:(a+b) % 4)
      js: ccm.reduce(function(a,b) { return a.add(b).mod(4); })
      rb: ccm.reduce{ |a, b| (a + b) % 4 }
      ot: 0

    # Order by
    - py: tbl.order_by('id')[0]
      js: tbl.orderBy('id').nth(0)
      rb: tbl.order_by(:id)[0]
      ot: ({'id':0, 'a':0})

    - py: "tbl.order_by(lambda x: x['id'])[0]"
      js: tbl.orderBy(function (x) { return x('id'); }).nth(0)
      rb: tbl.order_by{|x| x[:id]}[0]
      ot: ({'id':0, 'a':0})

    - cd: tbl.order_by('a', 'id').nth(0)
      ot: ({'id':0,'a':0})

    - py: "tbl.order_by(lambda x: [x['a'], x['id']])[0]"
      js: tbl.orderBy(function (x) { return [x('a'), x('id')]; }).nth(0)
      rb: tbl.order_by{|x| [x[:a], x[:id]]}[0]
      ot: ({'id':0, 'a':0})

    - cd: tbl.order_by(r.desc('a'), r.asc('id')).nth(0)
      ot: ({'id':3,'a':3})

    - py: "tbl.order_by(r.desc(lambda x: x['a']), 'id')[0]"
      js: tbl.orderBy(r.desc(function (x) { return x('a'); }), 'id').nth(0)
      rb: tbl.order_by(r.desc{|x| x[:a]}, 'id')[0]
      ot: ({'id':3, 'a':3})

    - cd: tbl.order_by(r.asc('a'), r.desc('id')).nth(0)
      ot: ({'id':96,'a':0})

    - cd: tbl.order_by('id').type_of()
      ot: "'SELECTION'"

    - cd: tbl.order_by('missing').order_by('id').nth(0)
      ot: ({'id':0, 'a':0})

    - cd: tbl.order_by('id', 'missing').nth(0)
      ot: ({'id':0, 'a':0})<commit_msg>Adds rql order_by test with 2 functions.<commit_after>desc: Tests that manipulation data in tables
tests:

    # Set up some data
    - cd: r.db('test').table_create('test1')
      ot: ({'created':1})
      def: tbl = r.db('test').table('test1')

    - cd: r.db('test').table_create('test2')
      ot: ({'created':1})
      def: tbl2 = r.db('test').table('test2')

    - cd: r.db('test').table_create('test3')
      ot: ({'created':1})
      def: tbl3 = r.db('test').table('test3')

    - py: tbl.insert([{'id':i, 'a':i%4} for i in xrange(100)])
      js: |
        tbl.insert(function(){
            var res = []
            for (var i = 0; i < 100; i++) {
                res.push({id:i, 'a':i%4});
            }
            return res;
        }())
      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})

    - py: tbl2.insert([{'id':i, 'b':i%4} for i in xrange(100)])
      js: |
        tbl2.insert(function(){
            var res = []
            for (var i = 0; i < 100; i++) {
                res.push({id:i, 'b':i%4});
            }
            return res;
        }())
      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})

    - py: tbl3.insert([{'id':i, 'a':i%4, 'b':{'c':i%5}} for i in xrange(100)])
      js: |
        tbl3.insert(function(){
            var res = []
            for (var i = 0; i < 100; i++) {
                res.push({id:i, 'a':i%4, 'b':{'c':i%5}});
            }
            return res;
        }())
      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})

    # Map-Reduce
    - py:
        - tbl.map(lambda row:row['id']).reduce(lambda a,b:a+b)
        - tbl.map(r.row['id']).reduce(lambda a,b:a+b)
      js:
        - tbl.map(function(row) { return row('id'); }).reduce(function(a,b) { return a.add(b); })
        - tbl.map(r.row('id')).reduce(function(a,b) { return a.add(b); })
      rb: tbl.map{ |row| row[:id] }.reduce{ |a, b| a + b }
      ot: 4950

    # Concat-map
    - py: tbl.concat_map(lambda row:[])
      js: tbl.concatMap(function(row) { return []; })
      rb: tbl.concat_map{ |row| [] }
      ot: ([])
    - def:
        py: ccm = tbl.concat_map(lambda row:[row['a'], (row['a'] + 1) % 4])
        js: ccm = tbl.concatMap(function(row) { return [row('a'), row('a').add(1).mod(4)]; })
        rb: ccm = tbl.concat_map{ |row| [row[:a], (row[:a] + 1) % 4] }
    - cd: ccm.count()
      ot: 200
    - py: ccm.reduce(lambda a,b:(a+b) % 4)
      js: ccm.reduce(function(a,b) { return a.add(b).mod(4); })
      rb: ccm.reduce{ |a, b| (a + b) % 4 }
      ot: 0

    # Order by
    - py: tbl.order_by('id')[0]
      js: tbl.orderBy('id').nth(0)
      rb: tbl.order_by(:id)[0]
      ot: ({'id':0, 'a':0})

    - py: "tbl.order_by(lambda x: x['id'])[0]"
      js: tbl.orderBy(function (x) { return x('id'); }).nth(0)
      rb: tbl.order_by{|x| x[:id]}[0]
      ot: ({'id':0, 'a':0})

    - cd: tbl.order_by('a', 'id').nth(0)
      ot: ({'id':0,'a':0})

    - py: "tbl.order_by(lambda x: [x['a'], x['id']])[0]"
      js: tbl.orderBy(function (x) { return [x('a'), x('id')]; }).nth(0)
      rb: tbl.order_by{|x| [x[:a], x[:id]]}[0]
      ot: ({'id':0, 'a':0})

    - cd: tbl.order_by(r.desc('a'), r.asc('id')).nth(0)
      ot: ({'id':3,'a':3})

    - py: "tbl.order_by(r.desc(lambda x: x['a']), lambda x: x['id'])[0]"
      js: tbl.orderBy(r.desc(function (x) { return x('a'); }), function (x) { return x('id'); }).nth(0)
      rb: tbl.order_by(r.desc{|x| x[:a]}, lambda {|x| x[:id]})[0]
      ot: ({'id':3, 'a':3})

    - cd: tbl.order_by(r.asc('a'), r.desc('id')).nth(0)
      ot: ({'id':96,'a':0})

    - cd: tbl.order_by('id').type_of()
      ot: "'SELECTION'"

    - cd: tbl.order_by('missing').order_by('id').nth(0)
      ot: ({'id':0, 'a':0})

    - cd: tbl.order_by('id', 'missing').nth(0)
      ot: ({'id':0, 'a':0})
{'fraction_non_alphanumeric': 0.27204892966360855, 'fraction_numerical': 0.03706422018348624, 'mean_word_length': 2.292790978654853, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '915523', 'n_tokens_mistral': 3667, 'n_tokens_neox': 3445, 'n_words': 635}