示例#1
0
 public function run()
 {
     $this->checkQueryResult(r\expr('a')->add('b'), 'ab');
     $this->checkQueryResult(r\expr(1)->add(2), 3.0);
     $this->checkQueryResult(r\expr(1)->sub(2), -1.0);
     $this->checkQueryResult(r\expr(1)->mul(2), 2.0);
     $this->checkQueryResult(r\expr(1)->div(2), 0.5);
     $this->checkQueryResult(r\expr(1)->mod(2), 1.0);
     $this->checkQueryResult(r\expr(true)->rAnd(true), true);
     $this->checkQueryResult(r\expr(true)->rAnd(false), false);
     $this->checkQueryResult(r\expr(false)->rAnd(true), false);
     $this->checkQueryResult(r\expr(false)->rAnd(false), false);
     $this->checkQueryResult(r\expr(true)->rOr(true), true);
     $this->checkQueryResult(r\expr(true)->rOr(false), true);
     $this->checkQueryResult(r\expr(false)->rOr(true), true);
     $this->checkQueryResult(r\expr(false)->rOr(false), false);
     $this->checkQueryResult(r\expr(1.0)->eq(1.0), true);
     $this->checkQueryResult(r\expr(1.0)->eq(-1.0), false);
     $this->checkQueryResult(r\expr(1.0)->ne(1.0), false);
     $this->checkQueryResult(r\expr(1.0)->ne(-1.0), true);
     $this->checkQueryResult(r\expr(1.0)->gt(1.0), false);
     $this->checkQueryResult(r\expr(1.0)->gt(-1.0), true);
     $this->checkQueryResult(r\expr(1.0)->ge(1.0), true);
     $this->checkQueryResult(r\expr(1.0)->ge(-1.0), true);
     $this->checkQueryResult(r\expr(1.0)->lt(1.0), false);
     $this->checkQueryResult(r\expr(1.0)->lt(-1.0), false);
     $this->checkQueryResult(r\expr(1.0)->le(1.0), true);
     $this->checkQueryResult(r\expr(1.0)->le(-1.0), false);
     $this->checkQueryResult(r\expr(true)->not(), false);
     $this->checkQueryResult(r\expr(false)->not(), true);
 }
示例#2
0
 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();
 }
示例#3
0
 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));
 }
示例#4
0
 public function testIndexFunction()
 {
     $res = $this->db()->table('t1')->indexCreate('cfun', function ($r) {
         return \r\expr(5);
     })->run($this->conn);
     $this->assertEquals(array('created' => 1.0), (array) $res);
 }
示例#5
0
 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();
 }
示例#6
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();
 }
示例#7
0
 public function testCustomConflict()
 {
     $res = $this->db()->table('marvel')->insert(array('superhero' => 'Iron Man'), array('conflict' => function ($x, $k, $o) {
         return \r\expr(null);
     }))->run($this->conn, $this->opts);
     $this->assertObStatus(array('deleted' => 1), $res);
 }
