mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-30 20:00:36 +00:00
chore: accept table options in auto create table from hints (#5776)
chore: accept table options in auto create table from hint
This commit is contained in:
@@ -56,7 +56,7 @@ use store_api::storage::{RegionId, TableId};
|
||||
use table::metadata::TableInfo;
|
||||
use table::requests::{
|
||||
InsertRequest as TableInsertRequest, AUTO_CREATE_TABLE_KEY, TABLE_DATA_MODEL,
|
||||
TABLE_DATA_MODEL_TRACE_V1, TTL_KEY,
|
||||
TABLE_DATA_MODEL_TRACE_V1, VALID_TABLE_OPTION_KEYS,
|
||||
};
|
||||
use table::table_reference::TableReference;
|
||||
use table::TableRef;
|
||||
@@ -715,8 +715,10 @@ impl Inserter {
|
||||
ctx: &QueryContextRef,
|
||||
) -> Result<CreateTableExpr> {
|
||||
let mut table_options = Vec::with_capacity(4);
|
||||
if let Some(ttl) = ctx.extension(TTL_KEY) {
|
||||
table_options.push((TTL_KEY, ttl));
|
||||
for key in VALID_TABLE_OPTION_KEYS {
|
||||
if let Some(value) = ctx.extension(key) {
|
||||
table_options.push((key, value));
|
||||
}
|
||||
}
|
||||
|
||||
let mut engine_name = default_engine();
|
||||
|
||||
@@ -18,12 +18,13 @@ use tonic::metadata::MetadataMap;
|
||||
// For the given format: `x-greptime-hints: auto_create_table=true, ttl=7d`
|
||||
pub const HINTS_KEY: &str = "x-greptime-hints";
|
||||
|
||||
pub const HINT_KEYS: [&str; 5] = [
|
||||
pub const HINT_KEYS: [&str; 6] = [
|
||||
"x-greptime-hint-auto_create_table",
|
||||
"x-greptime-hint-ttl",
|
||||
"x-greptime-hint-append_mode",
|
||||
"x-greptime-hint-merge_mode",
|
||||
"x-greptime-hint-physical_table",
|
||||
"x-greptime-hint-skip_wal",
|
||||
];
|
||||
|
||||
pub(crate) fn extract_hints<T: ToHeaderMap>(headers: &T) -> Vec<(String, String)> {
|
||||
|
||||
@@ -46,6 +46,24 @@ pub const FILE_TABLE_FORMAT_KEY: &str = "format";
|
||||
pub const TABLE_DATA_MODEL: &str = "table_data_model";
|
||||
pub const TABLE_DATA_MODEL_TRACE_V1: &str = "greptime_trace_v1";
|
||||
|
||||
pub const VALID_TABLE_OPTION_KEYS: [&str; 11] = [
|
||||
// common keys:
|
||||
WRITE_BUFFER_SIZE_KEY,
|
||||
TTL_KEY,
|
||||
STORAGE_KEY,
|
||||
COMMENT_KEY,
|
||||
SKIP_WAL_KEY,
|
||||
// file engine keys:
|
||||
FILE_TABLE_LOCATION_KEY,
|
||||
FILE_TABLE_FORMAT_KEY,
|
||||
FILE_TABLE_PATTERN_KEY,
|
||||
// metric engine keys:
|
||||
PHYSICAL_TABLE_METADATA_KEY,
|
||||
LOGICAL_TABLE_METADATA_KEY,
|
||||
// table model info
|
||||
TABLE_DATA_MODEL,
|
||||
];
|
||||
|
||||
/// Returns true if the `key` is a valid key for any engine or storage.
|
||||
pub fn validate_table_option(key: &str) -> bool {
|
||||
if is_supported_in_s3(key) {
|
||||
@@ -60,24 +78,7 @@ pub fn validate_table_option(key: &str) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
[
|
||||
// common keys:
|
||||
WRITE_BUFFER_SIZE_KEY,
|
||||
TTL_KEY,
|
||||
STORAGE_KEY,
|
||||
COMMENT_KEY,
|
||||
SKIP_WAL_KEY,
|
||||
// file engine keys:
|
||||
FILE_TABLE_LOCATION_KEY,
|
||||
FILE_TABLE_FORMAT_KEY,
|
||||
FILE_TABLE_PATTERN_KEY,
|
||||
// metric engine keys:
|
||||
PHYSICAL_TABLE_METADATA_KEY,
|
||||
LOGICAL_TABLE_METADATA_KEY,
|
||||
// table model info
|
||||
TABLE_DATA_MODEL,
|
||||
]
|
||||
.contains(&key)
|
||||
VALID_TABLE_OPTION_KEYS.contains(&key)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
|
||||
Reference in New Issue
Block a user