Giter Club home page Giter Club logo

dbal-clickhouse's Introduction

Doctrine DBAL ClickHouse Driver

Latest Version on Packagist GitHub Tests Status GitHub Code Style Status Total Downloads Licence

Doctrine DBAL driver for ClickHouse - an open-source column-oriented database management system by Yandex

Driver is suitable for Symfony or any other framework using Doctrine.

  • v2 supports Doctrine DBAL 3+ and PHP 8.0+
  • v1 supports Doctrine DBAL 2+ and PHP 7.1+

Installation

composer require friendsofdoctrine/dbal-clickhouse

Initialization

Custom PHP script

$connectionParams = [
    'host' => 'localhost',
    'port' => 8123,
    'user' => 'default',
    'password' => '',
    'dbname' => 'default',
    'driverClass' => 'FOD\DBALClickHouse\Driver',
    'wrapperClass' => 'FOD\DBALClickHouse\Connection',
    'driverOptions' => [
        'extremes' => false,
        'readonly' => true,
        'max_execution_time' => 30,
        'enable_http_compression' => 0,
        'https' => false,
    ],
];
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, new \Doctrine\DBAL\Configuration());

driverOptions are special smi2/phpclickhouse client settings

Symfony

configure...

# app/config/config.yml
doctrine:
    dbal:
        connections:
            clickhouse:
                host:     localhost
                port:     8123
                user:     default
                password: ""
                dbname:   default
                driver_class: FOD\DBALClickHouse\Driver
                wrapper_class: FOD\DBALClickHouse\Connection
                options:
                    enable_http_compression: 1
                    max_execution_time: 60
            #mysql:
            #   ...

...and get from the service container

$conn = $this->get('doctrine.dbal.clickhouse_connection');

Usage

Create database

php bin/console doctrine:database:create --connection=clickhouse --if-not-exists

Create new table

// ***quick start***
$fromSchema = $conn->getSchemaManager()->createSchema();
$toSchema = clone $fromSchema;


// create new table object
$newTable = $toSchema->createTable('new_table');

// add columns
$newTable->addColumn('id', 'integer', ['unsigned' => true]);
$newTable->addColumn('payload', 'string', ['notnull' => false]);
// *option 'notnull' in false mode allows you to insert NULL into the column; 
//                   in this case, the column will be represented in the ClickHouse as Nullable(String)
$newTable->addColumn('hash', 'string', ['length' => 32, 'fixed' => true]);
// *option 'fixed' sets the fixed length of a string column as specified; 
//                 if specified, the type of the column is FixedString

//set primary key
$newTable->setPrimaryKey(['id']);


// execute migration SQLs to create table in ClickHouse
$sqlArray = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform());
foreach ($sqlArray as $sql) {
    $conn->exec($sql);
}
// ***more options (optional)***

//specify table engine
$newTable->addOption('engine', 'MergeTree');
// *if not specified -- default engine 'ReplacingMergeTree' will be used


// add Date column for partitioning
$newTable->addColumn('event_date', 'date', ['default' => 'toDate(now())']);
$newTable->addOption('eventDateColumn', 'event_date');
// *if not specified -- default Date column named EventDate will be added
$newTable->addOption('eventDateProviderColumn', 'updated_at');
// *if specified -- event date column will be added with default value toDate(updated_at); 
//    if the type of the provider column is `string`, the valid format of provider column values must be either `YYYY-MM-DD` or `YYYY-MM-DD hh:mm:ss`
//    if the type of provider column is neither `string`, nor `date`, nor `datetime`, provider column values must contain a valid UNIX Timestamp
$newTable->addOption('samplingExpression', 'intHash32(id)');
// samplingExpression -- a tuple that defines the table's primary key, and the index granularity

//specify index granularity
$newTable->addOption('indexGranularity', 4096);
// *if not specified -- default value 8192 will be used

Insert

// 1
$conn->exec("INSERT INTO new_table (id, payload) VALUES (1, 'dummyPayload1')");
// 2
$conn->insert('new_table', ['id' => 2, 'payload' => 'dummyPayload2']);
// INSERT INTO new_table (id, payload) VALUES (?, ?) [2, 'dummyPayload2']
// 3 via QueryBuilder
$qb = $conn->createQueryBuilder();

