| Actor | Fragment | Worker | State |
|---|---|---|---|
| 54110 | 2481 | 3 | running |
| 54111 | 2481 | 3 | running |
| 54112 | 2482 | 3 | running |
| 54113 | 2482 | 3 | running |
| 54142 | 2475 | 3 | running |
| 54143 | 2475 | 3 | running |
| 54144 | 2476 | 3 | running |
| 54145 | 2476 | 3 | running |
| 54146 | 2477 | 3 | running |
| 54147 | 2477 | 3 | running |
| 54148 | 2478 | 3 | running |
| 54149 | 2478 | 3 | running |
CREATE MATERIALIZED VIEW insights.accruals_agg_mv AS
SELECT
a.account_id,
a.asset_id,
a.fact_date AS dim_value_date,
COALESCE(h.currency_code, a.currency) AS currency_code,
CASE WHEN a.type = 'EXPENSE' THEN 'LIABILITY' ELSE 'ASSET' END AS type,
SUM(
a.amount * COALESCE(
fx_accrual.rate,
CASE WHEN a.currency = COALESCE(h.currency_code, a.currency) THEN 1 ELSE NULL END
)
) AS accrued_amount,
SUM(
a.amount * COALESCE(fx_sys.rate, CASE WHEN a.currency = 'SAR' THEN 1 ELSE NULL END)
) AS accrued_value_system_currency
FROM olap.accruals_ft AS a
LEFT JOIN olap.holding_values_raw_ft AS h
ON h.account_id = a.account_id
AND h.asset_id = a.asset_id
AND h.dim_value_date = a.fact_date
AND h.type = CASE WHEN a.type = 'EXPENSE' THEN 'LIABILITY' ELSE 'ASSET' END
LEFT JOIN asset_service.foreign_exchange_rates_eod_ft AS fx_accrual
ON fx_accrual.source_currency_code = a.currency
AND fx_accrual.target_currency_code = COALESCE(h.currency_code, a.currency)
AND fx_accrual.date = a.fact_date
LEFT JOIN asset_service.foreign_exchange_rates_eod_ft AS fx_sys
ON fx_sys.source_currency_code = a.currency
AND fx_sys.target_currency_code = 'SAR'
AND fx_sys.date = a.fact_date
WHERE
NOT a.is_included
AND (
NOT fx_accrual.rate IS NULL OR a.currency = COALESCE(h.currency_code, a.currency)
)
AND (
NOT fx_sys.rate IS NULL OR a.currency = 'SAR'
)
GROUP BY
a.account_id,
a.asset_id,
a.fact_date,
COALESCE(h.currency_code, a.currency),
CASE WHEN a.type = 'EXPENSE' THEN 'LIABILITY' ELSE 'ASSET' END