示例#8
0
 public function run()
 {
     $runOptions = array();
     $this->checkQueryResult(r\expr(null), null, $runOptions);
     $this->checkQueryResult(r\expr(true), true, $runOptions);
     $this->checkQueryResult(r\expr(false), false, $runOptions);
     $this->checkQueryResult(r\expr(0.5), 0.5, $runOptions);
     $this->checkQueryResult(r\expr(0), 0.0, $runOptions);
     $this->checkQueryResult(r\expr(-1), -1.0, $runOptions);
     $this->checkQueryResult(r\expr(1), 1.0, $runOptions);
     $this->checkQueryResult(r\expr(PHP_INT_MAX), (double) PHP_INT_MAX, $runOptions);
     // Depending on your platform, this might or might not pass
     $this->checkQueryResult(r\expr('0.5'), '0.5', $runOptions);
     $this->checkQueryResult(r\expr('foo'), 'foo', $runOptions);
     $this->checkQueryResult(r\expr(array('foo' => 'val')), array('foo' => 'val'), $runOptions);
     $this->checkQueryResult(r\expr(array('foo' => 7)), array('foo' => 7.0), $runOptions);
     $this->checkQueryResult(r\expr(array('foo' => null)), array('foo' => null), $runOptions);
     $this->checkQueryResult(r\expr(array('foo' => true)), array('foo' => true), $runOptions);
     $this->checkQueryResult(r\expr(array(1, 2, 3)), array(1.0, 2.0, 3.0), $runOptions);
     $this->checkQueryResult(r\expr(array(1, 'foo', true, null)), array(1.0, 'foo', true, null), $runOptions);
     // Special cases where we have to use manual Datum objects
     $this->checkQueryResult(new r\ArrayDatum(array()), array(), $runOptions);
     $this->checkQueryResult(new r\ObjectDatum(array()), array(), $runOptions);
     $this->checkQueryResult(new r\ObjectDatum(array(4 => new r\StringDatum('a'))), array(4 => 'a'), $runOptions);
     $this->checkQueryResult(new r\ObjectDatum(array('4' => new r\StringDatum('a'))), array('4' => 'a'), $runOptions);
     $this->checkQueryResult(r\expr(array(new r\ObjectDatum(array()))), array(array()), $runOptions);
     $this->checkQueryResult(r\expr((object) array()), array(), $runOptions);
     $this->checkQueryResult(r\expr(array((object) array())), array(array()), $runOptions);
 }
示例#9
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);
     $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);
 }
示例#10
0
 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();
 }
示例#11
0
 public function testReconnect()
 {
     $res1 = \r\expr(true)->run($this->conn);
     $this->conn->reconnect();
     $res2 = \r\expr(true)->run($this->conn);
     $this->assertTrue($res1);
     $this->assertTrue($res2);
 }
示例#12
0
 public function testRegression62()
 {
     $res = \r\expr(array(1, 2, 3))->map(\r\branch(\r\expr(true), function ($x) {
         return $x;
     }, function ($x) {
         return $x;
     }))->run($this->conn);
     $this->assertEquals(array(1.0, 2.0, 3.0), (array) $res);
 }
示例#13
0
 public function setUp()
 {
     $this->conn = $this->getConnection();
     $this->data = $this->useDataset('Heroes');
     $this->data->populate();
     $this->db()->table('marvel')->indexCreate('test', function ($x) {
         return \r\expr('5');
     })->run($this->conn);
     $this->db()->table('marvel')->indexWait('test')->run($this->conn);
 }
示例#14
0
 public function testFoldEmit()
 {
     $this->assertEquals(array(5, 6, 8, 11, 15), \r\expr(array(1, 2, 3, 4))->fold(5, function ($acc, $v) {
         return $acc->add($v);
     }, array('emit' => function ($o, $c, $n) {
         return array($o);
     }, 'final_emit' => function ($a) {
         return array($a);
     }))->run($this->conn));
 }
示例#15
0
 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);
 }
示例#16
0
 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'));
 }
示例#17
0
 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();
 }
示例#18
0
文件: Geo.php 项目: simensen/php-rql
 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);
 }
示例#19
0
 public function run()
 {
     $profile = r\expr(1)->profile($this->conn);
     if (!is_object($profile) && !is_array($profile)) {
         echo "Did not receive a query profile.\n";
     }
     $profile = r\expr(1)->profile($this->conn, null, $result);
     if (!is_object($profile) && !is_array($profile)) {
         echo "Did not receive a query profile.\n";
     }
     if ($result !== 1.0) {
         echo "Wrong result when profiling.\n";
     }
 }
