common_meta/ddl/utils/
table_info.rs

1// Copyright 2023 Greptime Team
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 snafu::OptionExt;
16use store_api::storage::TableId;
17use table::table_reference::TableReference;
18
19use crate::error::{Result, TableInfoNotFoundSnafu};
20use crate::key::table_info::{TableInfoManager, TableInfoValue};
21use crate::key::DeserializedValueWithBytes;
22
23/// Get all table info values by table ids.
24///
25/// Returns an error if any table does not exist.
26pub(crate) async fn get_all_table_info_values_by_table_ids<'a>(
27    table_info_manager: &TableInfoManager,
28    table_ids: &[TableId],
29    table_names: &[TableReference<'a>],
30) -> Result<Vec<DeserializedValueWithBytes<TableInfoValue>>> {
31    let mut table_info_map = table_info_manager.batch_get_raw(table_ids).await?;
32    let mut table_info_values = Vec::with_capacity(table_ids.len());
33    for (table_id, table_name) in table_ids.iter().zip(table_names) {
34        let table_info_value =
35            table_info_map
36                .remove(table_id)
37                .with_context(|| TableInfoNotFoundSnafu {
38                    table: table_name.to_string(),
39                })?;
40        table_info_values.push(table_info_value);
41    }
42
43    Ok(table_info_values)
44}