Skip to content

Commit 30fcfe2

Browse files
author
aleksei.p
committed
only parse and not modify statement
1 parent d7c743e commit 30fcfe2

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
@@ -5392,7 +5392,7 @@ impl<'a> Parser<'a> {
53925392

53935393
pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError> {
53945394
let name = self.parse_identifier(false)?;
5395-
let mut data_type = if self.is_column_type_sqlite_unspecified() {
5395+
let data_type = if self.is_column_type_sqlite_unspecified() {
53965396
DataType::Unspecified
53975397
} else {
53985398
self.parse_data_type()?
@@ -5424,16 +5424,6 @@ impl<'a> Parser<'a> {
54245424
break;
54255425
};
54265426
}
5427-
// ClickHouse represents a special NULL marker as a data type Nullable
5428-
// https://clickhouse.com/docs/en/sql-reference/data-types/nullable
5429-
if dialect_of!(self is ClickHouseDialect)
5430-
&& options
5431-
.iter()
5432-
.any(|o| matches!(o.option, ColumnOption::Null))
5433-
{
5434-
data_type = DataType::Nullable(Box::new(data_type));
5435-
options.retain(|o| !matches!(o.option, ColumnOption::Null));
5436-
}
54375427
Ok(ColumnDef {
54385428
name,
54395429
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)