$qb
    ->insert('new_table')
    ->setValue('id', ':id')
    ->setValue('payload', ':payload')
    ->setParameter('id', 3, \PDO::PARAM_INT) // need to explicitly set param type to `integer`, because default type is `string` and ClickHouse doesn't like types mismatchings
    ->setParameter('payload', 'dummyPayload3');

$qb->execute();

Select

echo $conn->fetchColumn('SELECT SUM(views) FROM articles');

Select via Dynamic Parameters and Prepared Statements

$stmt = $conn->prepare('SELECT authorId, SUM(views) AS total_views FROM articles WHERE category_id = :categoryId AND publish_date = :publishDate GROUP BY authorId');

$stmt->bindValue('categoryId', 123);
$stmt->bindValue('publishDate', new \DateTime('2017-02-29'), 'datetime');
$stmt->execute();

while ($row = $stmt->fetch()) {
    echo $row['authorId'] . ': ' . $row['total_views'] . PHP_EOL;
}

Additional types

If you want to use Array(T) type, register additional DBAL types in your code:

// register all custom DBAL Array types
ArrayType::registerArrayTypes($conn->getDatabasePlatform());
// register one custom DBAL Array(Int8) type
Type::addType('array(int8)', 'FOD\DBALClickHouse\Types\ArrayInt8Type');

or register them in Symfony configuration file:

# app/config/config.yml
doctrine:
    dbal:
        connections:
        ...
        types:
            array(int8): FOD\DBALClickHouse\Types\ArrayInt8Type
            array(int16): FOD\DBALClickHouse\Types\ArrayInt16Type
            array(int32): FOD\DBALClickHouse\Types\ArrayInt32Type
            array(int64): FOD\DBALClickHouse\Types\ArrayInt64Type
            array(uint8): FOD\DBALClickHouse\Types\ArrayUInt8Type
            array(uint16): FOD\DBALClickHouse\Types\ArrayUInt16Type
            array(uint32): FOD\DBALClickHouse\Types\ArrayUInt32Type
            array(uint64): FOD\DBALClickHouse\Types\ArrayUInt64Type
            array(float32): FOD\DBALClickHouse\Types\ArrayFloat32Type
            array(float64): FOD\DBALClickHouse\Types\ArrayFloat64Type
            array(string): FOD\DBALClickHouse\Types\ArrayStringableType
            array(datetime): FOD\DBALClickHouse\Types\ArrayDateTimeType
            array(date): FOD\DBALClickHouse\Types\ArrayDateType

Additional type BigIntType helps you to store bigint values as Int64/UInt64 value type in ClickHouse. You can override DBAL type in your code:

Type::overrideType(Type::BIGINT, 'FOD\DBALClickHouse\Types\BigIntType');

or use custom mapping types in Symfony configuration:

# app/config/config.yml
doctrine:
    dbal:
        types:
            bigint:  FOD\DBALClickHouse\Types\BigIntType
            ...

More information in Doctrine DBAL documentation:

dbal-clickhouse's People

Contributors

argayash avatar asanikovich avatar mochalygin avatar vasary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dbal-clickhouse's Issues

Deprecated Error with package

