Skip to content

Commit

Permalink
fix: canonicalize name of create database
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Mar 14, 2024
1 parent ca02a18 commit b14599f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/sql/src/parsers/create_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<'a> ParserContext<'a> {
expected: "a database name",
actual: self.peek_token_as_string(),
})?;

let database_name = Self::canonicalize_object_name(database_name);
Ok(Statement::CreateDatabase(CreateDatabase {
name: database_name,
if_not_exists,
Expand Down Expand Up @@ -722,7 +722,7 @@ mod tests {
use common_catalog::consts::FILE_ENGINE;
use common_error::ext::ErrorExt;
use sqlparser::ast::ColumnOption::NotNull;
use sqlparser::ast::{BinaryOperator, Value};
use sqlparser::ast::{BinaryOperator, ObjectName, Value};

use super::*;
use crate::dialect::GreptimeDbDialect;
Expand Down Expand Up @@ -916,6 +916,18 @@ mod tests {
}
_ => unreachable!(),
}

let sql = "CREATE DATABASE `fOo`";
let result =
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
let mut stmts = result.unwrap();
assert_eq!(
stmts.pop().unwrap(),
Statement::CreateDatabase(CreateDatabase::new(
ObjectName(vec![Ident::with_quote('`', "fOo"),]),
false
))
);
}

#[test]
Expand Down
10 changes: 10 additions & 0 deletions src/sql/src/statements/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ pub struct CreateDatabase {
pub if_not_exists: bool,
}

impl CreateDatabase {
/// Creates a statement for `CREATE DATABASE`
pub fn new(name: ObjectName, if_not_exists: bool) -> Self {
Self {
name,
if_not_exists,
}
}
}

#[derive(Debug, PartialEq, Eq, Clone, Visit, VisitMut)]
pub struct CreateExternalTable {
/// Table name
Expand Down

0 comments on commit b14599f

Please sign in to comment.