1use common_base::regex_pattern::NAME_PATTERN_REG;
16pub use datafusion_common::ScalarValue;
17use once_cell::sync::OnceCell;
18use snafu::ensure;
19
20pub use crate::columnar_value::ColumnarValue;
21use crate::error::{InvalidColumnPrefixSnafu, Result};
22
23static GREPTIME_TIMESTAMP_CELL: OnceCell<String> = OnceCell::new();
25
26static GREPTIME_VALUE_CELL: OnceCell<String> = OnceCell::new();
28
29pub fn set_default_prefix(prefix: Option<&str>) -> Result<()> {
30 match prefix {
31 None => {
32 GREPTIME_TIMESTAMP_CELL.get_or_init(|| GREPTIME_TIMESTAMP.to_string());
34 GREPTIME_VALUE_CELL.get_or_init(|| GREPTIME_VALUE.to_string());
35 }
36 Some(s) if s.trim().is_empty() => {
37 GREPTIME_TIMESTAMP_CELL.get_or_init(|| "timestamp".to_string());
39 GREPTIME_VALUE_CELL.get_or_init(|| "value".to_string());
40 }
41 Some(x) => {
42 ensure!(
43 NAME_PATTERN_REG.is_match(x),
44 InvalidColumnPrefixSnafu { prefix: x }
45 );
46 GREPTIME_TIMESTAMP_CELL.get_or_init(|| format!("{}_timestamp", x));
47 GREPTIME_VALUE_CELL.get_or_init(|| format!("{}_value", x));
48 }
49 }
50 Ok(())
51}
52
53pub fn greptime_timestamp() -> &'static str {
56 GREPTIME_TIMESTAMP_CELL.get_or_init(|| GREPTIME_TIMESTAMP.to_string())
57}
58
59pub fn greptime_value() -> &'static str {
62 GREPTIME_VALUE_CELL.get_or_init(|| GREPTIME_VALUE.to_string())
63}
64
65const GREPTIME_TIMESTAMP: &str = "greptime_timestamp";
67const GREPTIME_VALUE: &str = "greptime_value";
69pub const GREPTIME_COUNT: &str = "greptime_count";
71pub const GREPTIME_PHYSICAL_TABLE: &str = "greptime_physical_table";