[ "exception" => ErrorException { #message: "User Deprecated: The "FOD\DBALClickHouse\ClickHouseConnection" class implements "Doctrine\DBAL\Driver\PingableConnection" that is deprecated." #code: 0 #file: "./vendor/symfony/error-handler/DebugClassLoader.php" #line: 390 #severity: E_USER_DEPRECATED trace: { ./vendor/symfony/error-handler/DebugClassLoader.php:390 { โ€ฆ} ./vendor/friendsofdoctrine/dbal-clickhouse/src/Driver.php:57 { โ€ฆ} ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:398 { โ€ฆ} ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1938 { โ€ฆ} ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1276 { โ€ฆ} ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php:212 { โ€ฆ} ./src/Command/DistribuneAggregateIncomeCommand.php:65 { App\Command\DistribuneAggregateIncomeCommand->getWagesData(): array^ โ€บ ->groupBy('v.video, v.publisher'); โ€บ $statisticsData = $qb->execute(); โ€บ } ./src/Command/DistribuneAggregateIncomeCommand.php:47 { โ€ฆ} ./vendor/symfony/console/Command/Command.php:256 { โ€ฆ} ./vendor/symfony/console/Application.php:989 { โ€ฆ} ./vendor/symfony/framework-bundle/Console/Application.php:96 { โ€ฆ} ./vendor/symfony/console/Application.php:290 { โ€ฆ} ./vendor/symfony/framework-bundle/Console/Application.php:82 { โ€ฆ} ./vendor/symfony/console/Application.php:166 { โ€ฆ} ./bin/console:43 { โ€ฆ} } } ]

"can't find meta" error in prepare/execute

Hello.

I try to check if records already exist, and get error = "An exception occurred while executing 'SELECT 1 dupl FROM payments WHERE order_id= :order_id AND appid= :appid LIMIT 1' with params ["xxx=:1:11", "yyy-Amazon"]:\n\nCan`t find meta"}

My code:
$stmt = $conn->prepare('SELECT 1 dupl FROM payments WHERE order_id= :order_id AND appid= :appid LIMIT 1'); $stmt->bindValue('order_id', $order_id); $stmt->bindValue('appid', $j->app_id); $stmt->execute(); while ($row = $stmt->fetch()) { file_put_contents('ch_dupl_' . date('Y-m-d') . '_' . $tbl . '_' . $j->app_id . '_' . uniqid() . '.json', json_encode($j)); return true; }

My table structure:
CREATE TABLE default.payments ( cohort Date, installdatetime DateTime, attributedtouchtime Nullable(DateTime), ... appid String, ... order_id String, ... ) ENGINE = MergeTree() PARTITION BY cohort ORDER BY appid SETTINGS index_granularity = 8192;

Incorrect escaping of single quote in ClickHouseStatement::resolveType

I'm using version 2.0.0, and when I'm using prepared statement and making insert, I have a problem with inccorect escaping of single quote. Example:

/** @var FOD\DBALClickHouse\ClickHouseConnection $connection */
$stmt = $connection->prepare("INSERT INTO my_table (some_val) VALUES (?)");
$stmt->execute(["some ' value"]);

// HttpCode:400 ;  ;Code: 62, e.displayText() = DB::Exception: Cannot parse expression of type String() here: 'some \'' value'

The problem as I see it lays inside class \FOD\DBALClickHouse\ClickHousePlatform.

public function quoteStringLiteral($str): string
{
    return parent::quoteStringLiteral(addslashes($str));
}

It adds slashes before single/double quote etc. But inside parent method of \Doctrine\DBAL\Platforms\AbstractPlatform, there is different type of escaping as I see (doubling of quote).

public function quoteStringLiteral($str)
{
    $c = $this->getStringLiteralQuoteCharacter();

    return $c . str_replace($c, $c . $c, $str) . $c;
}

So eventually in such conditions, my value becomes some \'' value. This leads to an error of query execution at ClickHouse server. Previosly, this quoteStringLiteral method was looking like this:

public function quoteStringLiteral($str) : string
{
    $c = $this->getStringLiteralQuoteCharacter();

    return $c . addslashes($str) . $c;
}

I think additional addslashes is redundant in current (v2.0.0) implementation. But I'm open to discuss this in order to find best working solutions with this problem.

Support request: SELECT * WHERE foo IN :bar

ะะต ะผะพะณัƒ ะฟะพะฝัั‚ัŒ ะบะฐะบ ั€ะฐะฑะพั‚ัŒ ั IN
ะŸั€ะพะฑะพะฒะฐะป ั€ะฐะทะฝั‹ะต ะฒะฐั€ะธะฐะฝั‚ั‹ ะพั‚ััŽะดะฐ https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html
ะฟะพะปัƒั‡ะฐัŽ ะฒัะตะณะดะฐ Notice: Array to string conversion in FOD\DBALClickHouse\ClickHouseStatement->getTypedParam() (line 390 of vendor/friendsofdoctrine/dbal-clickhouse/src/ClickHouseStatement.php).

FOD\DBALClickHouse\ClickHouseStatement->getTypedParam('bar') (Line: 296)
FOD\DBALClickHouse\ClickHouseStatement->execute(NULL) (Line: 153)
Doctrine\DBAL\Statement->execute() (Line: 75)

ะŸั€ะธะผะต ะบะพะดะฐ:

<?php
$bar = [1, 2, 3];
$query = $conn->prepare('SELECT **** WHERE foo IN :bar');
$query->bindValue('bar', $bar);

Declaration of Driver::getSchemaManager must be compatible with interface

public function getSchemaManager(Connection $conn)

Fatal error
Declaration of
FOD\DBALClickHouse\Driver::getSchemaManager(Doctrine\DBAL\Connection $conn)
must be compatible with
Doctrine\DBAL\Driver::getSchemaManager(
Doctrine\DBAL\Connection $conn,
Doctrine\DBAL\Platforms\AbstractPlatform $platform
)

Since v3.0.0 of Doctrine/DBAL (JUL, 2020) AbstractPlatform became a required arg

Operation 'FOD\DBALClickHouse\ClickHousePlatform::appendLockHint' is not supported by platform.

Hello,
I tried to create a query using QueryBuilder, but got error:

Operation 'FOD\DBALClickHouse\ClickHousePlatform::appendLockHint' is not supported by platform.

The code which produces this error:

$qb = $this->createQueryBuilder('c')
->select('count(c)')
->andWhere('c.link = :link_id')
->setParameter('link_id', $linkId);

return $qb->getQuery()->getSingleScalarResult();

It produces DQL: SELECT count(c) FROM Trim\Clickhouse\Model\ClickStat c WHERE c.link = :link_id

Can you suggest where there is an error?

Btw, example with the connection use is working:

$conn = $this->getEntityManager()->getConnection();

return $conn->fetchColumn(
            'SELECT count() FROM clicks WHERE link_id = :link_id',
            ['link_id' => $linkId],
            0,
            ['link_id' => 'integer']
);

generateUUIDv4() with query builder

I try to define a column with default value = generateUUIDv4()

i try $newTable->addColumn('uuid', 'string', ['default' => 'generateUUIDv4()']);
but the value is string not the function ...

so for the moment i use a little trick like this:

public function up(Schema $schema) : void
    {
        /** @var Connection */
        $conn = $this->container->get('doctrine.dbal.clickhouse_connection');
        /** @var Schema */
        $fromSchema = new Schema();
        /** @var Schema */
        $toSchema = clone $fromSchema;

        $newTable = $toSchema->createTable('probe_datum');
        $newTable->addOption('engine', 'MergeTree');

        $newTable->addColumn('uuid', 'string', ['default' => 'generateUUIDv4()']);
        $newTable->addColumn('datetime_value', 'datetime');
        $newTable->addColumn('value', 'float');
        $newTable->addColumn('probe_id', 'integer');

        $newTable->setPrimaryKey(['uuid', 'datetime_value', 'probe_id']);

        $sqlArray = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform());

        foreach ($sqlArray as $sql) {
            $hackSql = str_replace('\'generateUUIDv4()\'', 'generateUUIDv4()', $sql);
            $conn->exec($hackSql);
        }
    }

