Skip to content

Commit

Permalink
Fixed #4
Browse files Browse the repository at this point in the history
  • Loading branch information
bashkarev committed Aug 28, 2017
1 parent 313aa5d commit 55f6249
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ language: php
php:
- 7
- 7.1
- nightly

env:
- CLICKHOUSE_VERSION=1.1.54159
- CLICKHOUSE_VERSION=latest

services:
- docker
Expand All @@ -13,6 +16,6 @@ install:
- travis_retry composer install --prefer-dist --no-interaction

before_script:
- docker run -d -p 127.0.0.1:8123:8123 --name some-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server:1.1.54159
- docker run -d -p 127.0.0.1:8123:8123 --name some-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server:$CLICKHOUSE_VERSION

script: ./vendor/bin/phpunit
15 changes: 13 additions & 2 deletions Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ protected function findColumns($table)
}

/**
* toDo size for FixedString
* @inheritdoc
*/
protected function loadColumnSchema($info)
Expand All @@ -82,9 +81,21 @@ protected function loadColumnSchema($info)
break 1;
}
}
if ($info['default_type'] !== '') {

if (isset($info['default_type']) && $info['default_type'] !== '') {
$column->defaultValue = $info['default_type'];
}
if (isset($info['default_kind']) && $info['default_kind'] !== '') {
$column->defaultValue = $info['default_kind'];
}

if (
$column->type === self::TYPE_STRING
&& preg_match('/^FixedString\((\d+)\)$/', $column->dbType, $out)
) {
$column->size = (int)$out[1];
}

$column->phpType = $this->getColumnPhpType($column);
return $column;
}
Expand Down
52 changes: 52 additions & 0 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* @copyright Copyright (c) 2017 Dmitry Bashkarev
* @license https://github.com/bashkarev/PhpStorm/blob/master/LICENSE
* @link https://github.com/bashkarev/PhpStorm#readme
*/

namespace bashkarev\clickhouse\tests;

use bashkarev\clickhouse\Schema;

/**
* @author Dmitry Bashkarev <[email protected]>
*/
class SchemaTest extends DatabaseTestCase
{

public function testTypes()
{
$columns = $this->getConnection()->getSchema()->getTableSchema('types', true)->columns;

$this->assertSame(Schema::TYPE_SMALLINT, $columns['UInt8']->type);
$this->assertSame(Schema::TYPE_INTEGER, $columns['UInt16']->type);
$this->assertSame(Schema::TYPE_INTEGER, $columns['UInt32']->type);
$this->assertSame(Schema::TYPE_BIGINT, $columns['UInt64']->type);

$this->assertSame(Schema::TYPE_SMALLINT, $columns['Int8']->type);
$this->assertSame(Schema::TYPE_INTEGER, $columns['Int16']->type);
$this->assertSame(Schema::TYPE_INTEGER, $columns['Int32']->type);
$this->assertSame(Schema::TYPE_BIGINT, $columns['Int64']->type);

$this->assertSame(Schema::TYPE_FLOAT, $columns['Float32']->type);
$this->assertSame(Schema::TYPE_FLOAT, $columns['Float64']->type);

$this->assertSame(Schema::TYPE_STRING, $columns['String']->type);
$this->assertSame(Schema::TYPE_STRING, $columns['FixedString']->type);

$this->assertSame(Schema::TYPE_DATETIME, $columns['DateTime']->type);
$this->assertSame(Schema::TYPE_DATE, $columns['Date']->type);

$this->assertSame(Schema::TYPE_STRING, $columns['Enum8']->type);
$this->assertSame(Schema::TYPE_STRING, $columns['Enum16']->type);

}

public function testSize()
{
$column = $this->getConnection()->getSchema()->getTableSchema('types', true)->columns['FixedString'];
$this->assertSame(20, $column->size);
}

}
22 changes: 21 additions & 1 deletion tests/data/clickhouse.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DROP TABLE IF EXISTS `csv`;
DROP TABLE IF EXISTS `customer`;
DROP TABLE IF EXISTS `types`;


CREATE TABLE csv (d Date, a String, b String) ENGINE = MergeTree(d, d, 8192);
Expand All @@ -15,4 +16,23 @@ CREATE TABLE `customer` (

INSERT INTO `customer` (id, email, name, address, status, profile_id) VALUES (1,'[email protected]', 'user1', 'address1', 1, 1);
INSERT INTO `customer` (id, email, name, address, status) VALUES (2, '[email protected]', 'user2', 'address2', 1);
INSERT INTO `customer` (id, email, name, address, status, profile_id) VALUES (3, '[email protected]', 'user3', 'address3', 2, 2);
INSERT INTO `customer` (id, email, name, address, status, profile_id) VALUES (3, '[email protected]', 'user3', 'address3', 2, 2);

CREATE TABLE `types` (
`UInt8` UInt8,
`UInt16` UInt16,
`UInt32` UInt32,
`UInt64` UInt64,
`Int8` Int8,
`Int16` Int16,
`Int32` Int32,
`Int64` Int64,
`Float32` Float32,
`Float64` Float64,
`String` String,
`FixedString` FixedString(20),
`DateTime` DateTime,
`Date` Date,
`Enum8` Enum8('hello' = 1, 'world' = 2),
`Enum16` Enum8('hello' = 1, 'world' = 2)
) ENGINE=Memory;

0 comments on commit 55f6249

Please sign in to comment.