From 2b4ed4369231955e6cdc6a13faef9057e3a903aa Mon Sep 17 00:00:00 2001 From: shuiyisong <113876041+shuiyisong@users.noreply.github.com> Date: Thu, 27 Mar 2025 16:17:27 +0800 Subject: [PATCH] chore: accept table options in auto create table from hints (#5776) chore: accept table options in auto create table from hint --- src/operator/src/insert.rs | 8 ++++--- src/servers/src/hint_headers.rs | 3 ++- src/table/src/requests.rs | 37 +++++++++++++++++---------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/operator/src/insert.rs b/src/operator/src/insert.rs index f9a2885a6b..579be92e44 100644 --- a/src/operator/src/insert.rs +++ b/src/operator/src/insert.rs @@ -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 { 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(); diff --git a/src/servers/src/hint_headers.rs b/src/servers/src/hint_headers.rs index 58afb3fd6c..1ead2edb9a 100644 --- a/src/servers/src/hint_headers.rs +++ b/src/servers/src/hint_headers.rs @@ -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(headers: &T) -> Vec<(String, String)> { diff --git a/src/table/src/requests.rs b/src/table/src/requests.rs index 1f33109ac8..5b7ad566c5 100644 --- a/src/table/src/requests.rs +++ b/src/table/src/requests.rs @@ -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)]