示例#20
0
 public function run()
 {
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->filter(r\row()->getField('y')->eq(2))->pluck('x'), array(array('x' => 1)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->filter(r\row('y')->eq(2))->pluck('x'), array(array('x' => 1)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->pluck('x'), array(array('x' => 1)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->pluck(array('x', 'y')), array(array('x' => 1, 'y' => 2)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => array('a' => 2.1, 'b' => 2.2))))->pluck(array('x' => true)), array(array('x' => 1)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => array('a' => 2.1, 'b' => 2.2))))->pluck(array('y' => array('a', 'b'))), array(array('y' => array('a' => 2.1, 'b' => 2.2))));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => array('a' => 2.1, 'b' => 2.2))))->pluck(array('y' => array('b' => true))), array(array('y' => array('b' => 2.2))));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->without('x'), array(array('y' => 2)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->without(array('x', 'y')), array(array()));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => array('a' => 2.1, 'b' => 2.2))))->without(array('x' => true)), array(array('y' => array('a' => 2.1, 'b' => 2.2))));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => array('a' => 2.1, 'b' => 2.2))))->without(array('y' => array('a', 'b'))), array(array('x' => 1, 'y' => array())));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => array('a' => 2.1, 'b' => 2.2))))->without(array('y' => array('b' => true))), array(array('x' => 1, 'y' => array('a' => 2.1))));
     $this->checkQueryResult(r\expr(array('x' => 1))->merge(array('y' => 2)), array('x' => 1, 'y' => 2));
     $this->checkQueryResult(r\expr(array('x' => 1))->merge(r\expr(array('y' => 2))), array('x' => 1, 'y' => 2));
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => array('a' => 1, 'b' => 2)))->merge(array('y' => array('c' => 3))), array('x' => 1, 'y' => array('a' => 1, 'b' => 2, 'c' => 3)));
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => array('a' => 1, 'b' => 2)))->merge(array('y' => r\literal(array('c' => 3)))), array('x' => 1, 'y' => array('c' => 3)));
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => array('a' => 1, 'b' => 2)))->merge(array('y' => r\literal())), array('x' => 1));
     $this->checkQueryResult(r\expr(array(array('a' => 1), array('a' => 2)))->merge(function ($doc) {
         return array('b' => $doc('a')->add(1));
     }), array(array('a' => 1, 'b' => 2), array('a' => 2, 'b' => 3)));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->append(4), array(1, 2, 3, 4));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->append(r\expr(4)), array(1, 2, 3, 4));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->prepend(4), array(4, 1, 2, 3));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->prepend(r\expr(4)), array(4, 1, 2, 3));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->difference(array(1, 2)), array(3));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->difference(r\expr(array(1, 2))), array(3));
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => 2))->hasFields('x'), true);
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => 2))->hasFields('foo'), false);
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => 2))->hasFields(array('x', 'y')), true);
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => 2))->hasFields(array('x', 'foo')), false);
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => 2))->hasFields(array('x' => true)), true);
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => 2))->hasFields(array('foo' => true)), false);
     $this->checkQueryResult(r\expr(array(1, 2, 3))->setInsert(4), array(1, 2, 3, 4));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->setInsert(1), array(1, 2, 3));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->setUnion(array(1, 4)), array(1, 2, 3, 4));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->setIntersection(array(1, 4)), array(1));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->setDifference(array(1, 4)), array(2, 3));
     $this->checkQueryResult(r\expr(array('a' => 1, 'b' => 2, 'c' => 3))->keys(), array('a', 'b', 'c'));
     $this->checkQueryResult(r\expr(array("Iron Man", "Spider-Man"))->insertAt(1, "Hulk"), array("Iron Man", "Hulk", "Spider-Man"));
     $this->checkQueryResult(r\expr(array("Iron Man", "Spider-Man"))->spliceAt(1, array("Hulk", "Thor")), array("Iron Man", "Hulk", "Thor", "Spider-Man"));
     $this->checkQueryResult(r\expr(array("Iron Man", "Hulk", "Spider-Man"))->deleteAt(1), array("Iron Man", "Spider-Man"));
     $this->checkQueryResult(r\expr(array("Iron Man", "Hulk", "Thor", "Spider-Man"))->deleteAt(1, 2), array("Iron Man", "Thor", "Spider-Man"));
     // TODO: This is disabled due to a potential bug in the server as of RethinkDB 1.9.0: https://github.com/rethinkdb/rethinkdb/issues/1456
     /*$this->checkQueryResult(r\expr(array("Iron Man", "Hulk", "Thor", "Spider-Man"))->deleteAt(1,2, array('right_bound' => 'closed')),
       array("Iron Man", "Spider-Man"));*/
     $this->checkQueryResult(r\expr(array("Iron Man", "Bruce", "Spider-Man"))->changeAt(1, "Hulk"), array("Iron Man", "Hulk", "Spider-Man"));
 }
