common_meta/ddl/
physical_table_metadata.rs1use std::collections::HashSet;
16
17use api::v1::SemanticType;
18use store_api::metadata::ColumnMetadata;
19use table::metadata::RawTableInfo;
20
21pub(crate) fn build_new_physical_table_info(
23 mut raw_table_info: RawTableInfo,
24 physical_columns: &[ColumnMetadata],
25) -> RawTableInfo {
26 let existing_columns = raw_table_info
27 .meta
28 .schema
29 .column_schemas
30 .iter()
31 .map(|col| col.name.clone())
32 .collect::<HashSet<_>>();
33 let primary_key_indices = &mut raw_table_info.meta.primary_key_indices;
34 let value_indices = &mut raw_table_info.meta.value_indices;
35 value_indices.clear();
36 let time_index = &mut raw_table_info.meta.schema.timestamp_index;
37 let columns = &mut raw_table_info.meta.schema.column_schemas;
38 columns.clear();
39
40 for (idx, col) in physical_columns.iter().enumerate() {
41 match col.semantic_type {
42 SemanticType::Tag => {
43 if !existing_columns.contains(&col.column_schema.name) {
45 primary_key_indices.push(idx);
46 }
47 }
48 SemanticType::Field => value_indices.push(idx),
49 SemanticType::Timestamp => *time_index = Some(idx),
50 }
51
52 columns.push(col.column_schema.clone());
53 }
54
55 if let Some(time_index) = *time_index {
56 raw_table_info.meta.schema.column_schemas[time_index].set_time_index();
57 }
58
59 raw_table_info
60}