phpClickHouse
phpClickHouse copied to clipboard
Missing columns exception
Hi guys. I get this error approximately 50% of cases. And in other 50% of cases everithing is ok. Do you have any ideas what's wrong?
That is my code:
public function transactions(string $accountId, AnalyticTransactionModel $analyticTransactionModel): array
{
$client = $this->clickhouseClient;
$client->cleanQueryDegeneration();
$client->enableQueryConditions();
$client->addQueryDegeneration(new Bindings());
$bindings = [
'account' => $accountId,
];
if ($analyticTransactionModel->interval !== null) {
$bindings['interval'] = $analyticTransactionModel->interval;
}
if ($analyticTransactionModel->dateFrom !== null) {
$bindings['dateFrom'] = $analyticTransactionModel->dateFrom;
}
if ($analyticTransactionModel->dateTo !== null) {
$bindings['dateTo'] = $analyticTransactionModel->dateTo;
}
if ($analyticTransactionModel->operation !== null) {
$bindings['operation'] = $analyticTransactionModel->operation;
}
if ($analyticTransactionModel->oppositeAccountType !== null) {
$bindings['oppositeAccountType'] = $analyticTransactionModel->oppositeAccountType;
}
if ($analyticTransactionModel->oppositeAccountId !== null) {
$bindings['oppositeAccountId'] = $analyticTransactionModel->oppositeAccountId;
}
$statement = $client->select('
SELECT
{if interval} toStartOfInterval(toDateTime(created_at), INTERVAL 1 {interval}) {else} null {/if} as date,
account_id,
sum(if(operation=\'debit\', points, -points)) as points,
sum(if(operation=\'debit\', -value, value)) as value,
argMax(current_points, toUnixTimestamp(created_at)) as current_points,
argMax(current_balance, toUnixTimestamp(created_at)) as current_balance,
count(1) as count_transactions
FROM transactions
WHERE account_id = :account
AND {if dateFrom} created_at >= :dateFrom {else} 1 {/if}
AND {if dateTo} created_at <= :dateTo {else} 1 {/if}
AND {if operation} operation = :operation {else} 1 {/if}
AND {if oppositeAccountType} opposite_account_type = :oppositeAccountType {else} 1 {/if}
AND {if oppositeAccountId} opposite_account_id = :oppositeAccountId {else} 1 {/if}
GROUP BY account_id {if interval} , date {/if}
ORDER BY account_id {if interval}, date {/if}
', $bindings);
return $statement->rows();
}