Skip to content

Commit 8c759d6

Browse files
author
aleksei.p
committed
only parse and not modify statement
1 parent 267d98d commit 8c759d6

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/parser/mod.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5503,7 +5503,7 @@ impl<'a> Parser<'a> {
55035503

55045504
pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError> {
55055505
let name = self.parse_identifier(false)?;
5506-
let mut data_type = if self.is_column_type_sqlite_unspecified() {
5506+
let data_type = if self.is_column_type_sqlite_unspecified() {
55075507
DataType::Unspecified
55085508
} else {
55095509
self.parse_data_type()?
@@ -5535,16 +5535,6 @@ impl<'a> Parser<'a> {
55355535
break;
55365536
};
55375537
}
5538-
// ClickHouse represents a special NULL marker as a data type Nullable
5539-
// https://clickhouse.com/docs/en/sql-reference/data-types/nullable
5540-
if dialect_of!(self is ClickHouseDialect)
5541-
&& options
5542-
.iter()
5543-
.any(|o| matches!(o.option, ColumnOption::Null))
5544-
{
5545-
data_type = DataType::Nullable(Box::new(data_type));
5546-
options.retain(|o| !matches!(o.option, ColumnOption::Null));
5547-
}
55485538
Ok(ColumnDef {
55495539
name,
55505540
data_type,

tests/sqlparser_clickhouse.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ fn parse_create_table() {
223223
#[test]
224224
fn parse_create_table_with_nullable() {
225225
let sql = r#"CREATE TABLE table (k UInt8, `a` Nullable(String), `b` Nullable(DateTime64(9, 'UTC')), c Nullable(DateTime64(9)), d Date32 NULL) ENGINE=MergeTree ORDER BY (`k`)"#;
226-
let canonical_sql = r#"CREATE TABLE table (k UInt8, `a` Nullable(STRING), `b` Nullable(DateTime64(9, 'UTC')), c Nullable(DateTime64(9)), d Nullable(Date32)) ENGINE=MergeTree ORDER BY (`k`)"#;
226+
// ClickHouse has a case-sensitive definition of data type, but canonical representation is not
227+
let canonical_sql = sql.replace("String", "STRING");
227228

228-
match clickhouse().one_statement_parses_to(sql, canonical_sql) {
229+
match clickhouse().one_statement_parses_to(sql, &canonical_sql) {
229230
Statement::CreateTable { name, columns, .. } => {
230231
assert_eq!(name, ObjectName(vec!["table".into()]));
231232
assert_eq!(
@@ -260,9 +261,11 @@ fn parse_create_table_with_nullable() {
260261
},
261262
ColumnDef {
262263
name: Ident::new("d"),
263-
data_type: DataType::Nullable(Box::new(DataType::Date32)),
264+
data_type: DataType::Date32,
264265
collation: None,
265-
options: vec![],
266+
options: vec![
267+
ColumnOptionDef{name: None, option: ColumnOption::Null}
268+
],
266269
},
267270
]
268271
);

0 commit comments

Comments
 (0)