operator/req_convert/
insert.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
15mod column_to_row;
16mod fill_impure_default;
17mod row_to_region;
18mod stmt_to_region;
19mod table_to_region;
20
21use api::v1::SemanticType;
22pub use column_to_row::ColumnToRow;
23pub use fill_impure_default::fill_reqs_with_impure_default;
24pub use row_to_region::RowToRegion;
25use snafu::{OptionExt, ResultExt};
26pub use stmt_to_region::StatementToRegion;
27use table::metadata::TableInfo;
28pub use table_to_region::TableToRegion;
29
30use crate::error::{ColumnNotFoundSnafu, MissingTimeIndexColumnSnafu, Result};
31
32fn semantic_type(table_info: &TableInfo, column: &str) -> Result<SemanticType> {
33    let table_meta = &table_info.meta;
34    let table_schema = &table_meta.schema;
35
36    let time_index_column = &table_schema
37        .timestamp_column()
38        .with_context(|| table::error::MissingTimeIndexColumnSnafu {
39            table_name: table_info.name.to_string(),
40        })
41        .context(MissingTimeIndexColumnSnafu)?
42        .name;
43
44    let semantic_type = if column == time_index_column {
45        SemanticType::Timestamp
46    } else {
47        let column_index = table_schema.column_index_by_name(column);
48        let column_index = column_index.context(ColumnNotFoundSnafu {
49            msg: format!("unable to find column {column} in table schema"),
50        })?;
51
52        if table_meta.primary_key_indices.contains(&column_index) {
53            SemanticType::Tag
54        } else {
55            SemanticType::Field
56        }
57    };
58
59    Ok(semantic_type)
60}