public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('superhero')->eq('Iron Man'))->count(), 1.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(function ($x) { return $x('superhero')->ne('Iron Man'); })->count(), 2.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'))->count(), 0.0); $caught = false; try { $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'), r\error())->count(), 0.0); } catch (r\RqlServerError $e) { $caught = true; } if (!$caught) { echo "Filter with default rrror() did not throw."; } $caught = false; try { $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'), r\error('msg'))->count(), 0.0); } catch (r\RqlServerError $e) { $caught = true; } if (!$caught) { echo "Filter with default rrror() did not throw."; } $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'), true)->count(), 3.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'), r\expr('true'))->count(), 3.0); }
public function run() { // Test management operations r\dbCreate('tableTest')->run($this->conn); $this->checkQueryResult(r\db('tableTest')->tableCreate('t1', array('durability' => 'soft', 'primary_key' => 'p'))->pluck('tables_created'), array('tables_created' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->insert(array('p' => 'foo')), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 0, 'inserted' => 1, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->rebalance()->pluck('rebalanced'), array('rebalanced' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->reconfigure(array('shards' => 1, 'replicas' => 1))->pluck('reconfigured'), array('reconfigured' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->wait()->pluck('ready'), array('ready' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->wait(array('wait_for' => "all_replicas_ready"))->pluck('ready'), array('ready' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->config()->pluck('name'), array('name' => "t1")); $this->checkQueryResult(r\db('tableTest')->table('t1')->status()->getField('status')->pluck('all_replicas_ready'), array('all_replicas_ready' => true)); $this->checkQueryResult(r\db('tableTest')->tableList(), array('t1')); // TODO: These index tests are kind of duplicates of IndexTest... $this->checkQueryResult(r\db('tableTest')->table('t1')->indexCreate('akey'), array('created' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexCreate('bfun', r\row('p')), array('created' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexCreate('cfun', function ($r) { return r\expr(5); }), array('created' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexList(), array('akey', 'bfun', 'cfun')); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexDrop('akey'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexDrop('bfun'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexDrop('cfun'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->sync(), array('synced' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1', false)->count(), 1.0); $this->checkQueryResult(r\db('tableTest')->table('t1', true)->count(), 1.0); $this->checkQueryResult(r\db('tableTest')->table('t1', array("use_outdated" => true))->count(), 1.0); $this->checkQueryResult(r\db('tableTest')->tableDrop('t1')->pluck('tables_dropped'), array('tables_dropped' => 1.0)); r\dbDrop('tableTest')->run($this->conn); // Test general whole-table queries $this->requireDataset('Heroes'); $testResult = r\db('Heroes')->table('marvel')->orderBy('superhero')->run($this->conn); $this->checkQueryResult(r\expr($testResult)->count(), 3.0); $this->datasets['Heroes']->reset(); }
public function run() { $this->requireDataset('Control'); $this->requireDataset('Heroes'); $this->checkQueryResult(r\rDo(array(1, 2, 3), function ($x, $y, $z) { return $x->mul($y->add($z)); }), 5.0); $this->checkQueryResult(r\branch(r\expr(true), r\expr('true'), r\expr('false')), 'true'); $this->checkQueryResult(r\branch(r\expr(false), r\expr('true'), r\expr('false')), 'false'); $this->checkQueryResult(r\expr(array(1, 2, 3))->rForeach(function ($x) { return r\db('Control')->table('t1')->insert(array('x' => $x)); })->attr('inserted'), 3.0); $this->checkQueryResult(r\db('Control')->table('t1')->map(r\row('x')), array(1, 2, 3)); $errorCaught = false; try { r\error('ERRRRRR')->run($this->conn); } catch (r\RqlUserError $e) { $errorCaught = true; } if (!$errorCaught) { echo "rrror() did not throw an error.\n"; } // Js is also tested separately in JsTest $this->checkQueryResult(r\js("'str1' + 'str2'"), 'str1str2'); $this->checkQueryResult(r\expr('5.0')->coerceTo('number'), 5.0); $this->checkQueryResult(r\expr(5.0)->coerceTo('string'), '5'); $this->checkQueryResult(r\expr(5.0)->typeOf(), 'NUMBER'); $this->checkQueryResult(r\expr('foo')->typeOf(), 'STRING'); $this->checkQueryResult(r\expr(null)->typeOf(), 'NULL'); $this->checkQueryResult(r\expr(array(1, 2, 3))->typeOf(), 'ARRAY'); $this->checkQueryResult(r\expr(array('x' => 1))->typeOf(), 'OBJECT'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->info(), array('type' => "TABLE", 'primary_key' => 'superhero', 'name' => 'marvel', 'indexes' => array(), 'db' => array('type' => 'DB', 'name' => 'Heroes'))); $this->datasets['Control']->reset(); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexList()->count(), 0.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexCreate('superpower'), array('created' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexCreate('foo', function ($r) { return r\expr(5); }), array('created' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexCreateMulti('superpower_m'), array('created' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexCreateMulti('foo_m', function ($r) { return r\expr(array(5, 6)); }), array('created' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexList()->count(), 4.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexWait('superpower')->pluck(array('index', 'ready')), array(array('index' => 'superpower', 'ready' => 1.0))); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexStatus('superpower')->pluck(array('index', 'ready')), array(array('index' => 'superpower', 'ready' => 1.0))); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexWait(array('superpower', 'foo'))->pluck(array('index', 'ready')), array(array('index' => 'superpower', 'ready' => 1.0), array('index' => 'foo', 'ready' => 1.0))); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexStatus(array('superpower', 'foo'))->pluck(array('index', 'ready')), array(array('index' => 'superpower', 'ready' => 1.0), array('index' => 'foo', 'ready' => 1.0))); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexWait()->pluck(array('index', 'ready')), array(array('index' => 'superpower', 'ready' => 1.0), array('index' => 'foo', 'ready' => 1.0), array('index' => 'superpower_m', 'ready' => 1.0), array('index' => 'foo_m', 'ready' => 1.0))); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexStatus()->pluck(array('index', 'ready')), array(array('index' => 'superpower', 'ready' => 1.0), array('index' => 'foo', 'ready' => 1.0), array('index' => 'superpower_m', 'ready' => 1.0), array('index' => 'foo_m', 'ready' => 1.0))); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexDrop('superpower'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexDrop('foo'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexDrop('superpower_m'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexDrop('foo_m'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexList()->count(), 0.0); $this->datasets['Heroes']->reset(); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->map(function ($hero) { return $hero('combatPower')->add($hero('compassionPower')->mul(2)); }), array(7.0, 9.0, 5.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->map(r\row('combatPower')->add(r\row('compassionPower')->mul(2))), array(7.0, 9.0, 5.0)); $this->checkQueryResult(r\expr(array(r\db('Heroes')->table('marvel')->coerceTo('array'), r\db('Heroes')->table('marvel')->coerceTo('array')))->concatMap(function ($hero) { return $hero->pluck('superhero'); })->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman', 'Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\expr(array(r\db('Heroes')->table('marvel')->coerceTo('array'), r\db('Heroes')->table('marvel')->coerceTo('array')))->concatMap(r\row()->pluck('superhero'))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman', 'Iron Man', 'Wolverine', 'Spiderman')); // Regression test for #62 $this->checkQueryResult(r\expr(array(1, 2, 3))->map(r\branch(r\expr(true), function ($x) { return $x; }, function ($x) { return $x; })), array(1.0, 2.0, 3.0)); $this->checkQueryResult(r\mapMultiple(array(r\range(1, 4), r\range(2, 5)), function ($x, $y) { return $x->add($y); }), array(3, 5, 7)); $this->checkQueryResult(r\range(1, 4)->mapMultiple(array(r\range(2, 5)), function ($x, $y) { return $x->add($y); }), array(3, 5, 7)); $this->checkQueryResult(r\range(1, 4)->mapMultiple(r\range(2, 5), function ($x, $y) { return $x->add($y); }), array(3, 5, 7)); $this->checkQueryResult(r\range(1, 4)->mapMultiple(array(r\range(2, 5), r\range(1, 4)), function ($x, $y, $z) { return $x->add($y)->sub($z); }), array(2, 3, 4)); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->get('Wolverine')->replace(array('superhero' => 'Wolverine', 'age' => 30)), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 1, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->get('Wolverine')->replace(array('superhero' => 'Wolverine', 'age' => r\js('35')), true), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 1, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->datasets['Heroes']->reset(); }
public function run() { // Test management operations r\dbCreate('tableTest')->run($this->conn); $this->checkQueryResult(r\db('tableTest')->tableCreate('t1', array('hard_durability' => false, 'cache_size' => 8, 'primary_key' => 'p')), array('created' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->insert(array('p' => 'foo')), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 0, 'inserted' => 1, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('tableTest')->tableList(), array('t1')); // TODO: These index tests are kind of duplicates of IndexTest... $this->checkQueryResult(r\db('tableTest')->table('t1')->indexCreate('akey'), array('created' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexCreate('bfun', r\row('p')), array('created' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexCreate('cfun', function ($r) { return r\expr(5); }), array('created' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexList(), array('akey', 'bfun', 'cfun')); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexDrop('akey'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexDrop('bfun'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('tableTest')->table('t1')->indexDrop('cfun'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('tableTest')->tableDrop('t1'), array('dropped' => 1.0)); r\dbDrop('tableTest')->run($this->conn); // Test general whole-table queries $this->requireDataset('Heroes'); $testResult = r\db('Heroes')->table('marvel')->orderBy('superhero')->run($this->conn)->toNative(); $this->checkQueryResult(r\expr($testResult)->count(), 3.0); $this->datasets['Heroes']->reset(); }
public function run() { $this->requireDataset('Huge'); $doc = array('key' => str_repeat("var", 1000)); $docs = array_fill(0, 5000, $doc); // Test 1: Retrieve only the first 100 results. Then delete the cursor. This should trigger a stop message. $cursor = r\db('Huge')->table('t5000')->without('id')->run($this->conn); $i = 0; foreach ($cursor as $val) { if (!$this->compareArrays($doc, $val)) { echo "Read wrong value.\n"; } if ($i++ >= 100) { break; } } unset($cursor); // Test 2: Call the cursor's close() method. The cursor should not return any more rows. $cursor = r\db('Huge')->table('t5000')->without('id')->run($this->conn); $cursor->close(); if (!$this->compareArrays(array(), $cursor->toArray())) { echo "Cursor still returned results after it was closed.\n"; } // Test 3: Retrieve all results. This tests paging. $this->checkQueryResult(r\db('Huge')->table('t5000')->without('id'), $docs); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->get('Wolverine')->delete(), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 0, 'inserted' => 0, 'errors' => 0, 'deleted' => 1)); $count = r\db('Heroes')->table('marvel')->count()->run($this->conn); $this->checkQueryResult(r\db('Heroes')->table('marvel')->delete(array('durability' => 'soft')), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 0, 'inserted' => 0, 'errors' => 0, 'deleted' => $count)); $this->datasets['Heroes']->reset(); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->insert(array('superhero' => 'Iron Man', 'superpower' => 'Arc Reactor', 'combatPower' => 2.0, 'compassionPower' => 1.5), true), array('unchanged' => 1, 'skipped' => 0, 'replaced' => 0, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->insert(array('superhero' => 'Iron Man', 'superpower' => 'Suit'), true), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 1, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->insert(array('superhero' => 'Pepper', 'superpower' => 'Stark Industries'), true), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 0, 'inserted' => 1, 'errors' => 0, 'deleted' => 0)); $this->datasets['Heroes']->reset(); }
public function run() { $this->checkQueryResult(r\dbCreate('dbTest')->pluck('dbs_created'), array('dbs_created' => 1.0)); $this->checkQueryResult(r\db('dbTest')->wait(), array('ready' => 0.0)); $this->checkQueryResult(r\db('dbTest')->rebalance(), array()); $this->checkQueryResult(r\db('dbTest')->reconfigure(array('shards' => 1, 'replicas' => 1)), array()); $this->checkQueryResult(r\dbDrop('dbTest')->pluck('dbs_dropped'), array('dbs_dropped' => 1.0)); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('superhero')->eq('Iron Man'))->count(), 1.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(function ($x) { return $x('superhero')->ne('Iron Man'); })->count(), 2.0); }
protected function create() { // Prepare a table with 5000 rows r\dbCreate('Huge')->run($this->conn); r\db('Huge')->tableCreate('t5000', array('durability' => 'soft'))->run($this->conn); $doc = array('key' => str_repeat("var", 1000)); $docs = array_fill(0, 5000, $doc); r\db('Huge')->table('t5000')->insert($docs)->run($this->conn); }
protected function create() { // Prepare a table with 5000 rows r\dbCreate('Huge')->run($this->conn); r\db('Huge')->tableCreate('t5000', array('hard_durability' => false, 'cache_size' => 128))->run($this->conn); $doc = array('key' => 'val'); $docs = array_fill(0, 5000, $doc); r\db('Huge')->table('t5000')->insert($docs)->run($this->conn); }
protected function create() { r\dbCreate('Heroes')->run($this->conn); r\db('Heroes')->tableCreate('marvel', array('primary_key' => 'superhero'))->run($this->conn); r\db('Heroes')->tableCreate('dc_universe', array('primary_key' => 'name'))->run($this->conn); $marvelTable = r\db('Heroes')->table('marvel'); $dcUniverseTable = r\db('Heroes')->table('dc_universe'); $marvelTable->insert(array('superhero' => 'Iron Man', 'superpower' => 'Arc Reactor', 'combatPower' => 2.0, 'compassionPower' => 1.5))->run($this->conn); $marvelTable->insert(array(array('superhero' => 'Wolverine', 'superpower' => 'Adamantium', 'combatPower' => 5.0, 'compassionPower' => 2.0), array('superhero' => 'Spiderman', 'superpower' => 'spidy sense', 'combatPower' => 2.0, 'compassionPower' => 2.5)))->run($this->conn); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->get('Wolverine')->update(array('age' => 30)), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 1, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->update(function ($r) { return $r->merge(array('age' => 5)); }), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 3, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->update(array('age' => r\row('age')->add(1))), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 3, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->update(array('age' => r\row('age')->add(r\js('1'))), array('durability' => 'soft', 'non_atomic' => true)), array('unchanged' => 0, 'skipped' => 0, 'replaced' => 3, 'inserted' => 0, 'errors' => 0, 'deleted' => 0)); $this->datasets['Heroes']->reset(); }
public function run() { $this->requireDataset('Heroes'); r\db('Heroes')->table('marvel')->indexCreate('test', function ($x) { return r\expr('5'); })->run($this->conn); $this->checkQueryResult(r\db('Heroes')->table('marvel')->getAll('5', 'test')->count(), 3.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->getAll('Iron Man')->count(), 1.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->get('Iron Man'), array('superhero' => 'Iron Man', 'superpower' => 'Arc Reactor', 'combatPower' => 2.0, 'compassionPower' => 1.5)); r\db('Heroes')->table('marvel')->indexDrop('test')->run($this->conn); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->map(function ($hero) { return $hero('combatPower')->add($hero('compassionPower')->mul(2)); }), array(7.0, 9.0, 5.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->map(r\row('combatPower')->add(r\row('compassionPower')->mul(2))), array(7.0, 9.0, 5.0)); $this->checkQueryResult(r\expr(array(r\db('Heroes')->table('marvel')->coerceTo('array'), r\db('Heroes')->table('marvel')->coerceTo('array')))->concatMap(function ($hero) { return $hero->pluck('superhero'); })->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman', 'Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\expr(array(r\db('Heroes')->table('marvel')->coerceTo('array'), r\db('Heroes')->table('marvel')->coerceTo('array')))->concatMap(r\row()->pluck('superhero'))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman', 'Iron Man', 'Wolverine', 'Spiderman')); }
public function run() { $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexList()->count(), 0.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexCreate('superpower'), array('created' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexCreate('foo', function ($r) { return r\expr(5); }), array('created' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexList()->count(), 2.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexDrop('superpower'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexDrop('foo'), array('dropped' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexList()->count(), 0.0); $this->datasets['Heroes']->reset(); }
protected function create() { r\dbCreate('Geo')->run($this->conn); r\db('Geo')->tableCreate('geo')->run($this->conn); $geoTable = r\db('Geo')->table('geo'); $geoTable->insert(array('geo' => r\point(1.0, 1.0)))->run($this->conn); $geoTable->insert(array('geo' => r\point(1.0, 0.0)))->run($this->conn); $geoTable->indexCreateGeo('geo')->run($this->conn); $geoTable->indexCreateMultiGeo('mgeo', function ($x) { return r\expr(array($x('geo'))); })->run($this->conn); $geoTable->indexWait('geo')->run($this->conn); $geoTable->indexWait('mgeo')->run($this->conn); }
public function run() { $this->requireDataset('Heroes'); r\db('Heroes')->table('marvel')->indexCreate('test', function ($x) { return r\expr('5'); })->run($this->conn); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('5', '5', 'test')->count(), 3.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('A', 'Z')->count(), 3.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('I', 'J')->count(), 1.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('I', 'I')->count(), 0.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between(null, 'J')->count(), 1.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('J', null)->count(), 2.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between(null, null)->count(), 3.0); r\db('Heroes')->table('marvel')->indexDrop('test')->run($this->conn); }
public function run() { $this->requireDataset('Heroes'); // FIXME: These checks don't actually verify the ordering (and the ones we specify here as reference are wrong)... $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array('combatPower', 'compassionPower'))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array(r\Desc('combatPower'), r\Desc('compassionPower')))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array(r\Asc('combatPower'), r\Asc('compassionPower')))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->skip(1)->map(r\row('superhero')), array('Spiderman', 'Wolverine')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->limit(1)->map(r\row('superhero')), array('Iron Man')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->nth(1)->attr('superhero'), 'Spiderman'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->nth(-1)->attr('superhero'), 'Wolverine'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->slice(1)->map(r\row('superhero')), array('Spiderman', 'Wolverine')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->slice(1, 1)->map(r\row('superhero')), array('Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->pluck('superhero')->union(r\expr(array(array('superhero' => 'foo'))))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman', 'foo')); }
protected function create() { r\dbCreate('Joins')->run($this->conn); r\db('Joins')->tableCreate('t1')->run($this->conn); r\db('Joins')->tableCreate('t2')->run($this->conn); $t1 = r\db('Joins')->table('t1'); $t2 = r\db('Joins')->table('t2'); $t1->indexCreate('other')->run($this->conn); $t2->indexCreate('other')->run($this->conn); $t1->insert(array('id' => 1, 'other' => 'a'))->run($this->conn); $t1->insert(array('id' => 2, 'other' => 'a'))->run($this->conn); $t1->insert(array('id' => 3, 'other' => 'b'))->run($this->conn); $t2->insert(array('id' => 'a', 'other' => 1))->run($this->conn); $t2->insert(array('id' => 'b', 'other' => 1))->run($this->conn); $t2->insert(array('id' => 'c', 'other' => 5))->run($this->conn); }
public function run() { $this->checkQueryResult(r\expr(array(1, 2, 3, 4))->reduce(function ($a, $b) { return $a->add($b); }), 10.0); $this->checkQueryResult(r\expr(array(1, 2, 3, 4))->count(), 4.0); $this->checkQueryResult(r\expr(array(1, 2, 3, 4))->count(2), 1.0); $this->checkQueryResult(r\expr(array(1, 2, 3, 4))->count(r\row()->lt(3)), 2.0); $this->checkQueryResult(r\expr(array(1, 2, 2, 4))->distinct(), array(1, 2, 4)); $this->checkQueryResult(r\expr(array(1, 2, 2, 4))->group(function ($r) { return $r; })->map(function ($r) { return $r; })->reduce(function ($a, $b) { return $a->add($b); })->ungroup(), array(array('reduction' => 1, 'group' => 1), array('reduction' => 4, 'group' => 2), array('reduction' => 4, 'group' => 4))); $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 2), array('v' => 4)))->group('v')->count()->ungroup(), array(array('reduction' => 1, 'group' => 1), array('reduction' => 2, 'group' => 2), array('reduction' => 1, 'group' => 4))); $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 2), array('v' => 4)))->group('v')->sum('v')->ungroup(), array(array('reduction' => 1, 'group' => 1), array('reduction' => 4, 'group' => 2), array('reduction' => 4, 'group' => 4))); $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 2), array('v' => 4)))->group('v')->avg('v')->ungroup(), array(array('reduction' => 1, 'group' => 1), array('reduction' => 2, 'group' => 2), array('reduction' => 4, 'group' => 4))); $this->checkQueryResult(r\expr(array(array('v' => 1, 'x' => 1), array('v' => 2, 'x' => 2), array('v' => 2, 'x' => 3), array('v' => 4, 'x' => 4)))->group(array('v', 'x'))->count()->ungroup(), array(array('reduction' => 1, 'group' => array('v' => 1, 'x' => 1)), array('reduction' => 1, 'group' => array('v' => 2, 'x' => 2)), array('reduction' => 1, 'group' => array('v' => 2, 'x' => 3)), array('reduction' => 1, 'group' => array('v' => 4, 'x' => 4)))); $this->checkQueryResult(r\expr(array(1, 2, 3))->count(), 3.0); $this->checkQueryResult(r\expr(array(1, 2, 3))->sum(), 6.0); $this->checkQueryResult(r\expr(array(1, 2, 3))->avg(), 2.0); $this->checkQueryResult(r\expr(array(1, 2, 3))->max(), 3.0); $this->checkQueryResult(r\expr(array(1, 2, 3))->min(), 1.0); $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 3)))->sum('v'), 6.0); $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 3)))->avg('v'), 2.0); $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 3)))->max('v'), array('v' => 3.0)); $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 3)))->min('v'), array('v' => 1.0)); $this->checkQueryResult(r\expr(array('a', 'b', 'c'))->contains('a'), true); $this->checkQueryResult(r\expr(array('a', 'b', 'c'))->contains('z'), false); $this->checkQueryResult(r\expr(array('a', 'b', 'c'))->contains(r\row()->eq('a')), true); $this->checkQueryResult(r\expr(array('a', 'b', 'c'))->contains(r\row()->eq('z')), false); $this->checkQueryResult(r\expr(array('a', 'b', 'c'))->contains(function ($x) { return $x->eq('a'); }), true); $this->checkQueryResult(r\expr(array('a', 'b', 'c'))->contains(function ($x) { return $x->eq('z'); }), false); $this->requireDataset('Heroes'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexCreate('combatPower'), array('created' => 1.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->indexWait('combatPower')->pluck(array('index', 'ready')), array(array('index' => 'combatPower', 'ready' => true))); $this->checkQueryResult(r\db('Heroes')->table('marvel')->distinct(array('index' => 'combatPower')), array(2.0, 5.0)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->max(array('index' => 'combatPower'))->getField("combatPower"), 5.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->min(array('index' => 'combatPower'))->getField("combatPower"), 2.0); $this->datasets['Heroes']->reset(); }
public function run() { $this->requireDataset('Heroes'); r\db('Heroes')->table('marvel')->indexCreate('test', function ($x) { return r\expr('5'); })->run($this->conn); r\db('Heroes')->table('marvel')->indexWait('test')->run($this->conn); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('5', '5', array('index' => 'test'))->count(), 0.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('5', '5', array('index' => 'test', 'right_bound' => 'closed'))->count(), 3.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('A', 'Z')->count(), 3.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('I', 'J')->count(), 1.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('I', 'I')->count(), 0.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between(r\minval(), 'J')->count(), 1.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between('J', r\maxval())->count(), 2.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->between(r\minval(), r\maxval())->count(), 3.0); r\db('Heroes')->table('marvel')->indexDrop('test')->run($this->conn); }
public function run() { $this->requireDataset('Control'); $this->requireDataset('Heroes'); $this->checkQueryResult(r\rDo(array(1, 2, 3), function ($x, $y, $z) { return $x->mul($y->add($z)); }), 5.0); $this->checkQueryResult(r\branch(r\expr(true), r\expr('true'), r\expr('false')), 'true'); $this->checkQueryResult(r\branch(r\expr(false), r\expr('true'), r\expr('false')), 'false'); $this->checkQueryResult(r\expr(array(1, 2, 3))->rForeach(function ($x) { return r\db('Control')->table('t1')->insert(array('x' => $x)); })->getField('inserted'), 3.0); $this->checkQueryResult(r\db('Control')->table('t1')->map(r\row('x')), array(1, 2, 3)); $errorCaught = false; try { r\error('ERRRRRR')->run($this->conn); } catch (r\RqlServerError $e) { $errorCaught = true; } if (!$errorCaught) { echo "rrror() did not throw an error.\n"; } // Js is also tested separately in JsTest $this->checkQueryResult(r\js("'str1' + 'str2'"), 'str1str2'); $this->checkQueryResult(r\expr('5.0')->coerceTo('number'), 5.0); $this->checkQueryResult(r\expr(5.0)->coerceTo('string'), '5'); $this->checkQueryResult(r\expr(5.0)->typeOf(), 'NUMBER'); $this->checkQueryResult(r\expr('foo')->typeOf(), 'STRING'); $this->checkQueryResult(r\expr(null)->typeOf(), 'NULL'); $this->checkQueryResult(r\expr(array(1, 2, 3))->typeOf(), 'ARRAY'); $this->checkQueryResult(r\expr(array('x' => 1))->typeOf(), 'OBJECT'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->info()->pluck(array('type', 'name')), array('type' => "TABLE", 'name' => 'marvel')); $this->checkQueryResult(r\expr(array('a' => 4))->getField('a')->rDefault(5), 4.0); $this->checkQueryResult(r\expr(array('a' => 4))->getField('b')->rDefault(5), 5.0); $this->checkQueryResult(r\expr(array('a' => 4))->getField('b')->rDefault(function ($e) { return r\expr(5); }), 5.0); $this->checkQueryResult(r\range()->limit(3), array(0, 1, 2)); $this->checkQueryResult(r\range(3), array(0, 1, 2)); $this->checkQueryResult(r\range(1, 3), array(1, 2)); $this->checkQueryResult(r\expr("123")->toJsonString(), "\"123\""); $this->datasets['Control']->reset(); }
public function run() { $this->requireDataset('Joins'); $this->checkQueryResult(r\db('Joins')->table('t1')->innerJoin(r\db('Joins')->table('t2'), function ($r1, $r2) { return $r1('other')->eq($r2('id')); }), array(array('left' => array('id' => 1, 'other' => 'a'), 'right' => array('id' => 'a', 'other' => 1)), array('left' => array('id' => 2, 'other' => 'a'), 'right' => array('id' => 'a', 'other' => 1)), array('left' => array('id' => 3, 'other' => 'b'), 'right' => array('id' => 'b', 'other' => 1)))); $this->checkQueryResult(r\db('Joins')->table('t1')->outerJoin(r\db('Joins')->table('t2'), function ($r1, $r2) { return $r1('other')->eq($r2('id')); }), array(array('left' => array('id' => 1, 'other' => 'a'), 'right' => array('id' => 'a', 'other' => 1)), array('left' => array('id' => 2, 'other' => 'a'), 'right' => array('id' => 'a', 'other' => 1)), array('left' => array('id' => 3, 'other' => 'b'), 'right' => array('id' => 'b', 'other' => 1)))); $this->checkQueryResult(r\db('Joins')->table('t2')->innerJoin(r\db('Joins')->table('t1'), function ($r1, $r2) { return $r1('other')->eq($r2('id')); }), array(array('right' => array('id' => 1, 'other' => 'a'), 'left' => array('id' => 'a', 'other' => 1)), array('right' => array('id' => 1, 'other' => 'a'), 'left' => array('id' => 'b', 'other' => 1)))); $this->checkQueryResult(r\db('Joins')->table('t2')->outerJoin(r\db('Joins')->table('t1'), function ($r1, $r2) { return $r1('other')->eq($r2('id')); }), array(array('right' => array('id' => 1, 'other' => 'a'), 'left' => array('id' => 'a', 'other' => 1)), array('right' => array('id' => 1, 'other' => 'a'), 'left' => array('id' => 'b', 'other' => 1)), array('left' => array('id' => 'c', 'other' => 5)))); $this->checkQueryResult(r\db('Joins')->table('t1')->eqJoin('other', r\db('Joins')->table('t2')), array(array('left' => array('id' => 1, 'other' => 'a'), 'right' => array('id' => 'a', 'other' => 1)), array('left' => array('id' => 2, 'other' => 'a'), 'right' => array('id' => 'a', 'other' => 1)), array('left' => array('id' => 3, 'other' => 'b'), 'right' => array('id' => 'b', 'other' => 1)))); $this->checkQueryResult(r\db('Joins')->table('t1')->eqJoin('id', r\db('Joins')->table('t2'), 'other'), array(array('left' => array('id' => 1, 'other' => 'a'), 'right' => array('id' => 'a', 'other' => 1)), array('left' => array('id' => 1, 'other' => 'a'), 'right' => array('id' => 'b', 'other' => 1)))); $this->checkQueryResult(r\db('Joins')->table('t1')->eqJoin('id', r\db('Joins')->table('t2'), 'other')->zip(), array(array('id' => 'a', 'other' => 1), array('id' => 'b', 'other' => 1))); }
public function run() { $this->requireDataset('Huge'); $doc = array('key' => 'val'); $docs = array_fill(0, 5000, $doc); // Test 1: Retrieve only the first 100 results. Then delete the cursor. This should trigger a stop message. $cursor = r\db('Huge')->table('t5000')->without('id')->run($this->conn); $i = 0; foreach ($cursor as $val) { if (!$this->compareArrays($doc, $val->toNative())) { echo "Read wrong value.\n"; } if ($i++ >= 100) { break; } } unset($cursor); // Test 1: Retrieve all results. This tests paging. $this->checkQueryResult(r\db('Huge')->table('t5000')->without('id'), $docs); }
public function run() { $this->checkQueryResult(r\geojson(array('type' => 'Point', 'coordinates' => array(0.0, 1.0))), array('$reql_type$' => 'GEOMETRY', 'type' => 'Point', 'coordinates' => array(0.0, 1.0))); $this->checkQueryResult(r\expr(array('$reql_type$' => 'GEOMETRY', 'type' => 'Point', 'coordinates' => array(0.0, 1.0)))->toGeojson(), array('type' => 'Point', 'coordinates' => array(0.0, 1.0))); $this->checkQueryResult(r\point(0.0, 1.0), array('$reql_type$' => 'GEOMETRY', 'type' => 'Point', 'coordinates' => array(0.0, 1.0))); $this->checkQueryResult(r\line(array(array(0.0, 0.0), array(0.0, 1.0), array(1.0, 1.0))), array('$reql_type$' => 'GEOMETRY', 'type' => 'LineString', 'coordinates' => array(array(0.0, 0.0), array(0.0, 1.0), array(1.0, 1.0)))); $this->checkQueryResult(r\line(array(array(0.0, 0.0), array(0.0, 1.0), array(1.0, 1.0)))->fill(), array('$reql_type$' => 'GEOMETRY', 'type' => 'Polygon', 'coordinates' => array(array(array(0.0, 0.0), array(0.0, 1.0), array(1.0, 1.0), array(0.0, 0.0))))); $this->checkQueryResult(r\polygon(array(array(0.0, 0.0), array(0.0, 1.0), array(1.0, 1.0))), array('$reql_type$' => 'GEOMETRY', 'type' => 'Polygon', 'coordinates' => array(array(array(0.0, 0.0), array(0.0, 1.0), array(1.0, 1.0), array(0.0, 0.0))))); $this->checkQueryResult(r\polygon(array(array(0.0, 0.0), array(0.0, 2.0), array(2.0, 2.0), array(2.0, 0.0)))->polygonSub(r\polygon(array(array(0.5, 0.5), array(0.5, 0.8), array(0.8, 0.8)))), array('$reql_type$' => 'GEOMETRY', 'type' => 'Polygon', 'coordinates' => array(array(array(0.0, 0.0), array(0.0, 2.0), array(2.0, 2.0), array(2.0, 0.0), array(0.0, 0.0)), array(array(0.5, 0.5), array(0.5, 0.8), array(0.8, 0.8), array(0.5, 0.5))))); // These might fail due to rounding issues, depending on the server's architecture $this->checkQueryResult(r\point(0.0, 1.0)->distance(r\point(1.0, 1.0))->coerceTo("STRING"), "111302.64933943081996"); $this->checkQueryResult(r\point(0.0, 1.0)->distance(r\point(1.0, 1.0), array("unit" => "km"))->coerceTo("STRING"), "111.30264933943082895"); $this->checkQueryResult(r\polygon(array(array(0.0, 0.0), array(0.0, 1.0), array(1.0, 1.0)))->intersects(r\line(array(array(0.0, 0.0), array(2.0, 2.0)))), true); $this->checkQueryResult(r\polygon(array(array(0.0, 0.0), array(0.0, 1.0), array(1.0, 1.0)))->includes(r\line(array(array(0.0, 0.0), array(2.0, 2.0)))), false); $this->checkQueryResult(r\circle(r\point(0.0, 0.0), 10.0)->intersects(r\line(array(array(0.1, 0.0), array(2.0, 2.0)))), false); $this->checkQueryResult(r\circle(r\point(0.0, 0.0), 10.0, array("unit" => "mi"))->intersects(r\line(array(array(0.1, 0.0), array(2.0, 2.0)))), true); $this->requireDataset('Geo'); $this->checkQueryResult(r\db('Geo')->table('geo')->getIntersecting(r\circle(r\point(0.0, 0.0), 150.0, array('unit' => "km")), array('index' => 'geo'))->count(), 1.0); $this->checkQueryResult(r\db('Geo')->table('geo')->getIntersecting(r\circle(r\point(0.0, 0.0), 150.0, array('unit' => "km")), array('index' => 'mgeo'))->count(), 1.0); // Again, there might be rounding issues on some servers $this->checkQueryResult(r\db('Geo')->table('geo')->getNearest(r\point(0.0, 0.0), array('max_dist' => 200.0, 'unit' => 'km', 'index' => 'geo'))->map(r\row('dist')->coerceTo('STRING')), array('111.3194907932735731', '156.89956829134027316')); }
public function run() { $this->requireDataset('Heroes'); // FIXME: These checks don't actually verify the ordering (and the ones we specify here as reference are wrong)... $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array('combatPower', 'compassionPower'))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array(r\Desc('combatPower'), r\Desc('compassionPower')))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array(r\Asc('combatPower'), r\Asc('compassionPower')))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array(r\row('combatPower'), r\row('compassionPower')))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array(r\Asc(r\row('combatPower')), r\Desc(r\row('compassionPower'))))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array(function ($x) { return $x('combatPower'); }, function ($x) { return $x('compassionPower'); }))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy(array(r\Asc(function ($x) { return $x('combatPower'); }), r\Desc(function ($x) { return $x('compassionPower'); })))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->skip(1)->map(r\row('superhero')), array('Spiderman', 'Wolverine')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->limit(1)->map(r\row('superhero')), array('Iron Man')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->nth(1)->getField('superhero'), 'Spiderman'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->nth(-1)->getField('superhero'), 'Wolverine'); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->slice(1)->map(r\row('superhero')), array('Spiderman', 'Wolverine')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->slice(1, 1)->map(r\row('superhero')), array()); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->slice(1, 2)->map(r\row('superhero')), array('Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->orderBy('superhero')->slice(1, 1, array('right_bound' => 'closed'))->map(r\row('superhero')), array('Spiderman')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->pluck('superhero')->union(r\expr(array(array('superhero' => 'foo'))))->map(r\row('superhero')), array('Iron Man', 'Wolverine', 'Spiderman', 'foo')); $this->checkQueryResult(r\db('Heroes')->table('marvel')->withFields(array('superhero', 'nemesis'))->count(), 0.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->withFields('superhero')->count(), 3.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->withFields(array('superhero' => true))->count(), 3.0); $this->checkQueryResult(r\expr(array('a', 'b', 'c'))->offsetsOf('c'), array(2)); $this->checkQueryResult(r\db('Heroes')->table('marvel')->isEmpty(), false); $this->checkQueryResult(r\expr(new r\ArrayDatum(array()))->isEmpty(), true); $this->checkQueryResult(r\db('Heroes')->table('marvel')->sample(1)->count(), 1.0); $this->checkQueryResult(r\db('Heroes')->table('marvel')->sample(3)->count(), 3.0); }