示例#21
0
 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'));
 }
示例#22
0
 public function run()
 {
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->filter(r\row()->attr('y')->eq(2))->pluck('x'), array(array('x' => 1)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->filter(r\row('y')->eq(2))->pluck('x'), array(array('x' => 1)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->pluck('x'), array(array('x' => 1)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->pluck(array('x', 'y')), array(array('x' => 1, 'y' => 2)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->without('x'), array(array('y' => 2)));
     $this->checkQueryResult(r\expr(array(array('x' => 1, 'y' => 2)))->without(array('x', 'y')), array(array()));
     $this->checkQueryResult(r\expr(array('x' => 1))->merge(array('y' => 2)), array('x' => 1, 'y' => 2));
     $this->checkQueryResult(r\expr(array('x' => 1))->merge(r\expr(array('y' => 2))), array('x' => 1, 'y' => 2));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->append(4), array(1, 2, 3, 4));
     $this->checkQueryResult(r\expr(array(1, 2, 3))->append(r\expr(4)), array(1, 2, 3, 4));
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => 2))->contains('x'), true);
     $this->checkQueryResult(r\expr(array('x' => 1, 'y' => 2))->contains('foo'), false);
 }
示例#23
0
 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);
 }
示例#24
0
 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();
 }
示例#25
0
 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);
 }
示例#26
0
 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();
 }
示例#27
0
 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))->reduce(function ($a, $b) {
         return $a->add($b);
     }, 5), 15.0);
     $this->checkQueryResult(r\expr(array(1, 2, 3, 4))->count(), 4.0);
     $this->checkQueryResult(r\expr(array(1, 2, 2, 4))->distinct(), array(1, 2, 4));
     $this->checkQueryResult(r\expr(array(1, 2, 2, 4))->groupedMapReduce(function ($r) {
         return $r;
     }, function ($r) {
         return $r;
     }, function ($a, $b) {
         return $a->add($b);
     }), 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)))->groupBy('v', r\count()), array(array('reduction' => 1, 'group' => array(1)), array('reduction' => 2, 'group' => array(2)), array('reduction' => 1, 'group' => array(4))));
     $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 2), array('v' => 4)))->groupBy('v', r\sum('v')), array(array('reduction' => 1, 'group' => array(1)), array('reduction' => 4, 'group' => array(2)), array('reduction' => 4, 'group' => array(4))));
     $this->checkQueryResult(r\expr(array(array('v' => 1), array('v' => 2), array('v' => 2), array('v' => 4)))->groupBy('v', r\avg('v')), array(array('reduction' => 1, 'group' => array(1)), array('reduction' => 2, 'group' => array(2)), array('reduction' => 4, 'group' => array(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)))->groupBy(array('v', 'x'), r\count()), array(array('reduction' => 1, 'group' => array(1, 1)), array('reduction' => 1, 'group' => array(2, 2)), array('reduction' => 1, 'group' => array(2, 3)), array('reduction' => 1, 'group' => array(4, 4))));
 }
示例#28
0
 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'));
 }
示例#29
0
 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);
 }
示例#30
0
 public function testChangeAt()
 {
     $res = \r\expr(array('Iron Man', 'Bruce', 'Spider-Man'))->changeAt(1, 'Hulk')->run($this->conn);
     $this->assertEquals(array('Iron Man', 'Hulk', 'Spider-Man'), (array) $res);
 }