Skip to content

Missing columns exception #136

Open
Open
@zserg84

Description

@zserg84

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();
    }

Снимок экрана в 2020-04-06 11-48-01

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions