From b8a9ec53519635f77035b2c14c041666625c6a30 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 2 Mar 2024 14:16:26 +0800 Subject: [PATCH] avoid _ fn Signed-off-by: tison --- src/operator/src/statement/ddl.rs | 13 ++++++------- src/query/src/sql.rs | 5 +++-- src/sql/src/parser.rs | 21 +++++++++++---------- src/sql/src/parsers/create_parser.rs | 6 +++--- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/operator/src/statement/ddl.rs b/src/operator/src/statement/ddl.rs index 9f5a71ec7fe6..88cb04bc7eba 100644 --- a/src/operator/src/statement/ddl.rs +++ b/src/operator/src/statement/ddl.rs @@ -35,7 +35,7 @@ use datatypes::prelude::ConcreteDataType; use datatypes::schema::RawSchema; use lazy_static::lazy_static; use partition::partition::{PartitionBound, PartitionDef}; -use query::sql::show_create_table; +use query::sql::create_table_stmt; use regex::Regex; use session::context::QueryContextRef; use session::table_name::table_idents_to_full_name; @@ -88,8 +88,8 @@ impl StatementExecutor { .catalog_manager .table(&catalog, &schema, &table) .await - .context(error::CatalogSnafu)? - .context(error::TableNotFoundSnafu { table_name: &table })?; + .context(CatalogSnafu)? + .context(TableNotFoundSnafu { table_name: &table })?; let partitions = self .partition_manager .find_table_partitions(table_ref.table_info().table_id()) @@ -97,9 +97,8 @@ impl StatementExecutor { .context(error::FindTablePartitionRuleSnafu { table_name: table })?; let quote_style = ctx.quote_style(); - let mut create_stmt = - show_create_table::create_table_stmt(&table_ref.table_info(), quote_style) - .context(error::ParseQuerySnafu)?; + let mut create_stmt = create_table_stmt(&table_ref.table_info(), quote_style) + .context(error::ParseQuerySnafu)?; create_stmt.name = stmt.table_name; create_stmt.if_not_exists = false; @@ -205,7 +204,7 @@ impl StatementExecutor { table_info.ident.table_id = table_id; - let table_info = Arc::new(table_info.try_into().context(error::CreateTableInfoSnafu)?); + let table_info = Arc::new(table_info.try_into().context(CreateTableInfoSnafu)?); create_table.table_id = Some(api::v1::TableId { id: table_id }); let table = DistTable::table(table_info); diff --git a/src/query/src/sql.rs b/src/query/src/sql.rs index e170f1208473..34e3f17fdd35 100644 --- a/src/query/src/sql.rs +++ b/src/query/src/sql.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod show_create_table; +mod show_create_table; use std::collections::HashMap; use std::sync::Arc; @@ -37,6 +37,7 @@ use object_store::ObjectStore; use once_cell::sync::Lazy; use regex::Regex; use session::context::QueryContextRef; +pub use show_create_table::create_table_stmt; use snafu::{ensure, OptionExt, ResultExt}; use sql::statements::create::Partitions; use sql::statements::show::{ShowDatabases, ShowKind, ShowTables, ShowVariables}; @@ -260,7 +261,7 @@ pub fn show_create_table( let quote_style = query_ctx.quote_style(); - let mut stmt = show_create_table::create_table_stmt(&table_info, quote_style)?; + let mut stmt = create_table_stmt(&table_info, quote_style)?; stmt.partitions = partitions.map(|mut p| { p.set_quote(quote_style); p diff --git a/src/sql/src/parser.rs b/src/sql/src/parser.rs index 46e47401f39d..917ed004ed84 100644 --- a/src/sql/src/parser.rs +++ b/src/sql/src/parser.rs @@ -75,21 +75,22 @@ impl<'a> ParserContext<'a> { } pub fn parse_table_name(sql: &'a str, dialect: &dyn Dialect) -> Result { - let mut parser = Parser::new(dialect) + let parser = Parser::new(dialect) .with_options(ParserOptions::new().with_trailing_commas(true)) .try_with_sql(sql) .context(SyntaxSnafu)?; - - Self::_parse_table_name(&mut parser, sql) + ParserContext { parser, sql }.intern_parse_table_name() } - pub(crate) fn _parse_table_name(parser: &mut Parser, sql: &'a str) -> Result { - let raw_table_name = parser.parse_object_name().context(error::UnexpectedSnafu { - sql, - expected: "a table name", - actual: parser.peek_token().to_string(), - })?; - + pub(crate) fn intern_parse_table_name(&mut self) -> Result { + let raw_table_name = self + .parser + .parse_object_name() + .context(error::UnexpectedSnafu { + sql, + expected: "a table name", + actual: self.parser.peek_token().to_string(), + })?; Ok(Self::canonicalize_object_name(raw_table_name)) } diff --git a/src/sql/src/parsers/create_parser.rs b/src/sql/src/parsers/create_parser.rs index 63e9d7641c8b..00a797d44b23 100644 --- a/src/sql/src/parsers/create_parser.rs +++ b/src/sql/src/parsers/create_parser.rs @@ -66,7 +66,7 @@ impl<'a> ParserContext<'a> { let if_not_exists = self.parser .parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]); - let table_name = ParserContext::_parse_table_name(&mut self.parser, self.sql)?; + let table_name = self.intern_parse_table_name()?; let (columns, constraints) = self.parse_columns()?; let engine = self.parse_table_engine(common_catalog::consts::FILE_ENGINE)?; let options = self @@ -128,10 +128,10 @@ impl<'a> ParserContext<'a> { self.parser .parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]); - let table_name = ParserContext::_parse_table_name(&mut self.parser, self.sql)?; + let table_name = self.intern_parse_table_name()?; if self.parser.parse_keyword(Keyword::LIKE) { - let source_name = ParserContext::_parse_table_name(&mut self.parser, self.sql)?; + let source_name = self.intern_parse_table_name()?; return Ok(Statement::CreateTableLike(CreateTableLike { table_name,