how can i do this properly ?

using repository throw new ORMException("TableGenerator not yet implemented.");

Try using clickhouse db in my synfony 4.4 project...
I make a twig filter and try to make a request in ...

 /** @var EntityManager $em */
        $em = $this->container->get('doctrine.orm.clickhouse_entity_manager');
        /** @var ProbeDatumRepository $probeDatumRepository */
        $probeDatumRepository = $em->getRepository(ProbeDatum::class);

this throw exeption : TableGenerator not yet implemented.

Migrations

Hello! Can you please tell me if this library can work with Symfony migrations? And if he can, could you give an example of how this can be done?

Troubles with primary key on import MergeTree table

ORDER BY โ€” Primary key.

A tuple of columns or arbitrary expressions. Example: ORDER BY (CounterID, EventDate). If a sampling expression is used, the primary key must contain it. Example: ORDER BY (CounerID, EventDate, intHash32(UserID)).

CREATE TABLE client_work_interval
(
uuid String,
timestamp DateTime,
date Date,
manager_id UInt32,
user_id UInt32,
status Int8
)
ENGINE=MergeTree() PARTITION BY toYYYYMM(date) ORDER BY (date, intHash32(user_id), intHash32(manager_id)) SAMPLE BY intHash32(user_id) SETTINGS index_granularity=8192

php bin/console doctrine:mapping:import 'App\Entity' annotation --path=src/Entity --em=clickhouse

