From 51128dec586c7db1cfa2f213249384a02719e5b7 Mon Sep 17 00:00:00 2001 From: Lexx Date: Fri, 15 Jul 2016 02:16:41 +0300 Subject: [PATCH 1/9] Update ValuedQuery.php Made it more compatible with the original api --- rdb/ValuedQuery/ValuedQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rdb/ValuedQuery/ValuedQuery.php b/rdb/ValuedQuery/ValuedQuery.php index fd983a6..1d1c312 100644 --- a/rdb/ValuedQuery/ValuedQuery.php +++ b/rdb/ValuedQuery/ValuedQuery.php @@ -214,9 +214,9 @@ public function distinct($opts = null) { return new Distinct($this, $opts); } - public function group($groupOn) + public function group($fieldOrFunction, $groupOn) { - return new Group($this, $groupOn); + return new Group($this, $fieldOrFunction, $groupOn); } public function ungroup() { From 3c0920d30357e5c24543a065f6432e1c5cfaf9e5 Mon Sep 17 00:00:00 2001 From: Lexx Date: Fri, 15 Jul 2016 02:18:24 +0300 Subject: [PATCH 2/9] Update Group.php Made it more compatible with the original api --- rdb/Queries/Aggregations/Group.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rdb/Queries/Aggregations/Group.php b/rdb/Queries/Aggregations/Group.php index 9357573..4d8d17d 100644 --- a/rdb/Queries/Aggregations/Group.php +++ b/rdb/Queries/Aggregations/Group.php @@ -7,15 +7,19 @@ class Group extends ValuedQuery { - public function __construct(ValuedQuery $sequence, $groupOn) + public function __construct(ValuedQuery $sequence, $fieldOrFunction, $groupOn) { - if (!is_array($groupOn)) { - $groupOn = array($groupOn); - } + array_unshift($groupOn, $fieldOrFunction); + if (isset($groupOn['index'])) { $this->setOptionalArg('index', $this->nativeToDatum($groupOn['index'])); unset($groupOn['index']); } + + if (isset($groupOn['multi'])) { + $this->setOptionalArg('multi', $this->nativeToDatum($groupOn['multi'])); + unset($groupOn['multi']); + } $this->setPositionalArg(0, $sequence); $i = 1; From a0efaa89c27d546249c597dc54285e9930be3596 Mon Sep 17 00:00:00 2001 From: Lexx Date: Fri, 15 Jul 2016 02:18:52 +0300 Subject: [PATCH 3/9] Update Group.php --- rdb/Queries/Aggregations/Group.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdb/Queries/Aggregations/Group.php b/rdb/Queries/Aggregations/Group.php index 4d8d17d..a35de29 100644 --- a/rdb/Queries/Aggregations/Group.php +++ b/rdb/Queries/Aggregations/Group.php @@ -7,7 +7,7 @@ class Group extends ValuedQuery { - public function __construct(ValuedQuery $sequence, $fieldOrFunction, $groupOn) + public function __construct(ValuedQuery $sequence, $fieldOrFunction, $groupOn = []) { array_unshift($groupOn, $fieldOrFunction); From 3167e62e48726b06618857149fef1e55c8c64fc7 Mon Sep 17 00:00:00 2001 From: Lexx Date: Fri, 15 Jul 2016 02:21:11 +0300 Subject: [PATCH 4/9] Update ValuedQuery.php --- rdb/ValuedQuery/ValuedQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdb/ValuedQuery/ValuedQuery.php b/rdb/ValuedQuery/ValuedQuery.php index 1d1c312..47a0cf8 100644 --- a/rdb/ValuedQuery/ValuedQuery.php +++ b/rdb/ValuedQuery/ValuedQuery.php @@ -214,7 +214,7 @@ public function distinct($opts = null) { return new Distinct($this, $opts); } - public function group($fieldOrFunction, $groupOn) + public function group($fieldOrFunction, $groupOn = []) { return new Group($this, $fieldOrFunction, $groupOn); } From 68ce683217373e846aa5bb72bb76d1d64e8c7bc5 Mon Sep 17 00:00:00 2001 From: Lexx Date: Mon, 18 Jul 2016 01:03:31 +0300 Subject: [PATCH 5/9] Update NumberDatum.php --- rdb/Datum/NumberDatum.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rdb/Datum/NumberDatum.php b/rdb/Datum/NumberDatum.php index 82189ce..39513e8 100644 --- a/rdb/Datum/NumberDatum.php +++ b/rdb/Datum/NumberDatum.php @@ -9,13 +9,13 @@ class NumberDatum extends Datum { public function encodeServerRequest() { - return (float)$this->getValue(); + return $this->getValue(); } public static function decodeServerResponse($json) { $result = new NumberDatum(); - $result->setValue((float)$json); + $result->setValue($json); return $result; } From 528184da6041cddb8037566ad19edbbe3692f5ad Mon Sep 17 00:00:00 2001 From: Lexx Date: Thu, 15 Sep 2016 21:39:50 +0300 Subject: [PATCH 6/9] [] to array() --- rdb/ValuedQuery/ValuedQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdb/ValuedQuery/ValuedQuery.php b/rdb/ValuedQuery/ValuedQuery.php index 47a0cf8..b809f29 100644 --- a/rdb/ValuedQuery/ValuedQuery.php +++ b/rdb/ValuedQuery/ValuedQuery.php @@ -214,7 +214,7 @@ public function distinct($opts = null) { return new Distinct($this, $opts); } - public function group($fieldOrFunction, $groupOn = []) + public function group($fieldOrFunction, $groupOn = array()) { return new Group($this, $fieldOrFunction, $groupOn); } From 2110d06433b8fe0db8ce31bf3973529b717d41bc Mon Sep 17 00:00:00 2001 From: Lexx Date: Thu, 15 Sep 2016 21:40:34 +0300 Subject: [PATCH 7/9] [] to array() --- rdb/Queries/Aggregations/Group.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdb/Queries/Aggregations/Group.php b/rdb/Queries/Aggregations/Group.php index a35de29..51f88d7 100644 --- a/rdb/Queries/Aggregations/Group.php +++ b/rdb/Queries/Aggregations/Group.php @@ -7,7 +7,7 @@ class Group extends ValuedQuery { - public function __construct(ValuedQuery $sequence, $fieldOrFunction, $groupOn = []) + public function __construct(ValuedQuery $sequence, $fieldOrFunction, $groupOn = array()) { array_unshift($groupOn, $fieldOrFunction); From 9c464c1bc9adf0b2dbe186804c8c3104f68364ce Mon Sep 17 00:00:00 2001 From: lexx Date: Sat, 1 Oct 2016 21:37:29 +0300 Subject: [PATCH 8/9] fixed syntax and passed test --- rdb/Connection.php | 1 - rdb/DatumConverter.php | 1 - rdb/Queries/Aggregations/Group.php | 12 +++++++----- rdb/ValuedQuery/ValuedQuery.php | 4 ++-- tests/Functional/AggregationsTest.php | 1 + tests/TestHelpers/createDb.php | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rdb/Connection.php b/rdb/Connection.php index dcfdf63..5d7519c 100644 --- a/rdb/Connection.php +++ b/rdb/Connection.php @@ -271,7 +271,6 @@ public function run(Query $query, $options = array(), &$profile = '') } else { return $this->createCursorFromResponse($response, $token, $response['n'], $toNativeOptions); } - } public function continueQuery($token) diff --git a/rdb/DatumConverter.php b/rdb/DatumConverter.php index 055e3a9..eb67ada 100644 --- a/rdb/DatumConverter.php +++ b/rdb/DatumConverter.php @@ -158,7 +158,6 @@ public function canEncodeAsJson($v) } return false; - } public function wrapImplicitVar(Query $q) diff --git a/rdb/Queries/Aggregations/Group.php b/rdb/Queries/Aggregations/Group.php index 51f88d7..14c36f6 100644 --- a/rdb/Queries/Aggregations/Group.php +++ b/rdb/Queries/Aggregations/Group.php @@ -7,16 +7,18 @@ class Group extends ValuedQuery { - public function __construct(ValuedQuery $sequence, $fieldOrFunction, $groupOn = array()) + public function __construct(ValuedQuery $sequence, $groupOn = array()) { - array_unshift($groupOn, $fieldOrFunction); - + if (!is_array($groupOn)) { + $groupOn = array($groupOn); + } + if (isset($groupOn['index'])) { $this->setOptionalArg('index', $this->nativeToDatum($groupOn['index'])); unset($groupOn['index']); } - - if (isset($groupOn['multi'])) { + + if (isset($groupOn['multi'])) { $this->setOptionalArg('multi', $this->nativeToDatum($groupOn['multi'])); unset($groupOn['multi']); } diff --git a/rdb/ValuedQuery/ValuedQuery.php b/rdb/ValuedQuery/ValuedQuery.php index b809f29..92554ad 100644 --- a/rdb/ValuedQuery/ValuedQuery.php +++ b/rdb/ValuedQuery/ValuedQuery.php @@ -214,9 +214,9 @@ public function distinct($opts = null) { return new Distinct($this, $opts); } - public function group($fieldOrFunction, $groupOn = array()) + public function group($groupOn = array()) { - return new Group($this, $fieldOrFunction, $groupOn); + return new Group($this, $groupOn); } public function ungroup() { diff --git a/tests/Functional/AggregationsTest.php b/tests/Functional/AggregationsTest.php index 1891c77..15e0c06 100644 --- a/tests/Functional/AggregationsTest.php +++ b/tests/Functional/AggregationsTest.php @@ -160,6 +160,7 @@ public function testGroupArray() ->ungroup() ->run($this->conn); + $this->assertEquals($expected, $this->toArray($res)); } diff --git a/tests/TestHelpers/createDb.php b/tests/TestHelpers/createDb.php index 4bbb782..91dd3ed 100644 --- a/tests/TestHelpers/createDb.php +++ b/tests/TestHelpers/createDb.php @@ -6,7 +6,7 @@ $db = getenv('RDB_DB'); $res = r\dbCreate($db)->run($conn); -if ($res['dbs_created'] !== 1.0) { +if ($res['dbs_created'] !== 1) { echo 'Error creating DB' . PHP_EOL; exit; } From eb75db2f77c04a5a1b3fb9756d0bfb0a65c83dfb Mon Sep 17 00:00:00 2001 From: lexx Date: Sat, 1 Oct 2016 21:48:01 +0300 Subject: [PATCH 9/9] indentation --- rdb/Queries/Aggregations/Group.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdb/Queries/Aggregations/Group.php b/rdb/Queries/Aggregations/Group.php index 14c36f6..8a0dfa7 100644 --- a/rdb/Queries/Aggregations/Group.php +++ b/rdb/Queries/Aggregations/Group.php @@ -10,7 +10,7 @@ class Group extends ValuedQuery public function __construct(ValuedQuery $sequence, $groupOn = array()) { if (!is_array($groupOn)) { - $groupOn = array($groupOn); + $groupOn = array($groupOn); } if (isset($groupOn['index'])) {