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

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

Open
stepanselyuk opened this issue Jun 2, 2017 · 3 comments
Assignees

Comments

@stepanselyuk
Copy link

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']
);
@stepanselyuk
Copy link
Author

appendLockHint used in a query parsing code, and by default (\Doctrine\DBAL\Platforms\AbstractPlatform::appendLockHint):

    public function appendLockHint($fromClause, $lockMode)
    {
        return $fromClause;
    }

Is there a reason why \FOD\DBALClickHouse\ClickHousePlatform::appendLockHint throws exception?

@mochalygin mochalygin assigned mochalygin and argayash and unassigned mochalygin Jun 2, 2017
@mochalygin
Copy link
Member

Hi, Stepan!

ClickHouse engine does not support locks -- that's why ClickHousePlatform::appendLockHint() throws Exception.

In given query lock is unnecessary. QueryBuilder of ORM layer adds it (we suggest to use DBAL QueryBuilder).

We tried to remove this Exception to allow work with library from ORM layer as well, but we got 2 other errors:

  1. ClickHouse does not support table aliases (QB added them)
  2. ClickHouse does not accept any params in count() except *

We will think how to solve this problem. You can use library without ORM, only with DBAL.

@stepanselyuk
Copy link
Author

stepanselyuk commented Jun 6, 2017

For count() function possible to use user-defined DQL function like this:

<?php

namespace Trim\Clickhouse\DQL;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

/**
 * ROWS_COUNT(str)
 * "ROWS_COUNT" "(" ")".
 */
class RowsCountFunction extends FunctionNode
{
    public function getSql(SqlWalker $sqlWalker)
    {
        return 'COUNT(*)';
    }

    public function parse(Parser $parser)
    {
        $parser->match(Lexer::T_IDENTIFIER);          // ROWS_COUNT
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }
}

But yeah, yet I didn't found a way how to remove aliases from ORM query builder. I tried just to specify alias as empty string, but got other ORM error, like expected end of string, but got other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants