Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Feb 28, 2024
1 parent 749bc59 commit 86a1a4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/operator/src/statement/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions src/sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectName> {
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<Expr> {
Expand Down
20 changes: 4 additions & 16 deletions src/sql/src/parsers/create_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down 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 = 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
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 = 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,
Expand Down Expand Up @@ -173,18 +173,6 @@ impl<'a> ParserContext<'a> {
Ok(Statement::CreateTable(create_table))
}

fn parse_table_name(&mut self) -> Result<ObjectName> {
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<Option<Partitions>> {
Expand Down

0 comments on commit 86a1a4c

Please sign in to comment.