Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group function closer to the original one #134

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rdb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions rdb/Datum/NumberDatum.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class NumberDatum extends Datum
{
public function encodeServerRequest()
{
return (float)$this->getValue();
return $this->getValue();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because all the numbers are saved as float. I couldn't save integers.

}

public static function decodeServerResponse($json)
{
$result = new NumberDatum();
$result->setValue((float)$json);
$result->setValue($json);
return $result;
}

Expand Down
1 change: 0 additions & 1 deletion rdb/DatumConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public function canEncodeAsJson($v)
}

return false;

}

public function wrapImplicitVar(Query $q)
Expand Down
8 changes: 7 additions & 1 deletion rdb/Queries/Aggregations/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@

class Group extends ValuedQuery
{
public function __construct(ValuedQuery $sequence, $groupOn)
public function __construct(ValuedQuery $sequence, $groupOn = array())
{
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'])) {
$this->setOptionalArg('multi', $this->nativeToDatum($groupOn['multi']));
unset($groupOn['multi']);
}

$this->setPositionalArg(0, $sequence);
$i = 1;
foreach ($groupOn as $g) {
Expand Down
2 changes: 1 addition & 1 deletion rdb/ValuedQuery/ValuedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function distinct($opts = null)
{
return new Distinct($this, $opts);
}
public function group($groupOn)
public function group($groupOn = array())
{
return new Group($this, $groupOn);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Functional/AggregationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function testGroupArray()
->ungroup()
->run($this->conn);


$this->assertEquals($expected, $this->toArray($res));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestHelpers/createDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down