-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
208 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimPod\ClickHouseClient\Exception; | ||
|
||
use Exception; | ||
|
||
final class CannotInsert extends Exception implements ClickHouseClientException | ||
{ | ||
public static function noValues() : self | ||
{ | ||
return new self(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimPod\ClickHouseClient\Exception; | ||
|
||
interface ClickHouseClientException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimPod\ClickHouseClient\Tests; | ||
|
||
use Ds\Set; | ||
use Ds\Vector; | ||
use SimPod\ClickHouseClient\Exception\CannotInsert; | ||
use SimPod\ClickHouseClient\Format\JsonEachRow; | ||
|
||
final class InsertTest extends TestCaseBase | ||
{ | ||
use WithClient; | ||
|
||
/** | ||
* @dataProvider providerInsert | ||
*/ | ||
public function testInsert(string $tableSql) : void | ||
{ | ||
$data = new Vector( | ||
[ | ||
['PageViews' => 5, 'UserID' => '4324182021466249494', 'Duration' => 146, 'Sign' => -1], | ||
['PageViews' => 6, 'UserID' => '4324182021466249494', 'Duration' => 185, 'Sign' => 1], | ||
] | ||
); | ||
|
||
$this->client->executeQuery($tableSql); | ||
|
||
$this->client->insert('UserActivity', $data); | ||
|
||
$output = $this->client->select( | ||
<<<CLICKHOUSE | ||
SELECT * FROM UserActivity | ||
CLICKHOUSE | ||
, | ||
new JsonEachRow() | ||
); | ||
|
||
self::assertSame($data->toArray(), $output->data()); | ||
} | ||
|
||
/** | ||
* @dataProvider providerInsert | ||
*/ | ||
public function testInsertUseColumns(string $tableSql) : void | ||
{ | ||
$data = [ | ||
['PageViews' => 5, 'UserID' => '4324182021466249494', 'Duration' => 146, 'Sign' => -1], | ||
['PageViews' => 6, 'UserID' => '4324182021466249494', 'Duration' => 185, 'Sign' => 1], | ||
]; | ||
|
||
$this->client->executeQuery($tableSql); | ||
|
||
$this->client->insert( | ||
'UserActivity', | ||
new Vector( | ||
[ | ||
[5, '4324182021466249494', 146, -1], | ||
[6, '4324182021466249494', 185, 1], | ||
] | ||
), | ||
new Set(['PageViews', 'UserID', 'Duration', 'Sign']) | ||
); | ||
|
||
$output = $this->client->select( | ||
<<<CLICKHOUSE | ||
SELECT * FROM UserActivity | ||
CLICKHOUSE | ||
, | ||
new JsonEachRow() | ||
); | ||
|
||
self::assertSame($data, $output->data()); | ||
} | ||
|
||
/** | ||
* @return iterable<array<mixed>> | ||
*/ | ||
public function providerInsert() : iterable | ||
{ | ||
$sql = <<<CLICKHOUSE | ||
CREATE TABLE UserActivity ( | ||
PageViews UInt32, | ||
UserID UInt64, | ||
Duration UInt32, | ||
Sign Int8 | ||
) | ||
ENGINE Memory | ||
CLICKHOUSE; | ||
|
||
yield [$sql]; | ||
} | ||
|
||
public function testInsertEmptyValuesThrowsException() : void | ||
{ | ||
$this->expectException(CannotInsert::class); | ||
|
||
$this->client->insert('table', new Vector()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters