| Actor | Fragment | Worker | State |
|---|---|---|---|
| 157586 | 12721 | 33 | running |
| 157587 | 12721 | 33 | running |
| 157588 | 12720 | 33 | running |
| 157589 | 12720 | 33 | running |
| 157590 | 12722 | 33 | running |
| 157591 | 12722 | 33 | running |
| 157678 | 12728 | 33 | running |
| 157679 | 12728 | 33 | running |
| 157718 | 12723 | 33 | running |
| 157719 | 12723 | 33 | running |
| 157720 | 12724 | 33 | running |
| 157721 | 12724 | 33 | running |
CREATE MATERIALIZED VIEW insights.client_account_via_portfolio_mv AS
SELECT
client_id,
account_id,
effective_start_date,
effective_end_date,
type
FROM (
SELECT
cp.client_id,
atp.account_id,
GREATEST(atp.effective_start_date, cp.effective_start_date) AS effective_start_date,
CASE
WHEN atp.effective_end_date IS NULL AND cp.effective_end_date IS NULL
THEN CAST(NULL AS DATE)
WHEN atp.effective_end_date IS NULL
THEN cp.effective_end_date
WHEN cp.effective_end_date IS NULL
THEN atp.effective_end_date
ELSE LEAST(atp.effective_end_date, cp.effective_end_date)
END AS effective_end_date,
CAST('all' AS VARCHAR) AS type
FROM olap.account_to_portfolios_dm AS atp
JOIN olap.clients_portfolios_dm AS cp
ON cp.portfolio_id = atp.portfolio_id
JOIN insights.open_accounts_mv AS oa
ON oa.account_id = atp.account_id
WHERE
atp.disabled_at IS NULL
AND cp.disabled_at IS NULL
AND (
atp.effective_end_date IS NULL
OR atp.effective_end_date > atp.effective_start_date
)
AND NOT EXISTS(
SELECT
1
FROM olap.accounts_to_clients_dm AS atc
WHERE
atc.account_id = atp.account_id
AND atc.client_id = cp.client_id
AND atc.disabled_at IS NULL
AND (
atc.effective_end_date IS NULL
OR atc.effective_end_date > atc.effective_start_date
)
)
) AS intervals
WHERE
effective_end_date IS NULL OR effective_start_date < effective_end_date