Skip to content

Commit

Permalink
avoid _ fn
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Mar 2, 2024
1 parent 86a1a4c commit b8a9ec5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
13 changes: 6 additions & 7 deletions src/operator/src/statement/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,18 +88,17 @@ 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())
.await
.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;

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/query/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions src/sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,22 @@ impl<'a> ParserContext<'a> {
}

pub fn parse_table_name(sql: &'a str, dialect: &dyn Dialect) -> Result<ObjectName> {
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<ObjectName> {
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<ObjectName> {
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))
}

Expand Down
6 changes: 3 additions & 3 deletions src/sql/src/parsers/create_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b8a9ec5

Please sign in to comment.