| Actor | Fragment | Worker | State |
|---|---|---|---|
| 737801 | 52429 | 51 | running |
| 737802 | 52429 | 51 | running |
| 737803 | 52430 | 51 | running |
| 737804 | 52430 | 51 | running |
| 737875 | 52434 | 51 | running |
| 737876 | 52434 | 51 | running |
| 737889 | 52432 | 51 | running |
| 737890 | 52432 | 51 | running |
| 737891 | 52431 | 51 | running |
| 737892 | 52431 | 51 | running |
| 737893 | 52433 | 51 | running |
| 737894 | 52433 | 51 | running |
CREATE MATERIALIZED VIEW alinma_bff.portfolio_owners_mv AS
WITH owner_rows AS (
SELECT
cp.portfolio_id,
c.id AS owner_id,
c.display_name,
c.local_display_name,
c.preferred_name,
cp.owner_type
FROM olap.clients_portfolios_dm AS cp
JOIN olap.clients_dm AS c
ON c.id = cp.client_id AND c.closing_date IS NULL
WHERE
cp.disabled_at IS NULL AND cp.effective_end_date IS NULL
UNION ALL
SELECT
ptp.portfolio_id,
p.id AS owner_id,
p.display_name,
CAST(NULL AS VARCHAR) AS local_display_name,
CAST(NULL AS VARCHAR) AS preferred_name,
CASE
WHEN ptp.involvement_type = 'PORTFOLIO_HOLDER'
THEN 'PRIMARY'
ELSE 'SECONDARY'
END AS owner_type
FROM alinma_bff.party_active_portfolio_involvements_mv AS ptp
JOIN party.parties AS p
ON p.id = ptp.party_id AND p.disabled_at IS NULL
)
SELECT
portfolio_id,
JSONB_AGG(
JSONB_BUILD_OBJECT(
'id',
owner_id,
'displayName',
display_name,
'localDisplayName',
local_display_name,
'preferredName',
preferred_name,
'ownerType',
owner_type
) ORDER BY owner_id
) AS owners,
CAST(COUNT(*) AS INT) AS owner_count
FROM owner_rows
GROUP BY
portfolio_id