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

fix smi2ChClient constructor #29

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
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,29 @@ doctrine:
array(date): FOD\DBALClickHouse\Types\ArrayDateType
```

Additional type `BigIntType` helps you to store bigint values as [Int64/UInt64](https://clickhouse.yandex/reference_en.html#UInt8,%20UInt16,%20UInt32,%20UInt64,%20Int8,%20Int16,%20Int32,%20Int64) value type in ClickHouse.
You can override DBAL type in your code:
```php
Type::overrideType(Type::BIGINT, 'FOD\DBALClickHouse\Types\BigIntType');
```
or use custom mapping types in Symfony configuration:
If you want to use [numeric types](https://clickhouse.yandex/docs/en/single/#uint8-uint16-uint32-uint64-int8-int16-int32-int64), register additional DBAL types in your Symfony configuration file:

```yml
# app/config/config.yml
doctrine:
dbal:
connections:
...
types:
bigint: FOD\DBALClickHouse\Types\BigIntType
...
int8: FOD\DBALClickHouse\Types\Int8Type
int16: FOD\DBALClickHouse\Types\Int16Type
int32: FOD\DBALClickHouse\Types\Int32Type
int64: FOD\DBALClickHouse\Types\Int64Type
float32: FOD\DBALClickHouse\Types\Float32Type
float64: FOD\DBALClickHouse\Types\Float64Type
decimal: FOD\DBALClickHouse\Types\DecimalType
```

or you can override DBAL type in your code:
```php
Type::overrideType(Type::BIGINT, 'FOD\DBALClickHouse\Types\Int64Type');

Type::overrideType(Type::DECIMAL, 'FOD\DBALClickHouse\Types\DecimalType');
```

### More information in Doctrine DBAL documentation:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "friendsofdoctrine/dbal-clickhouse",
"name": "bllem/dbal-clickhouse",
"type": "library",
"description": "Doctrine DBAL driver for ClickHouse",
"keywords": [
Expand Down
9 changes: 4 additions & 5 deletions src/ClickHouseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down Expand Up @@ -51,10 +51,9 @@ public function __construct(
'port' => $params['port'] ?? 8123,
'username' => $username,
'password' => $password,
'settings' => array_merge([
'database' => $params['dbname'] ?? 'default',
], $params['driverOptions'] ?? []),
]);
], array_merge([
'database' => $params['dbname'] ?? 'default',
], $params['driverOptions'] ?? []));

$this->platform = $platform;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ClickHouseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/ClickHouseKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
11 changes: 9 additions & 2 deletions src/ClickHousePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down Expand Up @@ -135,6 +135,7 @@ protected function initializeDoctrineTypeMappings() : void
'uint64' => 'bigint',
'float32' => 'decimal',
'float64' => 'float',
'decimal' => 'decimal',

'string' => 'string',
'fixedstring' => 'string',
Expand Down Expand Up @@ -667,7 +668,13 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
*/
$dateColumnParams = [
'type' => Type::getType('date'),
'default' => 'today()',
'default' =>
isset($options['eventDateColumn']) &&
isset($columns[$options['eventDateColumn']]) &&
isset($columns[$options['eventDateColumn']]['default']) &&
$columns[$options['eventDateColumn']]['default'] ?
$columns[$options['eventDateColumn']]['default'] :
'today()'
];
if (! empty($options['eventDateProviderColumn'])) {
$options['eventDateProviderColumn'] = trim($options['eventDateProviderColumn']);
Expand Down
25 changes: 24 additions & 1 deletion src/ClickHouseSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down Expand Up @@ -118,8 +118,29 @@ protected function _getPortableTableColumnDefinition($tableColumn) : Column
}

$unsigned = false;

if (stripos($columnType, 'uint') === 0) {

$unsigned = true;

$dbType = substr($columnType, 1);
}

$precision = 10;

$scale = 0;

if (stripos($columnType, 'decimal') === 0) {

$unsigned = false;

$dbType = 'decimal';

preg_match('/([0-9]{1,2})(, )?([0-9]{1,2})?/', $columnType, $matches);

$precision = isset($matches[1]) ? $matches[1] : 10;

$scale = isset($matches[3]) ? $matches[3] : 0;
}

if (! isset($tableColumn['name'])) {
Expand All @@ -141,6 +162,8 @@ protected function _getPortableTableColumnDefinition($tableColumn) : Column
'unsigned' => $unsigned,
'autoincrement' => false,
'comment' => null,
'precision' => $precision,
'scale' => $scale,
];

return new Column(
Expand Down
2 changes: 1 addition & 1 deletion src/ClickHouseStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayDateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayDateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayFloat32Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayFloat64Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayInt16Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayInt32Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayInt64Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayInt8Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayUInt16Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayUInt32Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayUInt64Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayUInt8Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/BigIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/BitNumericalClickHouseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/ClickHouseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Types/DatableClickHouseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
44 changes: 44 additions & 0 deletions src/Types/DecimalType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

/*
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOD\DBALClickHouse\Types;

/**
* Decimal Type
*/
class DecimalType extends Type
{

public function getBaseClickHouseType() : string
{
return NumericalClickHouseType::TYPE_DECIMAL;
}

public function getName(): string
{
return Type::DECIMAL;
}

/**
* {@inheritdoc}
*/
protected function getDeclaration(array $fieldDeclaration = []) : string
{

$fieldDeclaration['precision'] = ! isset($fieldDeclaration['precision']) || empty($fieldDeclaration['precision'])
? 10 : $fieldDeclaration['precision'];
$fieldDeclaration['scale'] = ! isset($fieldDeclaration['scale']) || empty($fieldDeclaration['scale'])
? 0 : $fieldDeclaration['scale'];

return $this->getBaseClickHouseType(). "({$fieldDeclaration['precision']}, {$fieldDeclaration['scale']})";
}
}
Loading