In DatabaseDriver.php line 288:
                                                                                                 
  Table client_work_interval has no primary key. Doctrine does not support reverse engineering   
  from tables that don't have a primary key.                                                     
                                                                               

BUG Question mark in value still misbehavior

Although #11 has closed, there are still bugs present.

There is simple test from repo, just some modified tests/InsertTest.php - copy method testInsertViaQueryBuilder() and change order of calling setValue/setParameter:

    public function testInsertViaQueryBuilder2()
    {
        $qb = $this->connection->createQueryBuilder();

        $qb
            ->insert('test_insert_table')
            ->setValue('payload', ':payload')
            ->setValue('id', ':id')
            ->setParameter('payload', 'Is this string a question?')
            ->setParameter('id', 11, \PDO::PARAM_INT)
            ->execute();

        $this->assertEquals([
            [
                'payload' => 'Is this string a question?',
                'id' => 11,
            ],
        ], $this->connection->fetchAll("SELECT payload, id from test_insert_table ORDER BY id"));
    }

assertEquals also modified.

Test results:

There was 1 failure:

1) FOD\DBALClickHouse\Tests\InsertTest::testInsertViaQueryBuilder2
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => Array (
-        'payload' => 'Is this string a question?'
-        'id' => 11
+        'payload' => 'Is this string a question11'
+        'id' => 15
     )
 )

It happened because there are consecutive replacement of question mark in query 4b7dbe2:

            foreach (array_keys($this->values) as $key) {
                $sql = preg_replace(
                    '/(' . (is_int($key) ? '\?' : ':' . $key) . ')/i',
                    $this->getTypedParam($key),
                    $sql,
                    1
                );
            }

and question mark in string value replaced with next parameter value.
Real SQL executed:

INSERT INTO test_insert_table (payload, id) VALUES('Is this string a question11', ?)

Seriously, guys?

get the statistics from the request

Hello, thanks a lot for the library.
Is there a way to get the statistics (like elapsed, rows count) and others data from Clickhouse ('meta', 'totals', 'extremes', 'rows_before_limit_at_least', 'statistics')?

Smi2 library provides them in Statement::init(), but I didn't find a way to get them back with the results (ClickhouseStatement::execute()).

? $this->client->select($statement)->rows()

Thanks a lot

Symbol `?` in query's value

php v7.4
friendsofdoctrine/dbal-clickhouse v1.5.3
clickhouse-server: yandex/clickhouse-server:20.3.8.53 (image from official yandex hub.docker.com)

Table schema:

CREATE TABLE new_table (
    `id` Int32, 
    `payload` String, 
    `date` DateTime
) 
ENGINE = MergeTree 
PARTITION BY toYYYYMMDD(date) 
ORDER BY (id, payload, date) 
SETTINGS index_granularity = 8192;

Code example:

/** @var \FOD\DBALClickHouse\Connection $connection */
$connection = $this->getDoctrine()->getConnection('clickhouse');
$connection->insert('new_table', [
    'id' => 2,
    'payload' => 'test?o',
    'date' => (new DateTime())->format('Y-m-d H:i:s'),
]);

Result:

An exception occurred while executing 'INSERT INTO new_table (id, payload, date) VALUES (?, ?, ?)' with params [2, "test?o", "2020-05-14 13:57:42"]:

Cannot parse expression of type String here: 'test'2020-05-14 13:57:42'o', ?)
IN:INSERT INTO new_table (id, payload, date) VALUES (2, 'test'2020-05-14 13:57:42'o', ?)

If change code to:

/** @var \FOD\DBALClickHouse\Connection $connection */
$connection = $this->getDoctrine()->getConnection('clickhouse');
$data = [
    'id' => 2,
    'payload' => 'test?o',
    'date' => (new DateTime())->format('Y-m-d H:i:s'),
];
$query = sprintf(
    'INSERT INTO new_table (%s) VALUES (%s)',
    implode(', ', array_keys($data)),
    substr(str_repeat('?, ', count($data)), 0, -2)
);
$statement = $connection->prepare($query);
$statement->execute(array_values($data));

Result: insert is successful

Support Decimal data type

I have few tables imported from old database which was a MySQL database. The tables contain columns with Decimal data type.
While doing

