risingwave_frontend/expr/function_impl/
rw_actor_vnodes.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::Arc;
16
17use risingwave_common::types::JsonbVal;
18use risingwave_expr::{ExprError, Result, capture_context, function};
19use serde_json::json;
20
21use super::context::META_CLIENT;
22use crate::meta_client::FrontendMetaClient;
23
24#[function("rw_actor_vnodes(int4) -> jsonb", volatile)]
25async fn rw_actor_vnodes(actor_id: i32) -> Result<JsonbVal> {
26    rw_actor_vnodes_impl_captured(actor_id).await
27}
28
29#[capture_context(META_CLIENT)]
30async fn rw_actor_vnodes_impl(
31    meta_client: &Arc<dyn FrontendMetaClient>,
32    actor_id: i32,
33) -> Result<JsonbVal> {
34    let vnode_indices = meta_client
35        .get_actor_vnodes((actor_id as u32).into())
36        .await
37        .map_err(|e| ExprError::Internal(e.into()))?;
38
39    Ok(json!(vnode_indices).into())
40}