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

Missing columns exception #136

Open
zserg84 opened this issue Apr 6, 2020 · 0 comments
Open

Missing columns exception #136

zserg84 opened this issue Apr 6, 2020 · 0 comments

Comments

@zserg84
Copy link

zserg84 commented Apr 6, 2020

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

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

1 participant