$fromSchema = $conn->getSchemaManager()->createSchema();
$toSchema = clone $fromSchema;

I'm getting following Exception

[Doctrine\DBAL\DBALException] Unknown database type decimal(3, 2) requested, FOD\DBALClickHouse\ClickHousePlatform may not support it. in public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php on line 443

Question mark in value of multi-insert prepared statement misbehavior

As @Ocramius suggested here doctrine/dbal#2981 (comment) I tried to do multiple insert with prepared statement (because writing of plain SQL is quite dangerous) and encountered with strange behavior - if text field value has question mark it would be replaced inline with next value to insert. Example:
Table structure (taken from doc with slight modification):

$fromSchema = $conn->getSchemaManager()->createSchema();
$toSchema = clone $fromSchema;


// create new table object
$newTable = $toSchema->createTable('new_table');

// add columns
$newTable->addColumn('id', 'integer', ['unsigned' => true]);
$newTable->addColumn('payload', 'string');
$newTable->addColumn('url', 'string');
$newTable->setPrimaryKey(['id']);

// execute migration SQLs to create table in ClickHouse
$sqlArray = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform());
foreach ($sqlArray as $sql) {
    $conn->exec($sql);
}

Insert query:

$statement = $conn->prepare('INSERT INTO new_table(id, payload, url) VALUES (?, ?, ?), (?, ?, ?);');
$statement->execute([123, 'foo-bar', 'https://some.url.com/?first=param', 456, 'bar-baz', 'http://example.com?p=1']);

Error produced by code:

PHP Fatal error: Uncaught ClickHouseDB\Exception\DatabaseException: Type mismatch in IN or VALUES section. Expected: UInt32. Got: String
IN:INSERT INTO new_table(id, payload, url) VALUES (123, 'foo-bar', 'https://some.url.com/456first=param'), ('bar-baz', 'http://example.com?p=1', ?);

php8 support?

Hello. Php8 has been around for half a year, is there any support planned?

Thanks

`php bin/console doctrine:database:create` does not work

Symfony 5.0.2

$ php bin/console doctrine:database:create

throws exception

In Driver.php line 54:
  Connection parameter `dbname` is required                                               

As far as I can see vendor/doctrine/doctrine-bundle/Command/CreateDatabaseDoctrineCommand.php:86 unsets dbname to check whether db exists and connects without driver:

// Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url
unset($params['dbname'], $params['path'], $params['url']);

$tmpConnection = DriverManager::getConnection($params);
$tmpConnection->connect($input->getOption('shard'));
$shouldNotCreateDatabase = $ifNotExists && in_array($name, $tmpConnection->getSchemaManager()->listDatabases());

but \FOD\DBALClickHouse\Driver::connect does not let that.

if (! isset($params['dbname'])) {
     throw new ClickHouseException('Connection parameter `dbname` is required');
}

The connection example in the readme does not work

I tried the symfony example in the readme and only get http errors from clickhouse. I created a trial account on their page, got the credentials and enabled the mysql interface. Their example works fine in the terminal.

mysql -h MY_INSTANCE.eu-central-1.aws.clickhouse.cloud -u MY_USER -P 3306 --password

But no matter what i set in my doctrine.yml file i get errors like this

Could not create database `myproject` for connection named default
An exception occurred while executing 'CREATE DATABASE `myproject`':

Received HTTP/0.9 when not allowed```

The port 8123 you provided in the readme also does not work.

In DBALException.php line 185:

An exception occurred while executing 'SELECT database, name FROM system.tables WHERE database != 'system' AND engine != 'View'':

An exception occurred while executing 'SELECT database, name FROM system.tables WHERE database != 'system' AND engine != 'View'':

Failed to connect to MY_INSTANCE.eu-central-1.aws.clickhouse.cloud port 8123 after 5004 ms: Timeout was reached


My config looks like this.

```yaml
doctrine:
    dbal:
        host:          MY_INSTANCE.eu-central-1.aws.clickhouse.cloud
        port:          3306
        user:          default
        password:      "MY_PASSWORD"
        dbname:        myproject
        driver_class:  FOD\DBALClickHouse\Driver
        wrapper_class: FOD\DBALClickHouse\Connection
        options:
            enable_http_compression: 1
            max_execution_time:      60

And i get this error

