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 column metadata of a table.
78pub const TABLE_COLUMN_METADATA_EXTENSION_KEY: &str = "TABLE_COLUMN_METADATA";
79
80/// HashMap key to be used in the region server's extension response.
81/// Represent the manifest info of a region.
82pub const MANIFEST_INFO_EXTENSION_KEY: &str = "MANIFEST_INFO";
83
84/// Returns true if it's a internal column of the metric engine.
85pub fn is_metric_engine_internal_column(name: &str) -> bool {
86    name == DATA_SCHEMA_TABLE_ID_COLUMN_NAME || name == DATA_SCHEMA_TSID_COLUMN_NAME
87}
88
89/// Returns true if it's metric engine
90pub fn is_metric_engine(name: &str) -> bool {
91    name == METRIC_ENGINE_NAME
92}
93
94/// Option key for metric engine index type.
95/// Used to identify the primary key index type of the metric engine.
96/// ```sql
97/// CREATE TABLE table_name (
98///     ...
99/// )
100/// ENGINE = metric
101/// WITH (
102///     physical_metric_table = "",
103///     index.type = "inverted",
104///     index.inverted_index.segment_row_count = "256",
105/// );
106/// ```
107pub const METRIC_ENGINE_INDEX_TYPE_OPTION: &str = "index.type";
108
109/// Option key for the granularity of the skipping index in the metric engine.
110/// This key is used to specify the granularity of the primary key index (skipping index) in the metric engine.
111/// ```sql
112/// CREATE TABLE table_name (
113///     ...
114/// )
115/// ENGINE = metric
116/// WITH (
117///     physical_metric_table = "",
118///     index.type = "skipping",
119///     index.granularity = "102400",
120///     index.false_positive_rate = "0.01",
121/// );
122/// ```
123pub const METRIC_ENGINE_INDEX_SKIPPING_INDEX_GRANULARITY_OPTION: &str = "index.granularity";
124pub const METRIC_ENGINE_INDEX_SKIPPING_INDEX_FALSE_POSITIVE_RATE_OPTION: &str =
125    "index.false_positive_rate";
126
127/// Default granularity for the skipping index in the metric engine.
128pub const METRIC_ENGINE_INDEX_SKIPPING_INDEX_GRANULARITY_OPTION_DEFAULT: u32 = 102400;
129
130/// Default false positive rate for the skipping index in the metric engine.
131pub const METRIC_ENGINE_INDEX_SKIPPING_INDEX_FALSE_POSITIVE_RATE_OPTION_DEFAULT: f64 = 0.01;
132
133/// Returns true if the `key` is a valid option key for the metric engine.
134pub fn is_metric_engine_option_key(key: &str) -> bool {
135    [
136        PHYSICAL_TABLE_METADATA_KEY,
137        LOGICAL_TABLE_METADATA_KEY,
138        METRIC_ENGINE_INDEX_TYPE_OPTION,
139        METRIC_ENGINE_INDEX_SKIPPING_INDEX_GRANULARITY_OPTION,
140        METRIC_ENGINE_INDEX_SKIPPING_INDEX_FALSE_POSITIVE_RATE_OPTION,
141    ]
142    .contains(&key)
143}