Skip to main content

fluss/rpc/message/
update_metadata.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use crate::metadata::{PhysicalTablePath, TablePath};
19use crate::proto::{MetadataResponse, PbPhysicalTablePath, PbTablePath};
20use crate::rpc::api_key::ApiKey;
21use crate::rpc::api_version::ApiVersion;
22use crate::rpc::frame::ReadError;
23use crate::rpc::frame::WriteError;
24use crate::rpc::message::{ReadVersionedType, RequestBody, WriteVersionedType};
25use std::collections::HashSet;
26use std::sync::Arc;
27
28use crate::{impl_read_version_type, impl_write_version_type, proto};
29use bytes::{Buf, BufMut};
30use prost::Message;
31
32pub struct UpdateMetadataRequest {
33    pub inner_request: proto::MetadataRequest,
34}
35
36impl UpdateMetadataRequest {
37    pub fn new(
38        table_paths: &HashSet<&TablePath>,
39        physical_table_paths: &HashSet<&Arc<PhysicalTablePath>>,
40        partition_ids: Vec<i64>,
41    ) -> Self {
42        UpdateMetadataRequest {
43            inner_request: proto::MetadataRequest {
44                table_path: table_paths
45                    .iter()
46                    .map(|path| PbTablePath {
47                        database_name: path.database().to_string(),
48                        table_name: path.table().to_string(),
49                    })
50                    .collect(),
51                partitions_path: physical_table_paths
52                    .iter()
53                    .map(|path| PbPhysicalTablePath {
54                        database_name: path.get_database_name().to_string(),
55                        table_name: path.get_table_name().to_string(),
56                        partition_name: path.get_partition_name().map(|pn| pn.to_string()),
57                    })
58                    .collect(),
59                partitions_id: partition_ids,
60            },
61        }
62    }
63}
64
65impl RequestBody for UpdateMetadataRequest {
66    type ResponseBody = MetadataResponse;
67
68    const API_KEY: ApiKey = ApiKey::MetaData;
69
70    const REQUEST_VERSION: ApiVersion = ApiVersion(0);
71}
72
73impl_write_version_type!(UpdateMetadataRequest);
74impl_read_version_type!(MetadataResponse);