From bba3108e0d1e8fc8d042dfd821c7c78dd33d0ac3 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 25 Apr 2024 12:06:05 +0800 Subject: [PATCH] refactor!: unify sql options into OptionMap (#3792) * unify sql options into OptionMap Signed-off-by: tison * fixup Signed-off-by: tison * Update src/sql/src/util.rs * drop legacy regions option Signed-off-by: tison * fixup Signed-off-by: tison * fixup Signed-off-by: tison --------- Signed-off-by: tison --- docs/schema-structs.md | 4 +- src/cmd/src/cli/export.rs | 4 +- src/frontend/src/instance.rs | 2 +- src/operator/src/expr_factory.rs | 6 +- src/query/src/sql/show_create_table.rs | 59 ++++---------- src/sql/src/error.rs | 9 +++ src/sql/src/parsers/copy_parser.rs | 12 +-- src/sql/src/parsers/create_parser.rs | 77 ++++++++----------- src/sql/src/statements/create.rs | 30 +++----- src/sql/src/statements/tql.rs | 3 +- src/sql/src/util.rs | 36 +++------ src/table/src/requests.rs | 5 +- tests-integration/src/instance.rs | 4 +- tests-integration/src/tests/instance_test.rs | 19 ++--- tests/cases/standalone/common/basic.result | 2 +- tests/cases/standalone/common/basic.sql | 2 +- .../common/create/create_type_alias.result | 4 +- .../common/create/create_with_options.result | 5 +- .../common/create/create_with_options.sql | 5 +- .../common/create/current_timestamp.result | 12 +-- .../standalone/common/drop/drop_table.result | 2 +- .../standalone/common/drop/drop_table.sql | 2 +- .../standalone/common/show/show_create.result | 5 +- 23 files changed, 110 insertions(+), 199 deletions(-) diff --git a/docs/schema-structs.md b/docs/schema-structs.md index 68638d02c158..032d08547ae2 100644 --- a/docs/schema-structs.md +++ b/docs/schema-structs.md @@ -73,7 +73,7 @@ CREATE TABLE cpu ( usage_system DOUBLE, datacenter STRING, TIME INDEX (ts), - PRIMARY KEY(datacenter, host)) ENGINE=mito WITH(regions=1); + PRIMARY KEY(datacenter, host)) ENGINE=mito; ``` Then the table's `TableMeta` may look like this: @@ -249,7 +249,7 @@ CREATE TABLE cpu ( usage_system DOUBLE, datacenter STRING, TIME INDEX (ts), - PRIMARY KEY(datacenter, host)) ENGINE=mito WITH(regions=1); + PRIMARY KEY(datacenter, host)) ENGINE=mito; select ts, usage_system from cpu; ``` diff --git a/src/cmd/src/cli/export.rs b/src/cmd/src/cli/export.rs index f47b73268738..4122fbd6d7a1 100644 --- a/src/cmd/src/cli/export.rs +++ b/src/cmd/src/cli/export.rs @@ -492,9 +492,7 @@ mod tests { ) ENGINE=mito -WITH( - regions = 1 -); +; "#; assert_eq!(res.trim(), expect.trim()); diff --git a/src/frontend/src/instance.rs b/src/frontend/src/instance.rs index 69a6cc2a12bc..5709c57d2931 100644 --- a/src/frontend/src/instance.rs +++ b/src/frontend/src/instance.rs @@ -650,7 +650,7 @@ mod tests { ts TIMESTAMP, TIME INDEX (ts), PRIMARY KEY(host) - ) engine=mito with(regions=1);"#; + ) engine=mito;"#; replace_test(sql, plugins.clone(), &query_ctx); // test drop table diff --git a/src/operator/src/expr_factory.rs b/src/operator/src/expr_factory.rs index cc950f6ba7ec..0a84c4a7315f 100644 --- a/src/operator/src/expr_factory.rs +++ b/src/operator/src/expr_factory.rs @@ -36,7 +36,6 @@ use sql::ast::{ColumnDef, ColumnOption, TableConstraint}; use sql::statements::alter::{AlterTable, AlterTableOperation}; use sql::statements::create::{CreateExternalTable, CreateTable, TIME_INDEX}; use sql::statements::{column_def_to_schema, sql_column_def_to_grpc_column_def}; -use sql::util::to_lowercase_options_map; use table::requests::{TableOptions, FILE_TABLE_META_KEY}; use table::table_reference::TableReference; @@ -190,8 +189,7 @@ pub fn create_to_expr(create: &CreateTable, query_ctx: QueryContextRef) -> Resul let time_index = find_time_index(&create.constraints)?; let table_options = HashMap::from( - &TableOptions::try_from(&to_lowercase_options_map(&create.options)) - .context(UnrecognizedTableOptionSnafu)?, + &TableOptions::try_from(create.options.as_ref()).context(UnrecognizedTableOptionSnafu)?, ); let primary_keys = find_primary_keys(&create.columns, &create.constraints)?; @@ -502,7 +500,7 @@ mod tests { #[test] fn test_create_to_expr() { - let sql = "CREATE TABLE monitor (host STRING,ts TIMESTAMP,TIME INDEX (ts),PRIMARY KEY(host)) ENGINE=mito WITH(regions=1, ttl='3days', write_buffer_size='1024KB');"; + let sql = "CREATE TABLE monitor (host STRING,ts TIMESTAMP,TIME INDEX (ts),PRIMARY KEY(host)) ENGINE=mito WITH(ttl='3days', write_buffer_size='1024KB');"; let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()) .unwrap() diff --git a/src/query/src/sql/show_create_table.rs b/src/query/src/sql/show_create_table.rs index 2004590aa561..d7ef0f04ea44 100644 --- a/src/query/src/sql/show_create_table.rs +++ b/src/query/src/sql/show_create_table.rs @@ -14,64 +14,35 @@ //! Implementation of `SHOW CREATE TABLE` statement. -use std::fmt::Display; +use std::collections::HashMap; use datatypes::schema::{ColumnDefaultConstraint, ColumnSchema, SchemaRef, COMMENT_KEY}; use humantime::format_duration; use snafu::ResultExt; use sql::ast::{ - ColumnDef, ColumnOption, ColumnOptionDef, Expr, Ident, ObjectName, SqlOption, TableConstraint, - Value as SqlValue, + ColumnDef, ColumnOption, ColumnOptionDef, Expr, Ident, ObjectName, TableConstraint, }; use sql::dialect::GreptimeDbDialect; use sql::parser::ParserContext; use sql::statements::create::{CreateTable, TIME_INDEX}; -use sql::statements::{self}; +use sql::statements::{self, OptionMap}; use table::metadata::{TableInfoRef, TableMeta}; -use table::requests::FILE_TABLE_META_KEY; +use table::requests::{FILE_TABLE_META_KEY, TTL_KEY, WRITE_BUFFER_SIZE_KEY}; use crate::error::{ConvertSqlTypeSnafu, ConvertSqlValueSnafu, Result, SqlSnafu}; -#[inline] -fn number_value(n: T) -> SqlValue { - SqlValue::Number(format!("{}", n), false) -} - -#[inline] -fn string_value(s: impl Into) -> SqlValue { - SqlValue::SingleQuotedString(s.into()) -} - -#[inline] -fn sql_option(name: &str, value: SqlValue) -> SqlOption { - SqlOption { - name: name.into(), - value: Expr::Value(value), - } -} - -fn create_sql_options(table_meta: &TableMeta) -> Vec { +fn create_sql_options(table_meta: &TableMeta) -> OptionMap { let table_opts = &table_meta.options; - let mut options = Vec::with_capacity(4 + table_opts.extra_options.len()); - - if !table_meta.region_numbers.is_empty() { - options.push(sql_option( - "regions", - number_value(table_meta.region_numbers.len()), - )); - } + let mut options = HashMap::with_capacity(4 + table_opts.extra_options.len()); if let Some(write_buffer_size) = table_opts.write_buffer_size { - options.push(sql_option( - "write_buffer_size", - string_value(write_buffer_size.to_string()), - )); + options.insert( + WRITE_BUFFER_SIZE_KEY.to_string(), + write_buffer_size.to_string(), + ); } if let Some(ttl) = table_opts.ttl { - options.push(sql_option( - "ttl", - string_value(format_duration(ttl).to_string()), - )); + options.insert(TTL_KEY.to_string(), format_duration(ttl).to_string()); } for (k, v) in table_opts @@ -79,10 +50,10 @@ fn create_sql_options(table_meta: &TableMeta) -> Vec { .iter() .filter(|(k, _)| k != &FILE_TABLE_META_KEY) { - options.push(sql_option(k, string_value(v))); + options.insert(k.to_string(), v.to_string()); } - options + OptionMap { map: options } } #[inline] @@ -265,9 +236,7 @@ CREATE TABLE IF NOT EXISTS "system_metrics" ( PRIMARY KEY ("id", "host") ) ENGINE=mito -WITH( - regions = 3 -)"#, +"#, sql ); } diff --git a/src/sql/src/error.rs b/src/sql/src/error.rs index 3d274fe6bc3c..6f1516d78f69 100644 --- a/src/sql/src/error.rs +++ b/src/sql/src/error.rs @@ -21,6 +21,7 @@ use common_time::timestamp::TimeUnit; use common_time::Timestamp; use datatypes::prelude::{ConcreteDataType, Value}; use snafu::{Location, Snafu}; +use sqlparser::ast::Ident; use sqlparser::parser::ParserError; use crate::ast::{Expr, Value as SqlValue}; @@ -141,6 +142,13 @@ pub enum Error { #[snafu(display("Unrecognized table option key: {}", key))] InvalidTableOption { key: String, location: Location }, + #[snafu(display("Unrecognized table option key: {}, value: {}", key, value))] + InvalidTableOptionValue { + key: Ident, + value: Expr, + location: Location, + }, + #[snafu(display("Failed to serialize column default constraint"))] SerializeColumnDefaultConstraint { location: Location, @@ -201,6 +209,7 @@ impl ErrorExt for Error { | InvalidDefault { .. } => StatusCode::InvalidSyntax, InvalidColumnOption { .. } + | InvalidTableOptionValue { .. } | InvalidDatabaseName { .. } | ColumnTypeMismatch { .. } | InvalidTableName { .. } diff --git a/src/sql/src/parsers/copy_parser.rs b/src/sql/src/parsers/copy_parser.rs index be4b18764460..fbe093a8b51e 100644 --- a/src/sql/src/parsers/copy_parser.rs +++ b/src/sql/src/parsers/copy_parser.rs @@ -129,10 +129,8 @@ impl<'a> ParserContext<'a> { let with = options .into_iter() - .filter_map(|option| { - parse_option_string(option.value).map(|v| (option.name.value.to_lowercase(), v)) - }) - .collect(); + .map(parse_option_string) + .collect::>()?; let connection_options = self .parser @@ -141,10 +139,8 @@ impl<'a> ParserContext<'a> { let connection = connection_options .into_iter() - .filter_map(|option| { - parse_option_string(option.value).map(|v| (option.name.value.to_lowercase(), v)) - }) - .collect(); + .map(parse_option_string) + .collect::>()?; Ok((with, connection, location)) } diff --git a/src/sql/src/parsers/create_parser.rs b/src/sql/src/parsers/create_parser.rs index 08764aaa6e42..20d2ef8eab30 100644 --- a/src/sql/src/parsers/create_parser.rs +++ b/src/sql/src/parsers/create_parser.rs @@ -34,8 +34,8 @@ use crate::parser::ParserContext; use crate::statements::create::{ CreateDatabase, CreateExternalTable, CreateTable, CreateTableLike, Partitions, TIME_INDEX, }; -use crate::statements::get_data_type_by_alias_name; use crate::statements::statement::Statement; +use crate::statements::{get_data_type_by_alias_name, OptionMap}; use crate::util::parse_option_string; pub const ENGINE: &str = "ENGINE"; @@ -73,32 +73,12 @@ impl<'a> ParserContext<'a> { } let engine = self.parse_table_engine(common_catalog::consts::FILE_ENGINE)?; - let options = self - .parser - .parse_options(Keyword::WITH) - .context(SyntaxSnafu)? - .into_iter() - .filter_map(|option| { - if let Some(v) = parse_option_string(option.value) { - Some((option.name.value.to_lowercase(), v)) - } else { - None - } - }) - .collect::>(); - for key in options.keys() { - ensure!( - validate_table_option(key), - InvalidTableOptionSnafu { - key: key.to_string() - } - ); - } + let options = self.parse_create_table_options()?; Ok(Statement::CreateExternalTable(CreateExternalTable { name: table_name, columns, constraints, - options: options.into(), + options, if_not_exists, engine, })) @@ -149,20 +129,7 @@ impl<'a> ParserContext<'a> { } let engine = self.parse_table_engine(default_engine())?; - let options = self - .parser - .parse_options(Keyword::WITH) - .context(error::SyntaxSnafu)?; - for option in options.iter() { - ensure!( - validate_table_option(&option.name.value), - InvalidTableOptionSnafu { - key: option.name.value.to_string() - } - ); - } - // Sorts options so that `test_display_create_table` can always pass. - let options = options.into_iter().sorted().collect(); + let options = self.parse_create_table_options()?; let create_table = CreateTable { if_not_exists, name: table_name, @@ -177,6 +144,25 @@ impl<'a> ParserContext<'a> { Ok(Statement::CreateTable(create_table)) } + fn parse_create_table_options(&mut self) -> Result { + let options = self + .parser + .parse_options(Keyword::WITH) + .context(SyntaxSnafu)? + .into_iter() + .map(parse_option_string) + .collect::>>()?; + for key in options.keys() { + ensure!( + validate_table_option(key), + InvalidTableOptionSnafu { + key: key.to_string() + } + ); + } + Ok(options.into()) + } + /// "PARTITION BY ..." syntax: // TODO(ruihang): docs fn parse_partitions(&mut self) -> Result> { @@ -1415,7 +1401,7 @@ ENGINE=mito"; memory float64, TIME INDEX (ts), PRIMARY KEY(ts, host)) engine=mito - with(regions=1); + with(ttl='10s'); "; let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()) @@ -1449,9 +1435,9 @@ ENGINE=mito"; } ); let options = &c.options; - assert_eq!(1, options.len()); - assert_eq!("regions", &options[0].name.to_string()); - assert_eq!("1", &options[0].value.to_string()); + assert_eq!(1, options.map.len()); + let (k, v) = options.map.iter().next().unwrap(); + assert_eq!(("ttl", "10s"), (k.as_str(), v.as_str())); } _ => unreachable!(), } @@ -1465,8 +1451,7 @@ ENGINE=mito"; cpu float64 default 0, memory float64, TIME INDEX (ts, host), - PRIMARY KEY(ts, host)) engine=mito - with(regions=1); + PRIMARY KEY(ts, host)) engine=mito; "; let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()); @@ -1483,8 +1468,7 @@ ENGINE=mito"; cpu float64 default 0, memory float64, TIME INDEX (ts, host), - PRIMARY KEY(ts, host)) engine=mito - with(regions=1); + PRIMARY KEY(ts, host)) engine=mito; "; let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()); @@ -1498,8 +1482,7 @@ ENGINE=mito"; t timestamp, memory float64, TIME INDEX (t), - PRIMARY KEY(ts, host)) engine=mito - with(regions=1); + PRIMARY KEY(ts, host)) engine=mito; "; let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()); diff --git a/src/sql/src/statements/create.rs b/src/sql/src/statements/create.rs index eb992b48ef45..92f62b09c072 100644 --- a/src/sql/src/statements/create.rs +++ b/src/sql/src/statements/create.rs @@ -19,7 +19,7 @@ use itertools::Itertools; use sqlparser::ast::Expr; use sqlparser_derive::{Visit, VisitMut}; -use crate::ast::{ColumnDef, Ident, ObjectName, SqlOption, TableConstraint, Value as SqlValue}; +use crate::ast::{ColumnDef, Ident, ObjectName, TableConstraint, Value as SqlValue}; use crate::statements::{redact_and_sort_options, OptionMap}; const LINE_SEP: &str = ",\n"; @@ -86,8 +86,8 @@ pub struct CreateTable { pub columns: Vec, pub engine: String, pub constraints: Vec, - /// Table options in `WITH`. - pub options: Vec, + /// Table options in `WITH`. All keys are lowercase. + pub options: OptionMap, pub partitions: Option, } @@ -155,11 +155,9 @@ impl Display for CreateTable { writeln!(f, "{partitions}")?; } writeln!(f, "ENGINE={}", &self.engine)?; - if !self.options.is_empty() { - writeln!(f, "WITH(")?; - let options: Vec<&SqlOption> = self.options.iter().sorted().collect(); - writeln!(f, "{}", format_list_indent!(options))?; - write!(f, ")")?; + if !self.options.map.is_empty() { + let options = redact_and_sort_options(&self.options); + write!(f, "WITH(\n{}\n)", format_list_indent!(options))?; } Ok(()) } @@ -198,8 +196,7 @@ pub struct CreateExternalTable { pub name: ObjectName, pub columns: Vec, pub constraints: Vec, - /// Table options in `WITH`. - /// All keys are lowercase. + /// Table options in `WITH`. All keys are lowercase. pub options: OptionMap, pub if_not_exists: bool, pub engine: String, @@ -218,9 +215,7 @@ impl Display for CreateExternalTable { writeln!(f, "ENGINE={}", &self.engine)?; if !self.options.map.is_empty() { let options = redact_and_sort_options(&self.options); - writeln!(f, "WITH(")?; - writeln!(f, "{}", format_list_indent!(options))?; - write!(f, ")")?; + write!(f, "WITH(\n{}\n)", format_list_indent!(options))?; } Ok(()) } @@ -266,7 +261,7 @@ mod tests { host > 'a', ) engine=mito - with(regions=1, ttl='7d', storage='File'); + with(ttl='7d', storage='File'); "; let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()) @@ -292,7 +287,6 @@ PARTITION ON COLUMNS (host) ( ) ENGINE=mito WITH( - regions = 1, storage = 'File', ttl = '7d' )"#, @@ -369,14 +363,14 @@ ENGINE=mito ) PARTITION ON COLUMNS (host) () engine=mito - with(regions=1, ttl='7d', 'compaction.type'='world'); + with(ttl='7d', 'compaction.type'='world'); "; let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()) .unwrap(); match &result[0] { Statement::CreateTable(c) => { - assert_eq!(3, c.options.len()); + assert_eq!(2, c.options.map.len()); } _ => unreachable!(), } @@ -391,7 +385,7 @@ ENGINE=mito ) PARTITION ON COLUMNS (host) () engine=mito - with(regions=1, ttl='7d', hello='world'); + with(ttl='7d', hello='world'); "; let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()); diff --git a/src/sql/src/statements/tql.rs b/src/sql/src/statements/tql.rs index 07f8cb8876ec..a963849a70c6 100644 --- a/src/sql/src/statements/tql.rs +++ b/src/sql/src/statements/tql.rs @@ -33,7 +33,6 @@ impl Display for Tql { } } -// TODO: encapsulate shard TQL args into a struct and implement Display for it. fn format_tql( f: &mut std::fmt::Formatter<'_>, start: &str, @@ -61,7 +60,7 @@ pub struct TqlEval { impl Display for TqlEval { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "TQL EVAL")?; + write!(f, "TQL EVAL ")?; format_tql( f, &self.start, diff --git a/src/sql/src/util.rs b/src/sql/src/util.rs index c9c135225280..39efe2c3e411 100644 --- a/src/sql/src/util.rs +++ b/src/sql/src/util.rs @@ -12,13 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; use std::fmt::{Display, Formatter}; use std::sync::LazyLock; use regex::Regex; use sqlparser::ast::{Expr, ObjectName, SqlOption, Value}; +use crate::error::{InvalidTableOptionValueSnafu, Result}; + static SQL_SECRET_PATTERNS: LazyLock> = LazyLock::new(|| { vec![ Regex::new(r#"(?i)access_key_id=["']([^"']*)["'].*"#).unwrap(), @@ -47,29 +48,16 @@ pub fn format_raw_object_name(name: &ObjectName) -> String { format!("{}", Inner { name }) } -pub fn parse_option_string(value: Expr) -> Option { - match value { - Expr::Value(Value::SingleQuotedString(v)) | Expr::Value(Value::DoubleQuotedString(v)) => { - Some(v) - } - _ => None, - } -} - -/// Converts options to HashMap. -/// All keys are lowercase. -pub fn to_lowercase_options_map(opts: &[SqlOption]) -> HashMap { - let mut map = HashMap::with_capacity(opts.len()); - for SqlOption { name, value } in opts { - let value_str = match value { - Expr::Value(Value::SingleQuotedString(s)) - | Expr::Value(Value::DoubleQuotedString(s)) => s.clone(), - Expr::Identifier(i) => i.value.clone(), - _ => value.to_string(), - }; - let _ = map.insert(name.value.to_lowercase().clone(), value_str); - } - map +pub fn parse_option_string(option: SqlOption) -> Result<(String, String)> { + let (key, value) = (option.name, option.value); + let v = match value { + Expr::Value(Value::SingleQuotedString(v)) | Expr::Value(Value::DoubleQuotedString(v)) => v, + Expr::Identifier(v) => v.value, + Expr::Value(Value::Number(v, _)) => v.to_string(), + value => return InvalidTableOptionValueSnafu { key, value }.fail(), + }; + let k = key.value.to_lowercase(); + Ok((k, v)) } /// Use regex to match and replace common seen secret values in SQL. diff --git a/src/table/src/requests.rs b/src/table/src/requests.rs index 9472491bcbe9..e925d0cac0ea 100644 --- a/src/table/src/requests.rs +++ b/src/table/src/requests.rs @@ -53,7 +53,6 @@ pub fn validate_table_option(key: &str) -> bool { // common keys: WRITE_BUFFER_SIZE_KEY, TTL_KEY, - REGIONS_KEY, STORAGE_KEY, // file engine keys: FILE_TABLE_LOCATION_KEY, @@ -80,7 +79,6 @@ pub struct TableOptions { pub const WRITE_BUFFER_SIZE_KEY: &str = "write_buffer_size"; pub const TTL_KEY: &str = "ttl"; -pub const REGIONS_KEY: &str = "regions"; pub const STORAGE_KEY: &str = "storage"; impl TryFrom<&HashMap> for TableOptions { @@ -113,7 +111,7 @@ impl TryFrom<&HashMap> for TableOptions { options.ttl = Some(ttl_value); } options.extra_options = HashMap::from_iter(value.iter().filter_map(|(k, v)| { - if k != WRITE_BUFFER_SIZE_KEY && k != REGIONS_KEY && k != TTL_KEY { + if k != WRITE_BUFFER_SIZE_KEY && k != TTL_KEY { Some((k.clone(), v.clone())) } else { None @@ -281,7 +279,6 @@ mod tests { assert!(validate_table_option(FILE_TABLE_FORMAT_KEY)); assert!(validate_table_option(FILE_TABLE_PATTERN_KEY)); assert!(validate_table_option(TTL_KEY)); - assert!(validate_table_option(REGIONS_KEY)); assert!(validate_table_option(WRITE_BUFFER_SIZE_KEY)); assert!(validate_table_option(STORAGE_KEY)); assert!(!validate_table_option("foo")); diff --git a/tests-integration/src/instance.rs b/tests-integration/src/instance.rs index 87a1ea476f3c..1e52162ef3ca 100644 --- a/tests-integration/src/instance.rs +++ b/tests-integration/src/instance.rs @@ -357,7 +357,7 @@ mod tests { disk_util DOUBLE DEFAULT 9.9, TIME INDEX (ts), PRIMARY KEY(host) - ) engine=mito with(regions=1);"#; + ) engine=mito;"#; let output = SqlQueryHandler::do_query(&*instance, sql, QueryContext::arc()) .await .remove(0) @@ -419,7 +419,7 @@ mod tests { disk_util DOUBLE DEFAULT 9.9, TIME INDEX (ts), PRIMARY KEY(host) - ) engine=mito with(regions=1);"#; + ) engine=mito;"#; let output = SqlQueryHandler::do_query(&*instance, sql, query_ctx.clone()) .await .remove(0) diff --git a/tests-integration/src/tests/instance_test.rs b/tests-integration/src/tests/instance_test.rs index dd6fbccb1ad5..28b1af971d75 100644 --- a/tests-integration/src/tests/instance_test.rs +++ b/tests-integration/src/tests/instance_test.rs @@ -134,9 +134,7 @@ PARTITION ON COLUMNS (n) ( | | n >= 10 AND n < 100 | | | ) | | | ENGINE=mito | -| | WITH( | -| | regions = 4 | -| | ) | +| | | +-------+-------------------------------------+"# } else { r#"+-------+-------------------------------------+ @@ -151,9 +149,7 @@ PARTITION ON COLUMNS (n) ( | | ) | | | | | | ENGINE=mito | -| | WITH( | -| | regions = 1 | -| | ) | +| | | +-------+-------------------------------------+"# }; @@ -228,8 +224,7 @@ async fn test_show_create_external_table(instance: Arc) { ENGINE=file WITH( format = 'csv', - location = '{location}', - regions = 1 + location = '{location}' )"# ); assert_eq!(actual.to_string(), expect); @@ -560,7 +555,7 @@ async fn test_execute_create(instance: Arc) { memory double, TIME INDEX (ts), PRIMARY KEY(host) - ) engine=mito with(regions=1);"#, + ) engine=mito;"#, ) .await .data; @@ -1438,7 +1433,7 @@ async fn test_insert_with_default_value_for_type(instance: Arc, type_n cpu double default 0, TIME INDEX (ts), PRIMARY KEY(host) - ) engine=mito with(regions=1);"#, + ) engine=mito;"#, ); let output = execute_sql(&instance, &create_sql).await.data; assert!(matches!(output, OutputData::AffectedRows(0))); @@ -1555,7 +1550,7 @@ async fn test_delete(instance: Arc) { memory double, TIME INDEX (ts), PRIMARY KEY(host) - ) engine=mito with(regions=1);"#, + ) engine=mito;"#, ) .await .data; @@ -2085,7 +2080,6 @@ PARTITION ON COLUMNS ("a") ( ) ENGINE=mito WITH( - regions = 1, storage = '{storage_name}' )"# ) @@ -2100,7 +2094,6 @@ WITH( ENGINE=mito WITH( - regions = 1, storage = '{storage_name}' )"# ) diff --git a/tests/cases/standalone/common/basic.result b/tests/cases/standalone/common/basic.result index c054009a83a8..3fdd6b1d530d 100644 --- a/tests/cases/standalone/common/basic.result +++ b/tests/cases/standalone/common/basic.result @@ -64,7 +64,7 @@ create table foo ( cpu double default 0, TIME INDEX (ts), PRIMARY KEY(host) -) engine=mito with(regions=1); +) engine=mito; Affected Rows: 0 diff --git a/tests/cases/standalone/common/basic.sql b/tests/cases/standalone/common/basic.sql index fa03cb28942d..707f09df75a7 100644 --- a/tests/cases/standalone/common/basic.sql +++ b/tests/cases/standalone/common/basic.sql @@ -31,7 +31,7 @@ create table foo ( cpu double default 0, TIME INDEX (ts), PRIMARY KEY(host) -) engine=mito with(regions=1); +) engine=mito; insert into foo (host, cpu, ts) values ('host1', 1.1, '2000-01-01 00:00:00+00:00'); diff --git a/tests/cases/standalone/common/create/create_type_alias.result b/tests/cases/standalone/common/create/create_type_alias.result index 44d8aaf2aaf6..b5ac0984a5b1 100644 --- a/tests/cases/standalone/common/create/create_type_alias.result +++ b/tests/cases/standalone/common/create/create_type_alias.result @@ -46,9 +46,7 @@ SHOW CREATE TABLE data_types; | | ) | | | | | | ENGINE=mito | -| | WITH( | -| | regions = 1 | -| | ) | +| | | +------------+------------------------------------------------------------+ DESC TABLE data_types; diff --git a/tests/cases/standalone/common/create/create_with_options.result b/tests/cases/standalone/common/create/create_with_options.result index f205e8469def..4592d8cb9eb5 100644 --- a/tests/cases/standalone/common/create/create_with_options.result +++ b/tests/cases/standalone/common/create/create_with_options.result @@ -30,7 +30,7 @@ create table if not exists test_opts( PRIMARY KEY(host) ) engine=mito -with(regions=1, ttl='7d', 'compaction.type'='twcs', 'compaction.twcs.time_window'='1d'); +with(ttl='7d', 'compaction.type'='twcs', 'compaction.twcs.time_window'='1d'); Affected Rows: 0 @@ -47,7 +47,7 @@ create table if not exists test_opts( PRIMARY KEY(host) ) engine=mito -with('regions'=1, 'ttl'='7d', 'compaction.type'='twcs', 'compaction.twcs.time_window'='1d'); +with('ttl'='7d', 'compaction.type'='twcs', 'compaction.twcs.time_window'='1d'); Affected Rows: 0 @@ -65,7 +65,6 @@ create table if not exists test_mito_options( ) engine=mito with( - 'regions'=1, 'ttl'='7d', 'compaction.type'='twcs', 'compaction.twcs.max_active_window_files'='8', diff --git a/tests/cases/standalone/common/create/create_with_options.sql b/tests/cases/standalone/common/create/create_with_options.sql index 99aa47118985..11ed8757b19a 100644 --- a/tests/cases/standalone/common/create/create_with_options.sql +++ b/tests/cases/standalone/common/create/create_with_options.sql @@ -28,7 +28,7 @@ create table if not exists test_opts( PRIMARY KEY(host) ) engine=mito -with(regions=1, ttl='7d', 'compaction.type'='twcs', 'compaction.twcs.time_window'='1d'); +with(ttl='7d', 'compaction.type'='twcs', 'compaction.twcs.time_window'='1d'); drop table test_opts; @@ -41,7 +41,7 @@ create table if not exists test_opts( PRIMARY KEY(host) ) engine=mito -with('regions'=1, 'ttl'='7d', 'compaction.type'='twcs', 'compaction.twcs.time_window'='1d'); +with('ttl'='7d', 'compaction.type'='twcs', 'compaction.twcs.time_window'='1d'); drop table test_opts; @@ -55,7 +55,6 @@ create table if not exists test_mito_options( ) engine=mito with( - 'regions'=1, 'ttl'='7d', 'compaction.type'='twcs', 'compaction.twcs.max_active_window_files'='8', diff --git a/tests/cases/standalone/common/create/current_timestamp.result b/tests/cases/standalone/common/create/current_timestamp.result index def4fbe5dd6e..6bb53d838030 100644 --- a/tests/cases/standalone/common/create/current_timestamp.result +++ b/tests/cases/standalone/common/create/current_timestamp.result @@ -13,9 +13,7 @@ show create table t1; | | ) | | | | | | ENGINE=mito | -| | WITH( | -| | regions = 1 | -| | ) | +| | | +-------+-----------------------------------------------------------+ create table t2 (ts timestamp time index default currEnt_tImEsTamp()); @@ -33,9 +31,7 @@ show create table t2; | | ) | | | | | | ENGINE=mito | -| | WITH( | -| | regions = 1 | -| | ) | +| | | +-------+-----------------------------------------------------------+ create table t3 (ts timestamp time index default now()); @@ -53,9 +49,7 @@ show create table t3; | | ) | | | | | | ENGINE=mito | -| | WITH( | -| | regions = 1 | -| | ) | +| | | +-------+---------------------------------------------+ create table t4 (ts timestamp time index default now); diff --git a/tests/cases/standalone/common/drop/drop_table.result b/tests/cases/standalone/common/drop/drop_table.result index a8fad0ee78ca..d554a33a1bc1 100644 --- a/tests/cases/standalone/common/drop/drop_table.result +++ b/tests/cases/standalone/common/drop/drop_table.result @@ -8,7 +8,7 @@ create table foo ( cpu double default 0, TIME INDEX (ts), PRIMARY KEY(host) -) engine=mito with(regions=1); +) engine=mito; Affected Rows: 0 diff --git a/tests/cases/standalone/common/drop/drop_table.sql b/tests/cases/standalone/common/drop/drop_table.sql index d6ddf52101c1..65a092ce401f 100644 --- a/tests/cases/standalone/common/drop/drop_table.sql +++ b/tests/cases/standalone/common/drop/drop_table.sql @@ -6,7 +6,7 @@ create table foo ( cpu double default 0, TIME INDEX (ts), PRIMARY KEY(host) -) engine=mito with(regions=1); +) engine=mito; DROP TABLE IF EXISTS foo; diff --git a/tests/cases/standalone/common/show/show_create.result b/tests/cases/standalone/common/show/show_create.result index 60bd139fcf9c..90c99d77f0fa 100644 --- a/tests/cases/standalone/common/show/show_create.result +++ b/tests/cases/standalone/common/show/show_create.result @@ -41,7 +41,6 @@ SHOW CREATE TABLE system_metrics; | | ) | | | ENGINE=mito | | | WITH( | -| | regions = 3, | | | ttl = '7days', | | | write_buffer_size = '1.0KiB' | | | ) | @@ -68,9 +67,7 @@ show create table table_without_partition; | | ) | | | | | | ENGINE=mito | -| | WITH( | -| | regions = 1 | -| | ) | +| | | +-------------------------+-----------------------------------------------------------+ drop table table_without_partition;