-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #80
- Loading branch information
Showing
7 changed files
with
172 additions
and
2 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
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 ClickHouseDB\Type; | ||
|
||
interface NumericType extends Type | ||
{ | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ClickHouseDB\Type; | ||
|
||
interface Type | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function getValue(); | ||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ClickHouseDB\Type; | ||
|
||
final class UInt64 implements NumericType | ||
{ | ||
/** @var string */ | ||
public $value; | ||
|
||
private function __construct(string $uint64Value) | ||
{ | ||
$this->value = $uint64Value; | ||
} | ||
|
||
/** | ||
* @return self | ||
*/ | ||
public static function fromString(string $uint64Value) | ||
{ | ||
return new self($uint64Value); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->value; | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ClickHouseDB\Tests\Type; | ||
|
||
use ClickHouseDB\Tests\WithClient; | ||
use ClickHouseDB\Type\UInt64; | ||
use DateTimeImmutable; | ||
use PHPUnit\Framework\TestCase; | ||
use function array_column; | ||
use function implode; | ||
use function sprintf; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
final class UInt64Test extends TestCase | ||
{ | ||
use WithClient; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->client->write('DROP TABLE IF EXISTS uint64_data'); | ||
$this->client->write(' | ||
CREATE TABLE IF NOT EXISTS uint64_data ( | ||
date Date MATERIALIZED toDate(datetime), | ||
datetime DateTime, | ||
number UInt64 | ||
) | ||
ENGINE = MergeTree | ||
PARTITION BY date | ||
ORDER BY (datetime); | ||
'); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testWriteInsert() | ||
{ | ||
$this->client->write(sprintf( | ||
'INSERT INTO uint64_data VALUES %s', | ||
implode( | ||
',', | ||
[ | ||
sprintf('(now(), %s)', UInt64::fromString('0')), | ||
sprintf('(now(), %s)', UInt64::fromString('1')), | ||
sprintf('(now(), %s)', UInt64::fromString('18446744073709551615')), | ||
] | ||
) | ||
)); | ||
|
||
$statement = $this->client->select('SELECT number FROM uint64_data ORDER BY number ASC'); | ||
|
||
self::assertSame(3, $statement->count()); | ||
self::assertSame(['0', '1', '18446744073709551615'], array_column($statement->rows(), 'number')); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testInsert() | ||
{ | ||
$now = new DateTimeImmutable(); | ||
$this->client->insert( | ||
'uint64_data', | ||
[ | ||
[$now, UInt64::fromString('0')], | ||
[$now, UInt64::fromString('1')], | ||
[$now, UInt64::fromString('18446744073709551615')], | ||
] | ||
); | ||
|
||
$statement = $this->client->select('SELECT number FROM uint64_data ORDER BY number ASC'); | ||
|
||
self::assertSame(3, $statement->count()); | ||
self::assertSame(['0', '1', '18446744073709551615'], array_column($statement->rows(), 'number')); | ||
} | ||
} |