diff --git a/Cargo.lock b/Cargo.lock
index c2bad3d971..f4ff29fb70 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2004,9 +2004,11 @@ dependencies = [
"common-macro",
"common-test-util",
"futures",
+ "lazy_static",
"paste",
"pin-project",
"rand 0.9.1",
+ "regex",
"serde",
"snafu 0.8.6",
"tokio",
@@ -2454,6 +2456,7 @@ dependencies = [
"datafusion-expr",
"datatypes",
"futures-util",
+ "once_cell",
"serde",
"snafu 0.8.6",
"sqlparser",
@@ -7579,6 +7582,7 @@ dependencies = [
"common-decimal",
"common-error",
"common-macro",
+ "common-query",
"common-recordbatch",
"common-telemetry",
"common-time",
diff --git a/config/config.md b/config/config.md
index 72d48b5bcb..1c20e66540 100644
--- a/config/config.md
+++ b/config/config.md
@@ -13,6 +13,7 @@
| Key | Type | Default | Descriptions |
| --- | -----| ------- | ----------- |
| `default_timezone` | String | Unset | The default timezone of the server. |
+| `default_column_prefix` | String | Unset | The default column prefix for auto-created time index and value columns. |
| `init_regions_in_background` | Bool | `false` | Initialize all regions in the background during the startup.
By default, it provides services after all regions have been initialized. |
| `init_regions_parallelism` | Integer | `16` | Parallelism of initializing regions. |
| `max_concurrent_queries` | Integer | `0` | The maximum current queries allowed to be executed. Zero means unlimited. |
@@ -226,6 +227,7 @@
| Key | Type | Default | Descriptions |
| --- | -----| ------- | ----------- |
| `default_timezone` | String | Unset | The default timezone of the server. |
+| `default_column_prefix` | String | Unset | The default column prefix for auto-created time index and value columns. |
| `max_in_flight_write_bytes` | String | Unset | The maximum in-flight write bytes. |
| `runtime` | -- | -- | The runtime options. |
| `runtime.global_rt_size` | Integer | `8` | The number of threads to execute the runtime for global read operations. |
@@ -440,6 +442,7 @@
| Key | Type | Default | Descriptions |
| --- | -----| ------- | ----------- |
| `node_id` | Integer | Unset | The datanode identifier and should be unique in the cluster. |
+| `default_column_prefix` | String | Unset | The default column prefix for auto-created time index and value columns. |
| `require_lease_before_startup` | Bool | `false` | Start services after regions have obtained leases.
It will block the datanode start if it can't receive leases in the heartbeat from metasrv. |
| `init_regions_in_background` | Bool | `false` | Initialize all regions in the background during the startup.
By default, it provides services after all regions have been initialized. |
| `init_regions_parallelism` | Integer | `16` | Parallelism of initializing regions. |
diff --git a/config/datanode.example.toml b/config/datanode.example.toml
index 82ee07bd84..b232f5109f 100644
--- a/config/datanode.example.toml
+++ b/config/datanode.example.toml
@@ -2,6 +2,10 @@
## @toml2docs:none-default
node_id = 42
+## The default column prefix for auto-created time index and value columns.
+## @toml2docs:none-default
+default_column_prefix = "greptime"
+
## Start services after regions have obtained leases.
## It will block the datanode start if it can't receive leases in the heartbeat from metasrv.
require_lease_before_startup = false
diff --git a/config/frontend.example.toml b/config/frontend.example.toml
index 9ffcdad540..70c61c82c7 100644
--- a/config/frontend.example.toml
+++ b/config/frontend.example.toml
@@ -2,6 +2,10 @@
## @toml2docs:none-default
default_timezone = "UTC"
+## The default column prefix for auto-created time index and value columns.
+## @toml2docs:none-default
+default_column_prefix = "greptime"
+
## The maximum in-flight write bytes.
## @toml2docs:none-default
#+ max_in_flight_write_bytes = "500MB"
diff --git a/config/standalone.example.toml b/config/standalone.example.toml
index 744dbbe751..22f5574ef5 100644
--- a/config/standalone.example.toml
+++ b/config/standalone.example.toml
@@ -2,6 +2,10 @@
## @toml2docs:none-default
default_timezone = "UTC"
+## The default column prefix for auto-created time index and value columns.
+## @toml2docs:none-default
+default_column_prefix = "greptime"
+
## Initialize all regions in the background during the startup.
## By default, it provides services after all regions have been initialized.
init_regions_in_background = false
diff --git a/src/cmd/src/frontend.rs b/src/cmd/src/frontend.rs
index fda6d968bf..89992eba37 100644
--- a/src/cmd/src/frontend.rs
+++ b/src/cmd/src/frontend.rs
@@ -25,11 +25,13 @@ use clap::Parser;
use client::client_manager::NodeClients;
use common_base::Plugins;
use common_config::{Configurable, DEFAULT_DATA_HOME};
+use common_error::ext::BoxedError;
use common_grpc::channel_manager::ChannelConfig;
use common_meta::cache::{CacheRegistryBuilder, LayeredCacheRegistryBuilder};
use common_meta::heartbeat::handler::HandlerGroupExecutor;
use common_meta::heartbeat::handler::invalidate_table_cache::InvalidateCacheHandler;
use common_meta::heartbeat::handler::parse_mailbox_message::ParseMailboxMessageHandler;
+use common_query::prelude::set_default_prefix;
use common_stat::ResourceStatImpl;
use common_telemetry::info;
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
@@ -333,6 +335,9 @@ impl StartCommand {
.context(error::StartFrontendSnafu)?;
set_default_timezone(opts.default_timezone.as_deref()).context(error::InitTimezoneSnafu)?;
+ set_default_prefix(opts.default_column_prefix.as_deref())
+ .map_err(BoxedError::new)
+ .context(error::BuildCliSnafu)?;
let meta_client_options = opts
.meta_client
diff --git a/src/cmd/src/standalone.rs b/src/cmd/src/standalone.rs
index 58602d0a39..bf5aff7825 100644
--- a/src/cmd/src/standalone.rs
+++ b/src/cmd/src/standalone.rs
@@ -41,6 +41,7 @@ use common_meta::region_registry::LeaderRegionRegistry;
use common_meta::sequence::SequenceBuilder;
use common_meta::wal_options_allocator::{WalOptionsAllocatorRef, build_wal_options_allocator};
use common_procedure::ProcedureManagerRef;
+use common_query::prelude::set_default_prefix;
use common_telemetry::info;
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
use common_time::timezone::set_default_timezone;
@@ -355,6 +356,10 @@ impl StartCommand {
let mut plugins = Plugins::new();
let plugin_opts = opts.plugins;
let mut opts = opts.component;
+ set_default_prefix(opts.default_column_prefix.as_deref())
+ .map_err(BoxedError::new)
+ .context(error::BuildCliSnafu)?;
+
opts.grpc.detect_server_addr();
let fe_opts = opts.frontend_options();
let dn_opts = opts.datanode_options();
diff --git a/src/cmd/tests/load_config_test.rs b/src/cmd/tests/load_config_test.rs
index b92cf9631d..f4ee324b69 100644
--- a/src/cmd/tests/load_config_test.rs
+++ b/src/cmd/tests/load_config_test.rs
@@ -48,6 +48,7 @@ fn test_load_datanode_example_config() {
let expected = GreptimeOptions:: {
component: DatanodeOptions {
node_id: Some(42),
+ default_column_prefix: Some("greptime".to_string()),
meta_client: Some(MetaClientOptions {
metasrv_addrs: vec!["127.0.0.1:3002".to_string()],
timeout: Duration::from_secs(3),
@@ -113,6 +114,7 @@ fn test_load_frontend_example_config() {
let expected = GreptimeOptions:: {
component: FrontendOptions {
default_timezone: Some("UTC".to_string()),
+ default_column_prefix: Some("greptime".to_string()),
meta_client: Some(MetaClientOptions {
metasrv_addrs: vec!["127.0.0.1:3002".to_string()],
timeout: Duration::from_secs(3),
@@ -273,6 +275,7 @@ fn test_load_standalone_example_config() {
let expected = GreptimeOptions:: {
component: StandaloneOptions {
default_timezone: Some("UTC".to_string()),
+ default_column_prefix: Some("greptime".to_string()),
wal: DatanodeWalConfig::RaftEngine(RaftEngineConfig {
dir: Some(format!("{}/{}", DEFAULT_DATA_HOME, WAL_DIR)),
sync_period: Some(Duration::from_secs(10)),
diff --git a/src/common/base/Cargo.toml b/src/common/base/Cargo.toml
index ae2945b1f5..4a881990b4 100644
--- a/src/common/base/Cargo.toml
+++ b/src/common/base/Cargo.toml
@@ -18,9 +18,11 @@ bytes.workspace = true
common-error.workspace = true
common-macro.workspace = true
futures.workspace = true
+lazy_static.workspace = true
paste.workspace = true
pin-project.workspace = true
rand.workspace = true
+regex.workspace = true
serde = { version = "1.0", features = ["derive"] }
snafu.workspace = true
tokio.workspace = true
diff --git a/src/common/base/src/lib.rs b/src/common/base/src/lib.rs
index cc5acdbf47..1f530c2753 100644
--- a/src/common/base/src/lib.rs
+++ b/src/common/base/src/lib.rs
@@ -19,6 +19,7 @@ pub mod plugins;
pub mod range_read;
#[allow(clippy::all)]
pub mod readable_size;
+pub mod regex_pattern;
pub mod secrets;
pub mod serde;
diff --git a/src/common/base/src/regex_pattern.rs b/src/common/base/src/regex_pattern.rs
new file mode 100644
index 0000000000..7ff46693ba
--- /dev/null
+++ b/src/common/base/src/regex_pattern.rs
@@ -0,0 +1,22 @@
+// Copyright 2023 Greptime Team
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+use lazy_static::lazy_static;
+use regex::Regex;
+
+pub const NAME_PATTERN: &str = r"[a-zA-Z_:-][a-zA-Z0-9_:\-\.@#]*";
+
+lazy_static! {
+ pub static ref NAME_PATTERN_REG: Regex = Regex::new(&format!("^{NAME_PATTERN}$")).unwrap();
+}
diff --git a/src/common/meta/src/key.rs b/src/common/meta/src/key.rs
index a1d98db301..55dbc0ad01 100644
--- a/src/common/meta/src/key.rs
+++ b/src/common/meta/src/key.rs
@@ -121,6 +121,7 @@ use std::ops::{Deref, DerefMut};
use std::sync::Arc;
use bytes::Bytes;
+use common_base::regex_pattern::NAME_PATTERN;
use common_catalog::consts::{
DEFAULT_CATALOG_NAME, DEFAULT_PRIVATE_SCHEMA_NAME, DEFAULT_SCHEMA_NAME, INFORMATION_SCHEMA_NAME,
};
@@ -164,7 +165,6 @@ use crate::rpc::router::{LeaderState, RegionRoute, region_distribution};
use crate::rpc::store::BatchDeleteRequest;
use crate::state_store::PoisonValue;
-pub const NAME_PATTERN: &str = r"[a-zA-Z_:-][a-zA-Z0-9_:\-\.@#]*";
pub const TOPIC_NAME_PATTERN: &str = r"[a-zA-Z0-9_:-][a-zA-Z0-9_:\-\.@#]*";
pub const LEGACY_MAINTENANCE_KEY: &str = "__maintenance";
pub const MAINTENANCE_KEY: &str = "__switches/maintenance";
@@ -269,10 +269,6 @@ pub type FlowId = u32;
/// The partition of flow.
pub type FlowPartitionId = u32;
-lazy_static! {
- pub static ref NAME_PATTERN_REGEX: Regex = Regex::new(NAME_PATTERN).unwrap();
-}
-
lazy_static! {
pub static ref TOPIC_NAME_PATTERN_REGEX: Regex = Regex::new(TOPIC_NAME_PATTERN).unwrap();
}
diff --git a/src/common/query/Cargo.toml b/src/common/query/Cargo.toml
index 7cdc5a8a45..48328ea612 100644
--- a/src/common/query/Cargo.toml
+++ b/src/common/query/Cargo.toml
@@ -14,6 +14,7 @@ workspace = true
api.workspace = true
async-trait.workspace = true
bytes.workspace = true
+common-base.workspace = true
common-error.workspace = true
common-macro.workspace = true
common-recordbatch.workspace = true
@@ -22,6 +23,7 @@ datafusion.workspace = true
datafusion-common.workspace = true
datafusion-expr.workspace = true
datatypes.workspace = true
+once_cell.workspace = true
serde.workspace = true
snafu.workspace = true
sqlparser.workspace = true
diff --git a/src/common/query/src/error.rs b/src/common/query/src/error.rs
index 163efb30a7..618795bb4a 100644
--- a/src/common/query/src/error.rs
+++ b/src/common/query/src/error.rs
@@ -199,6 +199,9 @@ pub enum Error {
#[snafu(implicit)]
location: Location,
},
+
+ #[snafu(display("Invalid character in prefix config: {}", prefix))]
+ InvalidColumnPrefix { prefix: String },
}
pub type Result = std::result::Result;
@@ -227,7 +230,8 @@ impl ErrorExt for Error {
Error::UnsupportedInputDataType { .. }
| Error::TypeCast { .. }
- | Error::InvalidFuncArgs { .. } => StatusCode::InvalidArguments,
+ | Error::InvalidFuncArgs { .. }
+ | Error::InvalidColumnPrefix { .. } => StatusCode::InvalidArguments,
Error::ConvertDfRecordBatchStream { source, .. } => source.status_code(),
diff --git a/src/common/query/src/prelude.rs b/src/common/query/src/prelude.rs
index f467906402..c27b94294e 100644
--- a/src/common/query/src/prelude.rs
+++ b/src/common/query/src/prelude.rs
@@ -12,15 +12,61 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+use common_base::regex_pattern::NAME_PATTERN_REG;
pub use datafusion_common::ScalarValue;
+use once_cell::sync::OnceCell;
+use snafu::ensure;
pub use crate::columnar_value::ColumnarValue;
+use crate::error::{InvalidColumnPrefixSnafu, Result};
-/// Default timestamp column name for Prometheus metrics.
-pub const GREPTIME_TIMESTAMP: &str = "greptime_timestamp";
-/// Default value column name for Prometheus metrics.
-pub const GREPTIME_VALUE: &str = "greptime_value";
-/// Default counter column name for OTLP metrics.
+/// Default time index column name.
+static GREPTIME_TIMESTAMP_CELL: OnceCell = OnceCell::new();
+
+/// Default value column name.
+static GREPTIME_VALUE_CELL: OnceCell = OnceCell::new();
+
+pub fn set_default_prefix(prefix: Option<&str>) -> Result<()> {
+ match prefix {
+ None => {
+ // use default greptime prefix
+ GREPTIME_TIMESTAMP_CELL.get_or_init(|| GREPTIME_TIMESTAMP.to_string());
+ GREPTIME_VALUE_CELL.get_or_init(|| GREPTIME_VALUE.to_string());
+ }
+ Some(s) if s.trim().is_empty() => {
+ // use "" to disable prefix
+ GREPTIME_TIMESTAMP_CELL.get_or_init(|| "timestamp".to_string());
+ GREPTIME_VALUE_CELL.get_or_init(|| "value".to_string());
+ }
+ Some(x) => {
+ ensure!(
+ NAME_PATTERN_REG.is_match(x),
+ InvalidColumnPrefixSnafu { prefix: x }
+ );
+ GREPTIME_TIMESTAMP_CELL.get_or_init(|| format!("{}_timestamp", x));
+ GREPTIME_VALUE_CELL.get_or_init(|| format!("{}_value", x));
+ }
+ }
+ Ok(())
+}
+
+/// Get the default timestamp column name.
+/// Returns the configured value, or `greptime_timestamp` if not set.
+pub fn greptime_timestamp() -> &'static str {
+ GREPTIME_TIMESTAMP_CELL.get_or_init(|| GREPTIME_TIMESTAMP.to_string())
+}
+
+/// Get the default value column name.
+/// Returns the configured value, or `greptime_value` if not set.
+pub fn greptime_value() -> &'static str {
+ GREPTIME_VALUE_CELL.get_or_init(|| GREPTIME_VALUE.to_string())
+}
+
+/// Default timestamp column name constant for backward compatibility.
+const GREPTIME_TIMESTAMP: &str = "greptime_timestamp";
+/// Default value column name constant for backward compatibility.
+const GREPTIME_VALUE: &str = "greptime_value";
+/// Default counter column name for OTLP metrics (legacy mode).
pub const GREPTIME_COUNT: &str = "greptime_count";
/// Default physical table name
pub const GREPTIME_PHYSICAL_TABLE: &str = "greptime_physical_table";
diff --git a/src/datanode/src/config.rs b/src/datanode/src/config.rs
index 2f2fcd2697..e40a52bd6b 100644
--- a/src/datanode/src/config.rs
+++ b/src/datanode/src/config.rs
@@ -66,6 +66,7 @@ impl Default for StorageConfig {
#[serde(default)]
pub struct DatanodeOptions {
pub node_id: Option,
+ pub default_column_prefix: Option,
pub workload_types: Vec,
pub require_lease_before_startup: bool,
pub init_regions_in_background: bool,
@@ -119,6 +120,7 @@ impl Default for DatanodeOptions {
fn default() -> Self {
Self {
node_id: None,
+ default_column_prefix: None,
workload_types: vec![DatanodeWorkloadType::Hybrid],
require_lease_before_startup: false,
init_regions_in_background: false,
diff --git a/src/datanode/src/datanode.rs b/src/datanode/src/datanode.rs
index b9b8edcdba..50d0ef4076 100644
--- a/src/datanode/src/datanode.rs
+++ b/src/datanode/src/datanode.rs
@@ -27,6 +27,7 @@ use common_meta::key::runtime_switch::RuntimeSwitchManager;
use common_meta::key::{SchemaMetadataManager, SchemaMetadataManagerRef};
use common_meta::kv_backend::KvBackendRef;
pub use common_procedure::options::ProcedureConfig;
+use common_query::prelude::set_default_prefix;
use common_stat::ResourceStatImpl;
use common_telemetry::{error, info, warn};
use common_wal::config::DatanodeWalConfig;
@@ -59,9 +60,9 @@ use tokio::sync::Notify;
use crate::config::{DatanodeOptions, RegionEngineConfig, StorageConfig};
use crate::error::{
- self, BuildMetricEngineSnafu, BuildMitoEngineSnafu, CreateDirSnafu, GetMetadataSnafu,
- MissingCacheSnafu, MissingNodeIdSnafu, OpenLogStoreSnafu, Result, ShutdownInstanceSnafu,
- ShutdownServerSnafu, StartServerSnafu,
+ self, BuildDatanodeSnafu, BuildMetricEngineSnafu, BuildMitoEngineSnafu, CreateDirSnafu,
+ GetMetadataSnafu, MissingCacheSnafu, MissingNodeIdSnafu, OpenLogStoreSnafu, Result,
+ ShutdownInstanceSnafu, ShutdownServerSnafu, StartServerSnafu,
};
use crate::event_listener::{
NoopRegionServerEventListener, RegionServerEventListenerRef, RegionServerEventReceiver,
@@ -220,6 +221,9 @@ impl DatanodeBuilder {
pub async fn build(mut self) -> Result {
let node_id = self.opts.node_id.context(MissingNodeIdSnafu)?;
+ set_default_prefix(self.opts.default_column_prefix.as_deref())
+ .map_err(BoxedError::new)
+ .context(BuildDatanodeSnafu)?;
let meta_client = self.meta_client.take();
diff --git a/src/datanode/src/error.rs b/src/datanode/src/error.rs
index a2e6f674e2..eda483a1e2 100644
--- a/src/datanode/src/error.rs
+++ b/src/datanode/src/error.rs
@@ -165,6 +165,13 @@ pub enum Error {
location: Location,
},
+ #[snafu(display("Failed to build datanode"))]
+ BuildDatanode {
+ #[snafu(implicit)]
+ location: Location,
+ source: BoxedError,
+ },
+
#[snafu(display("Failed to build http client"))]
BuildHttpClient {
#[snafu(implicit)]
@@ -429,7 +436,8 @@ impl ErrorExt for Error {
| MissingRequiredField { .. }
| RegionEngineNotFound { .. }
| ParseAddr { .. }
- | TomlFormat { .. } => StatusCode::InvalidArguments,
+ | TomlFormat { .. }
+ | BuildDatanode { .. } => StatusCode::InvalidArguments,
PayloadNotExist { .. }
| Unexpected { .. }
diff --git a/src/frontend/src/frontend.rs b/src/frontend/src/frontend.rs
index bf2e7a0558..dce9ffd158 100644
--- a/src/frontend/src/frontend.rs
+++ b/src/frontend/src/frontend.rs
@@ -45,6 +45,7 @@ use crate::service_config::{
pub struct FrontendOptions {
pub node_id: Option,
pub default_timezone: Option,
+ pub default_column_prefix: Option,
pub heartbeat: HeartbeatOptions,
pub http: HttpOptions,
pub grpc: GrpcOptions,
@@ -77,6 +78,7 @@ impl Default for FrontendOptions {
Self {
node_id: None,
default_timezone: None,
+ default_column_prefix: None,
heartbeat: HeartbeatOptions::frontend_default(),
http: HttpOptions::default(),
grpc: GrpcOptions::default(),
diff --git a/src/meta-srv/src/handler/persist_stats_handler.rs b/src/meta-srv/src/handler/persist_stats_handler.rs
index 1dc81f49eb..abc2fa3c3e 100644
--- a/src/meta-srv/src/handler/persist_stats_handler.rs
+++ b/src/meta-srv/src/handler/persist_stats_handler.rs
@@ -77,6 +77,7 @@ struct PersistRegionStat<'a> {
sst_size: u64,
write_bytes_delta: u64,
#[col(
+ // This col name is for the information schema table, so we don't touch it
name = "greptime_timestamp",
semantic = "Timestamp",
datatype = "TimestampMillisecond"
diff --git a/src/metric-engine/src/data_region.rs b/src/metric-engine/src/data_region.rs
index 5056cd0352..beab78cd70 100644
--- a/src/metric-engine/src/data_region.rs
+++ b/src/metric-engine/src/data_region.rs
@@ -240,6 +240,7 @@ impl DataRegion {
#[cfg(test)]
mod test {
+ use common_query::prelude::{greptime_timestamp, greptime_value};
use datatypes::prelude::ConcreteDataType;
use datatypes::schema::ColumnSchema;
@@ -300,8 +301,8 @@ mod test {
.map(|c| &c.column_schema.name)
.collect::>();
let expected = vec![
- "greptime_timestamp",
- "greptime_value",
+ greptime_timestamp(),
+ greptime_value(),
"__table_id",
"__tsid",
"job",
diff --git a/src/metric-engine/src/engine/alter.rs b/src/metric-engine/src/engine/alter.rs
index 1c4cb93639..1ae63915e9 100644
--- a/src/metric-engine/src/engine/alter.rs
+++ b/src/metric-engine/src/engine/alter.rs
@@ -224,6 +224,7 @@ mod test {
use api::v1::SemanticType;
use common_meta::ddl::test_util::assert_column_name_and_id;
use common_meta::ddl::utils::{parse_column_metadatas, parse_manifest_infos_from_extensions};
+ use common_query::prelude::{greptime_timestamp, greptime_value};
use store_api::metric_engine_consts::ALTER_PHYSICAL_EXTENSION_KEY;
use store_api::region_engine::RegionEngine;
use store_api::region_request::{
@@ -295,7 +296,7 @@ mod test {
.unwrap();
assert_eq!(semantic_type, SemanticType::Tag);
let timestamp_index = metadata_region
- .column_semantic_type(physical_region_id, logical_region_id, "greptime_timestamp")
+ .column_semantic_type(physical_region_id, logical_region_id, greptime_timestamp())
.await
.unwrap()
.unwrap();
@@ -305,8 +306,8 @@ mod test {
assert_column_name_and_id(
&column_metadatas,
&[
- ("greptime_timestamp", 0),
- ("greptime_value", 1),
+ (greptime_timestamp(), 0),
+ (greptime_value(), 1),
("__table_id", ReservedColumnId::table_id()),
("__tsid", ReservedColumnId::tsid()),
("job", 2),
@@ -364,8 +365,8 @@ mod test {
assert_column_name_and_id(
&column_metadatas,
&[
- ("greptime_timestamp", 0),
- ("greptime_value", 1),
+ (greptime_timestamp(), 0),
+ (greptime_value(), 1),
("__table_id", ReservedColumnId::table_id()),
("__tsid", ReservedColumnId::tsid()),
("job", 2),
diff --git a/src/metric-engine/src/engine/create.rs b/src/metric-engine/src/engine/create.rs
index c506c0e2b4..2796d3652b 100644
--- a/src/metric-engine/src/engine/create.rs
+++ b/src/metric-engine/src/engine/create.rs
@@ -619,6 +619,7 @@ pub(crate) fn region_options_for_metadata_region(
mod test {
use common_meta::ddl::test_util::assert_column_name_and_id;
use common_meta::ddl::utils::{parse_column_metadatas, parse_manifest_infos_from_extensions};
+ use common_query::prelude::{greptime_timestamp, greptime_value};
use store_api::metric_engine_consts::{METRIC_ENGINE_NAME, PHYSICAL_TABLE_METADATA_KEY};
use store_api::region_request::BatchRegionDdlRequest;
@@ -856,8 +857,8 @@ mod test {
assert_column_name_and_id(
&column_metadatas,
&[
- ("greptime_timestamp", 0),
- ("greptime_value", 1),
+ (greptime_timestamp(), 0),
+ (greptime_value(), 1),
("__table_id", ReservedColumnId::table_id()),
("__tsid", ReservedColumnId::tsid()),
("job", 2),
diff --git a/src/metric-engine/src/engine/sync.rs b/src/metric-engine/src/engine/sync.rs
index b62b138dab..741938f8d7 100644
--- a/src/metric-engine/src/engine/sync.rs
+++ b/src/metric-engine/src/engine/sync.rs
@@ -110,6 +110,7 @@ mod tests {
use std::collections::HashMap;
use api::v1::SemanticType;
+ use common_query::prelude::greptime_timestamp;
use common_telemetry::info;
use datatypes::data_type::ConcreteDataType;
use datatypes::schema::ColumnSchema;
@@ -243,7 +244,7 @@ mod tests {
.unwrap();
assert_eq!(semantic_type, SemanticType::Tag);
let timestamp_index = metadata_region
- .column_semantic_type(physical_region_id, logical_region_id, "greptime_timestamp")
+ .column_semantic_type(physical_region_id, logical_region_id, greptime_timestamp())
.await
.unwrap()
.unwrap();
diff --git a/src/metric-engine/src/test_util.rs b/src/metric-engine/src/test_util.rs
index d594541d84..cc173e534c 100644
--- a/src/metric-engine/src/test_util.rs
+++ b/src/metric-engine/src/test_util.rs
@@ -17,6 +17,7 @@
use api::v1::value::ValueData;
use api::v1::{ColumnDataType, ColumnSchema as PbColumnSchema, Row, SemanticType, Value};
use common_meta::ddl::utils::parse_column_metadatas;
+use common_query::prelude::{greptime_timestamp, greptime_value};
use common_telemetry::debug;
use datatypes::prelude::ConcreteDataType;
use datatypes::schema::ColumnSchema;
@@ -132,7 +133,7 @@ impl TestEnv {
column_id: 0,
semantic_type: SemanticType::Timestamp,
column_schema: ColumnSchema::new(
- "greptime_timestamp",
+ greptime_timestamp(),
ConcreteDataType::timestamp_millisecond_datatype(),
false,
),
@@ -141,7 +142,7 @@ impl TestEnv {
column_id: 1,
semantic_type: SemanticType::Field,
column_schema: ColumnSchema::new(
- "greptime_value",
+ greptime_value(),
ConcreteDataType::float64_datatype(),
false,
),
@@ -204,8 +205,8 @@ impl TestEnv {
assert_eq!(
column_names,
vec![
- "greptime_timestamp",
- "greptime_value",
+ greptime_timestamp(),
+ greptime_value(),
"__table_id",
"__tsid",
"job",
@@ -300,7 +301,7 @@ pub fn create_logical_region_request(
column_id: 0,
semantic_type: SemanticType::Timestamp,
column_schema: ColumnSchema::new(
- "greptime_timestamp",
+ greptime_timestamp(),
ConcreteDataType::timestamp_millisecond_datatype(),
false,
),
@@ -309,7 +310,7 @@ pub fn create_logical_region_request(
column_id: 1,
semantic_type: SemanticType::Field,
column_schema: ColumnSchema::new(
- "greptime_value",
+ greptime_value(),
ConcreteDataType::float64_datatype(),
false,
),
@@ -372,14 +373,14 @@ pub fn alter_logical_region_request(tags: &[&str]) -> RegionAlterRequest {
pub fn row_schema_with_tags(tags: &[&str]) -> Vec {
let mut schema = vec![
PbColumnSchema {
- column_name: "greptime_timestamp".to_string(),
+ column_name: greptime_timestamp().to_string(),
datatype: ColumnDataType::TimestampMillisecond as i32,
semantic_type: SemanticType::Timestamp as _,
datatype_extension: None,
options: None,
},
PbColumnSchema {
- column_name: "greptime_value".to_string(),
+ column_name: greptime_value().to_string(),
datatype: ColumnDataType::Float64 as i32,
semantic_type: SemanticType::Field as _,
datatype_extension: None,
diff --git a/src/mito-codec/Cargo.toml b/src/mito-codec/Cargo.toml
index 99a46e8ac9..81808f2714 100644
--- a/src/mito-codec/Cargo.toml
+++ b/src/mito-codec/Cargo.toml
@@ -15,6 +15,7 @@ common-base.workspace = true
common-decimal.workspace = true
common-error.workspace = true
common-macro.workspace = true
+common-query.workspace = true
common-recordbatch.workspace = true
common-telemetry.workspace = true
common-time.workspace = true
diff --git a/src/mito-codec/src/primary_key_filter.rs b/src/mito-codec/src/primary_key_filter.rs
index e4d1ce5056..c71fafc974 100644
--- a/src/mito-codec/src/primary_key_filter.rs
+++ b/src/mito-codec/src/primary_key_filter.rs
@@ -154,6 +154,7 @@ mod tests {
use std::sync::Arc;
use api::v1::SemanticType;
+ use common_query::prelude::{greptime_timestamp, greptime_value};
use datafusion_common::Column;
use datafusion_expr::{BinaryExpr, Expr, Literal, Operator};
use datatypes::prelude::ConcreteDataType;
@@ -193,7 +194,7 @@ mod tests {
})
.push_column_metadata(ColumnMetadata {
column_schema: ColumnSchema::new(
- "greptime_value",
+ greptime_value(),
ConcreteDataType::float64_datatype(),
false,
),
@@ -202,7 +203,7 @@ mod tests {
})
.push_column_metadata(ColumnMetadata {
column_schema: ColumnSchema::new(
- "greptime_timestamp",
+ greptime_timestamp(),
ConcreteDataType::timestamp_nanosecond_datatype(),
false,
),
diff --git a/src/mito-codec/src/row_converter/sparse.rs b/src/mito-codec/src/row_converter/sparse.rs
index edc26db8f0..191c2bd011 100644
--- a/src/mito-codec/src/row_converter/sparse.rs
+++ b/src/mito-codec/src/row_converter/sparse.rs
@@ -385,6 +385,7 @@ mod tests {
use std::sync::Arc;
use api::v1::SemanticType;
+ use common_query::prelude::{greptime_timestamp, greptime_value};
use common_time::Timestamp;
use common_time::timestamp::TimeUnit;
use datatypes::schema::ColumnSchema;
@@ -461,7 +462,7 @@ mod tests {
})
.push_column_metadata(ColumnMetadata {
column_schema: ColumnSchema::new(
- "greptime_value",
+ greptime_value(),
ConcreteDataType::float64_datatype(),
false,
),
@@ -470,7 +471,7 @@ mod tests {
})
.push_column_metadata(ColumnMetadata {
column_schema: ColumnSchema::new(
- "greptime_timestamp",
+ greptime_timestamp(),
ConcreteDataType::timestamp_nanosecond_datatype(),
false,
),
diff --git a/src/mito2/src/memtable/partition_tree.rs b/src/mito2/src/memtable/partition_tree.rs
index e404a5851e..31cadac4f1 100644
--- a/src/mito2/src/memtable/partition_tree.rs
+++ b/src/mito2/src/memtable/partition_tree.rs
@@ -384,6 +384,7 @@ mod tests {
use api::v1::helper::{field_column_schema, row, tag_column_schema, time_index_column_schema};
use api::v1::value::ValueData;
use api::v1::{Mutation, OpType, Rows, SemanticType};
+ use common_query::prelude::{greptime_timestamp, greptime_value};
use common_time::Timestamp;
use datafusion_common::Column;
use datafusion_expr::{BinaryExpr, Expr, Literal, Operator};
@@ -694,7 +695,7 @@ mod tests {
})
.push_column_metadata(ColumnMetadata {
column_schema: ColumnSchema::new(
- "greptime_timestamp",
+ greptime_timestamp(),
ConcreteDataType::timestamp_millisecond_datatype(),
false,
),
@@ -703,7 +704,7 @@ mod tests {
})
.push_column_metadata(ColumnMetadata {
column_schema: ColumnSchema::new(
- "greptime_value",
+ greptime_value(),
ConcreteDataType::float64_datatype(),
true,
),
diff --git a/src/operator/src/insert.rs b/src/operator/src/insert.rs
index 59ab06c95e..9de4fb3fba 100644
--- a/src/operator/src/insert.rs
+++ b/src/operator/src/insert.rs
@@ -37,7 +37,7 @@ use common_meta::cache::TableFlownodeSetCacheRef;
use common_meta::node_manager::{AffectedRows, NodeManagerRef};
use common_meta::peer::Peer;
use common_query::Output;
-use common_query::prelude::{GREPTIME_TIMESTAMP, GREPTIME_VALUE};
+use common_query::prelude::{greptime_timestamp, greptime_value};
use common_telemetry::tracing_context::TracingContext;
use common_telemetry::{error, info, warn};
use datatypes::schema::SkippingIndexOptions;
@@ -721,14 +721,14 @@ impl Inserter {
// schema with timestamp and field column
let default_schema = vec![
ColumnSchema {
- column_name: GREPTIME_TIMESTAMP.to_string(),
+ column_name: greptime_timestamp().to_string(),
datatype: ColumnDataType::TimestampMillisecond as _,
semantic_type: SemanticType::Timestamp as _,
datatype_extension: None,
options: None,
},
ColumnSchema {
- column_name: GREPTIME_VALUE.to_string(),
+ column_name: greptime_value().to_string(),
datatype: ColumnDataType::Float64 as _,
semantic_type: SemanticType::Field as _,
datatype_extension: None,
diff --git a/src/operator/src/statement/ddl.rs b/src/operator/src/statement/ddl.rs
index 3b626d13d0..295e33e43e 100644
--- a/src/operator/src/statement/ddl.rs
+++ b/src/operator/src/statement/ddl.rs
@@ -26,13 +26,13 @@ use api::v1::{
};
use catalog::CatalogManagerRef;
use chrono::Utc;
+use common_base::regex_pattern::NAME_PATTERN_REG;
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME, is_readonly_schema};
use common_catalog::{format_full_flow_name, format_full_table_name};
use common_error::ext::BoxedError;
use common_meta::cache_invalidator::Context;
use common_meta::ddl::create_flow::FlowType;
use common_meta::instruction::CacheIdent;
-use common_meta::key::NAME_PATTERN;
use common_meta::key::schema_name::{SchemaName, SchemaNameKey};
use common_meta::procedure_executor::ExecutorContext;
#[cfg(feature = "enterprise")]
@@ -52,14 +52,12 @@ use datafusion_expr::LogicalPlan;
use datatypes::prelude::ConcreteDataType;
use datatypes::schema::{RawSchema, Schema};
use datatypes::value::Value;
-use lazy_static::lazy_static;
use partition::expr::{Operand, PartitionExpr, RestrictedOp};
use partition::multi_dim::MultiDimPartitionRule;
use query::parser::QueryStatement;
use query::plan::extract_and_rewrite_full_table_names;
use query::query_engine::DefaultSerializer;
use query::sql::create_table_stmt;
-use regex::Regex;
use session::context::QueryContextRef;
use session::table_name::table_idents_to_full_name;
use snafu::{OptionExt, ResultExt, ensure};
@@ -96,10 +94,6 @@ use crate::expr_helper;
use crate::statement::StatementExecutor;
use crate::statement::show::create_partitions_stmt;
-lazy_static! {
- pub static ref NAME_PATTERN_REG: Regex = Regex::new(&format!("^{NAME_PATTERN}$")).unwrap();
-}
-
impl StatementExecutor {
pub fn catalog_manager(&self) -> CatalogManagerRef {
self.catalog_manager.clone()
diff --git a/src/pipeline/src/etl/transform/transformer/greptime.rs b/src/pipeline/src/etl/transform/transformer/greptime.rs
index de98213972..6774842ef1 100644
--- a/src/pipeline/src/etl/transform/transformer/greptime.rs
+++ b/src/pipeline/src/etl/transform/transformer/greptime.rs
@@ -24,7 +24,7 @@ use api::v1::column_data_type_extension::TypeExt;
use api::v1::value::ValueData;
use api::v1::{ColumnDataType, ColumnDataTypeExtension, JsonTypeExtension, SemanticType};
use coerce::{coerce_columns, coerce_value};
-use common_query::prelude::{GREPTIME_TIMESTAMP, GREPTIME_VALUE};
+use common_query::prelude::{greptime_timestamp, greptime_value};
use common_telemetry::warn;
use greptime_proto::v1::{ColumnSchema, Row, Rows, Value as GreptimeValue};
use itertools::Itertools;
@@ -48,7 +48,6 @@ use crate::etl::transform::index::Index;
use crate::etl::transform::{Transform, Transforms};
use crate::{PipelineContext, truthy, unwrap_or_continue_if_err};
-const DEFAULT_GREPTIME_TIMESTAMP_COLUMN: &str = "greptime_timestamp";
const DEFAULT_MAX_NESTED_LEVELS_FOR_JSON_FLATTENING: usize = 10;
/// fields not in the columns will be discarded
@@ -138,10 +137,7 @@ impl GreptimeTransformer {
let default = None;
let transform = Transform {
- fields: Fields::one(Field::new(
- DEFAULT_GREPTIME_TIMESTAMP_COLUMN.to_string(),
- None,
- )),
+ fields: Fields::one(Field::new(greptime_timestamp().to_string(), None)),
type_,
default,
index: Some(Index::Time),
@@ -347,7 +343,7 @@ fn calc_ts(p_ctx: &PipelineContext, values: &VrlValue) -> Result