common_catalog/
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
15pub const SYSTEM_CATALOG_NAME: &str = "system";
16pub const INFORMATION_SCHEMA_NAME: &str = "information_schema";
17pub const PG_CATALOG_NAME: &str = "pg_catalog";
18pub const SYSTEM_CATALOG_TABLE_NAME: &str = "system_catalog";
19pub const DEFAULT_CATALOG_NAME: &str = "greptime";
20pub const DEFAULT_SCHEMA_NAME: &str = "public";
21pub const DEFAULT_PRIVATE_SCHEMA_NAME: &str = "greptime_private";
22
23/// Reserves [0,MIN_USER_FLOW_ID) for internal usage.
24/// User defined table id starts from this value.
25pub const MIN_USER_FLOW_ID: u32 = 1024;
26/// Reserves [0,MIN_USER_TABLE_ID) for internal usage.
27/// User defined table id starts from this value.
28pub const MIN_USER_TABLE_ID: u32 = 1024;
29/// the max system table id
30pub const MAX_SYS_TABLE_ID: u32 = MIN_USER_TABLE_ID - 1;
31/// system_catalog table id
32pub const SYSTEM_CATALOG_TABLE_ID: u32 = 0;
33/// scripts table id
34pub const SCRIPTS_TABLE_ID: u32 = 1;
35/// numbers table id
36pub const NUMBERS_TABLE_ID: u32 = 2;
37
38/// ----- Begin of information_schema tables -----
39/// id for information_schema.tables
40pub const INFORMATION_SCHEMA_TABLES_TABLE_ID: u32 = 3;
41/// id for information_schema.columns
42pub const INFORMATION_SCHEMA_COLUMNS_TABLE_ID: u32 = 4;
43/// id for information_schema.engines
44pub const INFORMATION_SCHEMA_ENGINES_TABLE_ID: u32 = 5;
45/// id for information_schema.column_privileges
46pub const INFORMATION_SCHEMA_COLUMN_PRIVILEGES_TABLE_ID: u32 = 6;
47/// id for information_schema.column_statistics
48pub const INFORMATION_SCHEMA_COLUMN_STATISTICS_TABLE_ID: u32 = 7;
49/// id for information_schema.build_info
50pub const INFORMATION_SCHEMA_BUILD_INFO_TABLE_ID: u32 = 8;
51/// id for information_schema.CHARACTER_SETS
52pub const INFORMATION_SCHEMA_CHARACTER_SETS_TABLE_ID: u32 = 9;
53/// id for information_schema.COLLATIONS
54pub const INFORMATION_SCHEMA_COLLATIONS_TABLE_ID: u32 = 10;
55/// id for information_schema.COLLATIONS
56pub const INFORMATION_SCHEMA_COLLATION_CHARACTER_SET_APPLICABILITY_TABLE_ID: u32 = 11;
57/// id for information_schema.CHECK_CONSTRAINTS
58pub const INFORMATION_SCHEMA_CHECK_CONSTRAINTS_TABLE_ID: u32 = 12;
59/// id for information_schema.EVENTS
60pub const INFORMATION_SCHEMA_EVENTS_TABLE_ID: u32 = 13;
61/// id for information_schema.FILES
62pub const INFORMATION_SCHEMA_FILES_TABLE_ID: u32 = 14;
63/// id for information_schema.SCHEMATA
64pub const INFORMATION_SCHEMA_SCHEMATA_TABLE_ID: u32 = 15;
65/// id for information_schema.KEY_COLUMN_USAGE
66pub const INFORMATION_SCHEMA_KEY_COLUMN_USAGE_TABLE_ID: u32 = 16;
67/// id for information_schema.OPTIMIZER_TRACE
68pub const INFORMATION_SCHEMA_OPTIMIZER_TRACE_TABLE_ID: u32 = 17;
69/// id for information_schema.PARAMETERS
70pub const INFORMATION_SCHEMA_PARAMETERS_TABLE_ID: u32 = 18;
71/// id for information_schema.PROFILING
72pub const INFORMATION_SCHEMA_PROFILING_TABLE_ID: u32 = 19;
73/// id for information_schema.REFERENTIAL_CONSTRAINTS
74pub const INFORMATION_SCHEMA_REFERENTIAL_CONSTRAINTS_TABLE_ID: u32 = 20;
75/// id for information_schema.ROUTINES
76pub const INFORMATION_SCHEMA_ROUTINES_TABLE_ID: u32 = 21;
77/// id for information_schema.SCHEMA_PRIVILEGES
78pub const INFORMATION_SCHEMA_SCHEMA_PRIVILEGES_TABLE_ID: u32 = 22;
79/// id for information_schema.TABLE_PRIVILEGES
80pub const INFORMATION_SCHEMA_TABLE_PRIVILEGES_TABLE_ID: u32 = 23;
81/// id for information_schema.TRIGGERS
82pub const INFORMATION_SCHEMA_TRIGGERS_TABLE_ID: u32 = 24;
83/// id for information_schema.GLOBAL_STATUS
84pub const INFORMATION_SCHEMA_GLOBAL_STATUS_TABLE_ID: u32 = 25;
85/// id for information_schema.SESSION_STATUS
86pub const INFORMATION_SCHEMA_SESSION_STATUS_TABLE_ID: u32 = 26;
87/// id for information_schema.RUNTIME_METRICS
88pub const INFORMATION_SCHEMA_RUNTIME_METRICS_TABLE_ID: u32 = 27;
89/// id for information_schema.PARTITIONS
90pub const INFORMATION_SCHEMA_PARTITIONS_TABLE_ID: u32 = 28;
91/// id for information_schema.REGION_PEERS
92pub const INFORMATION_SCHEMA_REGION_PEERS_TABLE_ID: u32 = 29;
93/// id for information_schema.columns
94pub const INFORMATION_SCHEMA_TABLE_CONSTRAINTS_TABLE_ID: u32 = 30;
95/// id for information_schema.cluster_info
96pub const INFORMATION_SCHEMA_CLUSTER_INFO_TABLE_ID: u32 = 31;
97/// id for information_schema.VIEWS
98pub const INFORMATION_SCHEMA_VIEW_TABLE_ID: u32 = 32;
99/// id for information_schema.FLOWS
100pub const INFORMATION_SCHEMA_FLOW_TABLE_ID: u32 = 33;
101/// id for information_schema.procedure_info
102pub const INFORMATION_SCHEMA_PROCEDURE_INFO_TABLE_ID: u32 = 34;
103/// id for information_schema.region_statistics
104pub const INFORMATION_SCHEMA_REGION_STATISTICS_TABLE_ID: u32 = 35;
105
106// ----- End of information_schema tables -----
107
108/// ----- Begin of pg_catalog tables -----
109pub const PG_CATALOG_PG_CLASS_TABLE_ID: u32 = 256;
110pub const PG_CATALOG_PG_TYPE_TABLE_ID: u32 = 257;
111pub const PG_CATALOG_PG_NAMESPACE_TABLE_ID: u32 = 258;
112pub const PG_CATALOG_PG_DATABASE_TABLE_ID: u32 = 259;
113
114// ----- End of pg_catalog tables -----
115
116pub const MITO_ENGINE: &str = "mito";
117pub const MITO2_ENGINE: &str = "mito2";
118pub const METRIC_ENGINE: &str = "metric";
119
120pub fn default_engine() -> &'static str {
121    MITO_ENGINE
122}
123
124pub const FILE_ENGINE: &str = "file";
125
126pub const SEMANTIC_TYPE_PRIMARY_KEY: &str = "TAG";
127pub const SEMANTIC_TYPE_FIELD: &str = "FIELD";
128pub const SEMANTIC_TYPE_TIME_INDEX: &str = "TIMESTAMP";
129
130pub fn is_readonly_schema(schema: &str) -> bool {
131    matches!(schema, INFORMATION_SCHEMA_NAME)
132}
133
134// ---- special table and fields ----
135pub const TRACE_ID_COLUMN: &str = "trace_id";
136pub const SPAN_ID_COLUMN: &str = "span_id";
137pub const SPAN_NAME_COLUMN: &str = "span_name";
138pub const SERVICE_NAME_COLUMN: &str = "service_name";
139pub const PARENT_SPAN_ID_COLUMN: &str = "parent_span_id";
140pub const TRACE_TABLE_NAME: &str = "opentelemetry_traces";
141pub const TRACE_TABLE_NAME_SESSION_KEY: &str = "trace_table_name";
142// ---- End of special table and fields ----
143
144/// Generate the trace services table name from the trace table name by adding `_services` suffix.
145pub fn trace_services_table_name(trace_table_name: &str) -> String {
146    format!("{}_services", trace_table_name)
147}
148// ---- End of special table and fields ----