From 86a1a4c0c2bb2b477b663442ee97440e088dbfa3 Mon Sep 17 00:00:00 2001 From: kould Date: Wed, 28 Feb 2024 20:36:55 +0800 Subject: [PATCH] rebase --- src/operator/src/statement/ddl.rs | 4 ++-- src/sql/src/parser.rs | 7 +++++-- src/sql/src/parsers/create_parser.rs | 20 ++++---------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/operator/src/statement/ddl.rs b/src/operator/src/statement/ddl.rs index e4e60b65b9c0..9f5a71ec7fe6 100644 --- a/src/operator/src/statement/ddl.rs +++ b/src/operator/src/statement/ddl.rs @@ -38,9 +38,10 @@ use partition::partition::{PartitionBound, PartitionDef}; use query::sql::show_create_table; use regex::Regex; use session::context::QueryContextRef; +use session::table_name::table_idents_to_full_name; use snafu::{ensure, IntoError, OptionExt, ResultExt}; use sql::statements::alter::AlterTable; -use sql::statements::create::{CreateExternalTable, CreateTable, Partitions}; +use sql::statements::create::{CreateExternalTable, CreateTable, CreateTableLike, Partitions}; use table::dist_table::DistTable; use table::metadata::{self, RawTableInfo, RawTableMeta, TableId, TableInfo, TableType}; use table::requests::{AlterKind, AlterTableRequest, TableOptions}; @@ -57,7 +58,6 @@ use crate::error::{ }; use crate::expr_factory; use crate::statement::show::create_partitions_stmt; -use crate::table::table_idents_to_full_name; lazy_static! { static ref NAME_PATTERN_REG: Regex = Regex::new(&format!("^{NAME_PATTERN}$")).unwrap(); diff --git a/src/sql/src/parser.rs b/src/sql/src/parser.rs index 52aaf0213bd4..46e47401f39d 100644 --- a/src/sql/src/parser.rs +++ b/src/sql/src/parser.rs @@ -80,14 +80,17 @@ impl<'a> ParserContext<'a> { .try_with_sql(sql) .context(SyntaxSnafu)?; + Self::_parse_table_name(&mut parser, sql) + } + + 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(), })?; - let table_name = Self::canonicalize_object_name(raw_table_name); - Ok(table_name) + Ok(Self::canonicalize_object_name(raw_table_name)) } pub fn parse_function(sql: &'a str, dialect: &dyn Dialect) -> Result { diff --git a/src/sql/src/parsers/create_parser.rs b/src/sql/src/parsers/create_parser.rs index 2f1057222ee4..63e9d7641c8b 100644 --- a/src/sql/src/parsers/create_parser.rs +++ b/src/sql/src/parsers/create_parser.rs @@ -32,7 +32,7 @@ use crate::error::{ }; use crate::parser::ParserContext; use crate::statements::create::{ - CreateDatabase, CreateExternalTable, CreateTable, Partitions, TIME_INDEX, + CreateDatabase, CreateExternalTable, CreateTable, CreateTableLike, Partitions, TIME_INDEX, }; use crate::statements::get_data_type_by_alias_name; use crate::statements::statement::Statement; @@ -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 = self.parse_table_name()?; + let table_name = ParserContext::_parse_table_name(&mut self.parser, self.sql)?; 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 = self.parse_table_name()?; + let table_name = ParserContext::_parse_table_name(&mut self.parser, self.sql)?; if self.parser.parse_keyword(Keyword::LIKE) { - let source_name = self.parse_table_name()?; + let source_name = ParserContext::_parse_table_name(&mut self.parser, self.sql)?; return Ok(Statement::CreateTableLike(CreateTableLike { table_name, @@ -173,18 +173,6 @@ impl<'a> ParserContext<'a> { Ok(Statement::CreateTable(create_table)) } - fn parse_table_name(&mut self) -> Result { - let raw_table_name = self - .parser - .parse_object_name() - .context(error::UnexpectedSnafu { - sql: self.sql, - expected: "a table name", - actual: self.peek_token_as_string(), - })?; - Ok(Self::canonicalize_object_name(raw_table_name)) - } - /// "PARTITION BY ..." syntax: // TODO(ruihang): docs fn parse_partitions(&mut self) -> Result> {