From 25d64255a30e0c0c3a3628269de4b0fa3af4f0f5 Mon Sep 17 00:00:00 2001 From: irenjj <122664327+irenjj@users.noreply.github.com> Date: Mon, 27 May 2024 10:28:52 +0800 Subject: [PATCH] feat: support table level comment (#4042) * feat: support table level comment * use constants Signed-off-by: tison --------- Signed-off-by: tison Co-authored-by: tison --- src/operator/src/statement/ddl.rs | 4 +-- src/table/src/requests.rs | 2 ++ .../standalone/common/create/create.result | 33 +++++++++++++++++++ .../cases/standalone/common/create/create.sql | 11 +++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/operator/src/statement/ddl.rs b/src/operator/src/statement/ddl.rs index 521e3563fa..28a674fa8f 100644 --- a/src/operator/src/statement/ddl.rs +++ b/src/operator/src/statement/ddl.rs @@ -59,7 +59,7 @@ use store_api::metric_engine_consts::{LOGICAL_TABLE_METADATA_KEY, METRIC_ENGINE_ use substrait::{DFLogicalSubstraitConvertor, SubstraitPlan}; use table::dist_table::DistTable; use table::metadata::{self, RawTableInfo, RawTableMeta, TableId, TableInfo, TableType}; -use table::requests::{AlterKind, AlterTableRequest, TableOptions}; +use table::requests::{AlterKind, AlterTableRequest, TableOptions, COMMENT_KEY}; use table::TableRef; use super::StatementExecutor; @@ -1142,7 +1142,7 @@ fn create_table_info( }; let desc = if create_table.desc.is_empty() { - None + create_table.table_options.get(COMMENT_KEY).cloned() } else { Some(create_table.desc.clone()) }; diff --git a/src/table/src/requests.rs b/src/table/src/requests.rs index e86eb4e8e4..519ee2adb6 100644 --- a/src/table/src/requests.rs +++ b/src/table/src/requests.rs @@ -54,6 +54,7 @@ pub fn validate_table_option(key: &str) -> bool { WRITE_BUFFER_SIZE_KEY, TTL_KEY, STORAGE_KEY, + COMMENT_KEY, // file engine keys: FILE_TABLE_LOCATION_KEY, FILE_TABLE_FORMAT_KEY, @@ -80,6 +81,7 @@ pub struct TableOptions { pub const WRITE_BUFFER_SIZE_KEY: &str = "write_buffer_size"; pub const TTL_KEY: &str = "ttl"; pub const STORAGE_KEY: &str = "storage"; +pub const COMMENT_KEY: &str = "comment"; impl TableOptions { pub fn try_from_iter>( diff --git a/tests/cases/standalone/common/create/create.result b/tests/cases/standalone/common/create/create.result index ed0529b934..237873dee1 100644 --- a/tests/cases/standalone/common/create/create.result +++ b/tests/cases/standalone/common/create/create.result @@ -204,3 +204,36 @@ DROP table `ExcePTuRi`; Affected Rows: 0 +CREATE TABLE if not exists monitor ( + host STRING, + ts TIMESTAMP(9) DEFAULT CURRENT_TIMESTAMP() TIME INDEX, + cpu FLOAT64 DEFAULT 0, + memory FLOAT64, + PRIMARY KEY(host)) ENGINE=mito WITH(COMMENT='create by human'); + +Affected Rows: 0 + +SHOW CREATE TABLE monitor; + ++---------+-----------------------------------------------------------+ +| Table | Create Table | ++---------+-----------------------------------------------------------+ +| monitor | CREATE TABLE IF NOT EXISTS "monitor" ( | +| | "host" STRING NULL, | +| | "ts" TIMESTAMP(9) NOT NULL DEFAULT current_timestamp(), | +| | "cpu" DOUBLE NULL DEFAULT 0, | +| | "memory" DOUBLE NULL, | +| | TIME INDEX ("ts"), | +| | PRIMARY KEY ("host") | +| | ) | +| | | +| | ENGINE=mito | +| | WITH( | +| | comment = 'create by human' | +| | ) | ++---------+-----------------------------------------------------------+ + +DROP TABLE monitor; + +Affected Rows: 0 + diff --git a/tests/cases/standalone/common/create/create.sql b/tests/cases/standalone/common/create/create.sql index 9f541da312..8aa1f48606 100644 --- a/tests/cases/standalone/common/create/create.sql +++ b/tests/cases/standalone/common/create/create.sql @@ -81,3 +81,14 @@ DROP TABLE test_like_1; DROP TABLE test_like_2; DROP table `ExcePTuRi`; + +CREATE TABLE if not exists monitor ( + host STRING, + ts TIMESTAMP(9) DEFAULT CURRENT_TIMESTAMP() TIME INDEX, + cpu FLOAT64 DEFAULT 0, + memory FLOAT64, + PRIMARY KEY(host)) ENGINE=mito WITH(COMMENT='create by human'); + +SHOW CREATE TABLE monitor; + +DROP TABLE monitor;