Skip to main content

fluss/rpc/message/
create_table.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::{JsonSerde, TableDescriptor, TablePath};
19use crate::{impl_read_version_type, impl_write_version_type, proto};
20
21use crate::error::Result as FlussResult;
22use crate::proto::CreateTableResponse;
23use crate::rpc::api_key::ApiKey;
24use crate::rpc::api_version::ApiVersion;
25use crate::rpc::convert::to_table_path;
26use crate::rpc::frame::ReadError;
27use crate::rpc::frame::WriteError;
28use crate::rpc::message::{ReadVersionedType, RequestBody, WriteVersionedType};
29
30use bytes::{Buf, BufMut};
31use prost::Message;
32
33#[derive(Debug)]
34pub struct CreateTableRequest {
35    pub inner_request: proto::CreateTableRequest,
36}
37
38impl CreateTableRequest {
39    pub fn new(
40        table_path: &TablePath,
41        table_descriptor: &TableDescriptor,
42        ignore_if_exists: bool,
43    ) -> FlussResult<Self> {
44        Ok(CreateTableRequest {
45            inner_request: proto::CreateTableRequest {
46                table_path: to_table_path(table_path),
47                table_json: serde_json::to_vec(&table_descriptor.serialize_json()?).unwrap(),
48                ignore_if_exists,
49            },
50        })
51    }
52}
53
54impl RequestBody for CreateTableRequest {
55    type ResponseBody = CreateTableResponse;
56
57    const API_KEY: ApiKey = ApiKey::CreateTable;
58
59    const REQUEST_VERSION: ApiVersion = ApiVersion(0);
60}
61
62impl_write_version_type!(CreateTableRequest);
63impl_read_version_type!(CreateTableResponse);