bin/console doctrine:schema:update --dump-sql --complete --force

In DBALException.php line 185:

  An exception occurred while executing 'SELECT database, name FROM system.tables WHERE database != 'system' AND engine != 'View'':

  An exception occurred while executing 'SELECT database, name FROM system.tables WHERE database != 'system' AND engine != 'View'':

  Received HTTP/0.9 when not allowed


In DBALException.php line 185:

  An exception occurred while executing 'SELECT database, name FROM system.tables WHERE database != 'system' AND engine != 'View'':

  Received HTTP/0.9 when not allowed


In Statement.php line 190:

  Received HTTP/0.9 when not allowed


doctrine:schema:update [--em EM] [--complete] [--dump-sql] [-f|--force]```

Error when trying to create nullable fixed string

In migration when I add.

$table->addColumn('field', Type::STRING, ['length' => 3, 'notnull' => false]);

Error Unknown database type nullable(fixedstring(3)) requested, FOD\DBALClickHouse\ClickHousePlatform may not support it.

Error after CH upgrade from 2.6 to 2.7

Hi.
While doing migrations (Symfony5) and perform table creation I get now:

HttpCode:500 ; ;Code: 36. DB::Exception: This syntax for *MergeTree engine is deprecated. Use extended storage definition syntax with ORDER BY/PRIMARY KEY clause.See
also allow_deprecated_syntax_for_merge_tree setting. (BAD_ARGUMENTS) (version 22.7.2.15 (official build))

new db, createSchema(), table computed doesn't exist.

I try using a clickhouse and maria db in my symfony 4.4 project ...

i setup doctrine like this :
config/packages/doctrine.yaml

doctrine:
    dbal:
        default_connection: maria
        connections:
            maria:
                url: '%env(resolve:DATABASE_URL)%'
                charset: utf8mb4
                default_table_options:
                    collate: utf8mb4_unicode_ci
            clickhouse:
                host:     '%env(resolve:CLICKHOUSE_URL)%'
                port:     '%env(resolve:CLICKHOUSE_PORT)%'
                user:     '%env(resolve:CLICKHOUSE_USER)%'
                password: '%env(resolve:CLICKHOUSE_PWD)%'
                dbname:   '%env(resolve:CLICKHOUSE_DBNAME)%'
                driver_class: FOD\DBALClickHouse\Driver
                wrapper_class: FOD\DBALClickHouse\Connection
                options:
                    enable_http_compression: 1
                    max_execution_time: 60
    orm:
        auto_generate_proxy_classes: true
        default_entity_manager: default
        entity_managers:
            default:
                connection: maria
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
                auto_mapping: true
                mappings:
                    App:
                        is_bundle: false
                        type: staticphp
                        dir: '%kernel.project_dir%/src/Entity/'
                        prefix: 'App\Entity'
                        alias: App
            clickhouse:
                connection: clickhouse
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
                mappings:
                    App:
                        is_bundle: false
                        type: staticphp
                        dir: '%kernel.project_dir%/src/EntityClickhouse/'
                        prefix: 'App\EntityClickhouse'
                        alias: Clickhouse

Then i generate a Migration and i try to create a table following the Reame

but $fromSchema = $conn->getSchemaManager()->createSchema();
generate a error :

  [ClickHouseDB\Exception\DatabaseException (60)]        
  Table api_client.computed doesn't exist.               
  IN:DESCRIBE TABLE `api_client`.`computed` FORMAT JSON  

'api_client' is the dbname ( already created ).
i didn't know why they look for 'computed' table ...
( this table didn't exist, the db is empty )

Detect PK in MergeTree table fails

When I'm trying to create mapping from table in MergeTree by command

php bin/console doctrine:mapping:import App\\Entity xml --path=config/doctrine --em=clickhouse

it returns following

In DatabaseDriver.php line 288:
                                                                                                 
  Table stat has no primary key. Doctrine does not support reverse engineering from tables that  
   don't have a primary key.                 

Outdated dbal

outdated interface ResultStatement error on execution:

Compile Error: Declaration of FOD\DBALClickHouse\ClickHouseStatement::fetch($fetchMode = null) must be compatible with Doctrine\DBA  
  L\Driver\ResultStatement::fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) 

changed the interface to mysql port 9004

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.