mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-28 19:00:39 +00:00
feat: prefix option for timestamp index and value column (#7125)
* refactor: use GREPTIME_TIMESTAMP const Signed-off-by: shuiyisong <xixing.sys@gmail.com> * feat: add config for default ts col name Signed-off-by: shuiyisong <xixing.sys@gmail.com> * refactor: replace GREPTIME_TIMESTAMP with function get Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update config doc * fix: test Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: remove opts on flownode and metasrv Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: add validation for ts column name Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: use get_or_init to avoid test error Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: fmt Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update docs Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: using empty string to disable prefix Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update comment Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: address CR issues Signed-off-by: shuiyisong <xixing.sys@gmail.com> --------- Signed-off-by: shuiyisong <xixing.sys@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<T> = std::result::Result<T, Error>;
|
||||
@@ -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(),
|
||||
|
||||
|
||||
@@ -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<String> = OnceCell::new();
|
||||
|
||||
/// Default value column name.
|
||||
static GREPTIME_VALUE_CELL: OnceCell<String> = 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";
|
||||
|
||||
Reference in New Issue
Block a user