RWM Console cluster: risingwave-adib.adib-rw.svc.cluster.local

← cluster insights objects twrr_by_distribution_mv
Overview Objects Graph History
materialized view · insights.twrr_by_distribution_mv Explain plan ▶
Parallelism
2
Actors
10 / 10
running
Distribution
HASH
Rows
70,963
State size
20.8 MiB
Created
2026-08-25 16:51
Initialized
2026-08-25 16:50
Fragment flags
MVIEWSNAPSHOT_BACKFILL_STREAM_SCANSTREAM_SCAN
Actors
ActorFragmentWorkerState
114951 24517 26 running
114952 24517 26 running
114953 24516 26 running
114954 24516 26 running
114955 24519 26 running
114956 24519 26 running
114957 24518 26 running
114958 24518 26 running
114959 24520 26 running
114960 24520 26 running
sql · insights.twrr_by_distribution_mv — click to expand
CREATE MATERIALIZED VIEW insights.twrr_by_distribution_mv AS
WITH daily_balances AS (
  SELECT
    b.account_group_id,
    dim_balance_date,
    position_type,
    distribution_type,
    taxonomy_node_id,
    taxonomy_code,
    currency_code,
    market_value,
    fair_value,
    market_value_system_currency,
    fair_value_system_currency,
    LAG(market_value) OVER w AS prev_market_value,
    LAG(fair_value) OVER w AS prev_fair_value,
    LAG(market_value_system_currency) OVER w AS prev_market_value_system_currency,
    LAG(fair_value_system_currency) OVER w AS prev_fair_value_system_currency
  FROM insights.position_by_distribution_mv AS b
  WHERE
    position_type = 'POSITION' AND b.source_entity_type = 'portfolio'
  WINDOW w AS (
    PARTITION BY b.account_group_id, position_type, distribution_type, taxonomy_node_id
    ORDER BY dim_balance_date
  )
), twrr_data AS (
  SELECT
    b.account_group_id,
    b.dim_balance_date,
    b.distribution_type,
    b.taxonomy_node_id,
    b.taxonomy_code,
    b.currency_code,
    b.market_value,
    b.prev_market_value,
    b.fair_value,
    b.prev_fair_value,
    b.market_value_system_currency,
    b.prev_market_value_system_currency,
    b.fair_value_system_currency,
    b.prev_fair_value_system_currency,
    COALESCE(t.adjusted_net_flow, 0) AS net_flow,
    COALESCE(t.adjusted_net_flow_system_currency, 0) AS net_flow_system_currency
  FROM daily_balances AS b
  LEFT JOIN insights.flow_by_distribution_mv AS t
    ON b.account_group_id = t.account_group_id
    AND b.dim_balance_date = t.dim_transaction_date
    AND b.distribution_type = t.distribution_type
    AND b.taxonomy_node_id = t.taxonomy_node_id
    AND t.position_type = 'POSITION'
)
SELECT
  account_group_id,
  dim_balance_date,
  distribution_type,
  taxonomy_node_id,
  taxonomy_code,
  currency_code,
  market_value,
  prev_market_value,
  net_flow,
  CASE
    WHEN prev_market_value IS NULL OR prev_market_value = 0
    THEN 0
    WHEN market_value = 0
    THEN 0
    WHEN market_value - net_flow < 0 AND prev_market_value + net_flow > 0
    THEN GREATEST(market_value / (
      prev_market_value + net_flow
    ) - 1, -0.999999999999999999)
    ELSE GREATEST((
      market_value - net_flow
    ) / prev_market_value - 1, -0.999999999999999999)
  END AS daily_subperiod_return,
  CASE
    WHEN prev_fair_value IS NULL OR prev_fair_value = 0
    THEN 0
    WHEN fair_value = 0
    THEN 0
    WHEN fair_value - net_flow < 0 AND prev_fair_value + net_flow > 0
    THEN GREATEST(fair_value / (
      prev_fair_value + net_flow
    ) - 1, -0.999999999999999999)
    ELSE GREATEST((
      fair_value - net_flow
    ) / prev_fair_value - 1, -0.999999999999999999)
  END AS daily_subperiod_fair_value_return,
  CASE
    WHEN prev_market_value_system_currency IS NULL
    OR prev_market_value_system_currency = 0
    THEN 0
    WHEN market_value_system_currency = 0
    THEN 0
    WHEN market_value_system_currency - net_flow_system_currency < 0
    AND prev_market_value_system_currency + net_flow_system_currency > 0
    THEN GREATEST(
      market_value_system_currency / (
        prev_market_value_system_currency + net_flow_system_currency
      ) - 1,
      -0.999999999999999999
    )
    ELSE GREATEST(
      (
        market_value_system_currency - net_flow_system_currency
      ) / prev_market_value_system_currency - 1,
      -0.999999999999999999
    )
  END AS daily_subperiod_return_system_currency,
  CASE
    WHEN prev_fair_value_system_currency IS NULL OR prev_fair_value_system_currency = 0
    THEN 0
    WHEN fair_value_system_currency = 0
    THEN 0
    WHEN fair_value_system_currency - net_flow_system_currency < 0
    AND prev_fair_value_system_currency + net_flow_system_currency > 0
    THEN GREATEST(
      fair_value_system_currency / (
        prev_fair_value_system_currency + net_flow_system_currency
      ) - 1,
      -0.999999999999999999
    )
    ELSE GREATEST(
      (
        fair_value_system_currency - net_flow_system_currency
      ) / prev_fair_value_system_currency - 1,
      -0.999999999999999999
    )
  END AS daily_subperiod_fair_value_return_system_currency
FROM twrr_data
WHERE
  NOT prev_market_value IS NULL
Lineage · insights.twrr_by_distribution_mv 11 objects
Direct (1-hop) dependencies from rw_depend, across schemas. Click a neighbor to expand its dependencies; ⌘/Ctrl-click opens its page. Drag to pan, scroll to zoom. External source/sink endpoints (Kafka, Iceberg) are not shown.