store_api/metric_engine_consts.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
15//! Constants used in metric engine.
16
17use crate::storage::RegionGroup;
18
19/// region group value for data region inside a metric region
20pub const METRIC_DATA_REGION_GROUP: RegionGroup = 0;
21
22/// region group value for metadata region inside a metric region
23pub const METRIC_METADATA_REGION_GROUP: RegionGroup = 1;
24
25pub const METADATA_SCHEMA_TIMESTAMP_COLUMN_NAME: &str = "ts";
26pub const METADATA_SCHEMA_KEY_COLUMN_NAME: &str = "k";
27pub const METADATA_SCHEMA_VALUE_COLUMN_NAME: &str = "v";
28
29pub const METADATA_SCHEMA_TIMESTAMP_COLUMN_INDEX: usize = 0;
30pub const METADATA_SCHEMA_KEY_COLUMN_INDEX: usize = 1;
31pub const METADATA_SCHEMA_VALUE_COLUMN_INDEX: usize = 2;
32
33/// Column name of internal column `__metric` that stores the original metric name
34pub const DATA_SCHEMA_TABLE_ID_COLUMN_NAME: &str = "__table_id";
35pub const DATA_SCHEMA_TSID_COLUMN_NAME: &str = "__tsid";
36
37pub const METADATA_REGION_SUBDIR: &str = "metadata";
38pub const DATA_REGION_SUBDIR: &str = "data";
39
40pub const METRIC_ENGINE_NAME: &str = "metric";
41
42pub const FILE_ENGINE_NAME: &str = "file";
43
44/// Metadata key present in the `CREATE TABLE ... WITH ()` clause. This key is
45/// used to identify the table is a physical metric table. E.g.:
46/// ```sql
47/// CREATE TABLE physical_table (
48/// ...
49/// )
50/// ENGINE = metric
51/// WITH (
52/// physical_metric_table,
53/// );
54/// ```
55pub const PHYSICAL_TABLE_METADATA_KEY: &str = "physical_metric_table";
56
57/// Metadata key present in the `CREATE TABLE ... WITH ()` clause. This key is
58/// used to identify a logical table and associate it with a corresponding physical
59/// table . E.g.:
60/// ```sql
61/// CREATE TABLE logical_table (
62/// ...
63/// )
64/// ENGINE = metric
65/// WITH (
66/// on_physical_table = "physical_table",
67/// );
68/// ```
69/// And this key will be translated to corresponding physical **REGION** id in metasrv.
70pub const LOGICAL_TABLE_METADATA_KEY: &str = "on_physical_table";
71
72/// HashMap key to be used in the region server's extension response.
73/// Represent a list of column metadata that are added to physical table.
74pub const ALTER_PHYSICAL_EXTENSION_KEY: &str = "ALTER_PHYSICAL";
75
76/// HashMap key to be used in the region server's extension response.
77/// Represent the manifest info of a region.
78pub const MANIFEST_INFO_EXTENSION_KEY: &str = "MANIFEST_INFO";
79
80/// Returns true if it's a internal column of the metric engine.
81pub fn is_metric_engine_internal_column(name: &str) -> bool {
82 name == DATA_SCHEMA_TABLE_ID_COLUMN_NAME || name == DATA_SCHEMA_TSID_COLUMN_NAME
83}
84
85/// Returns true if it's metric engine
86pub fn is_metric_engine(name: &str) -> bool {
87 name == METRIC_ENGINE_NAME
88}
89
90/// Option key for metric engine index type.
91/// Used to identify the primary key index type of the metric engine.
92/// ```sql
93/// CREATE TABLE table_name (
94/// ...
95/// )
96/// ENGINE = metric
97/// WITH (
98/// physical_metric_table = "",
99/// index.type = "inverted",
100/// index.inverted_index.segment_row_count = "256",
101/// );
102/// ```
103pub const METRIC_ENGINE_INDEX_TYPE_OPTION: &str = "index.type";
104
105/// Option key for the granularity of the skipping index in the metric engine.
106/// This key is used to specify the granularity of the primary key index (skipping index) in the metric engine.
107/// ```sql
108/// CREATE TABLE table_name (
109/// ...
110/// )
111/// ENGINE = metric
112/// WITH (
113/// physical_metric_table = "",
114/// index.type = "skipping",
115/// index.granularity = "102400",
116/// );
117/// ```
118pub const METRIC_ENGINE_INDEX_SKIPPING_INDEX_GRANULARITY_OPTION: &str = "index.granularity";
119
120/// Default granularity for the skipping index in the metric engine.
121pub const METRIC_ENGINE_INDEX_SKIPPING_INDEX_GRANULARITY_OPTION_DEFAULT: u32 = 102400;
122
123/// Returns true if the `key` is a valid option key for the metric engine.
124pub fn is_metric_engine_option_key(key: &str) -> bool {
125 [
126 PHYSICAL_TABLE_METADATA_KEY,
127 LOGICAL_TABLE_METADATA_KEY,
128 METRIC_ENGINE_INDEX_TYPE_OPTION,
129 METRIC_ENGINE_INDEX_SKIPPING_INDEX_GRANULARITY_OPTION,
130 ]
131 .contains(&key)
132}