Skip to content

Commit a15c70d

Browse files
Add support for INVISIBLE columns in MySQL (#2033)
1 parent 3c61db5 commit a15c70d

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

src/ast/ddl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,13 @@ pub enum ColumnOption {
19111911
/// ```
19121912
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/creating-spatial-indexes.html
19131913
Srid(Box<Expr>),
1914+
/// MySQL specific: Column is invisible via SELECT *
1915+
/// Syntax:
1916+
/// ```sql
1917+
/// CREATE TABLE t (foo INT, bar INT INVISIBLE);
1918+
/// ```
1919+
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/invisible-columns.html
1920+
Invisible,
19141921
}
19151922

19161923
impl fmt::Display for ColumnOption {
@@ -2029,6 +2036,9 @@ impl fmt::Display for ColumnOption {
20292036
Srid(srid) => {
20302037
write!(f, "SRID {srid}")
20312038
}
2039+
Invisible => {
2040+
write!(f, "INVISIBLE")
2041+
}
20322042
}
20332043
}
20342044
}

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ impl Spanned for ColumnOption {
918918
ColumnOption::Policy(..) => Span::empty(),
919919
ColumnOption::Tags(..) => Span::empty(),
920920
ColumnOption::Srid(..) => Span::empty(),
921+
ColumnOption::Invisible => Span::empty(),
921922
}
922923
}
923924
}

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ define_keywords!(
499499
INTERSECTION,
500500
INTERVAL,
501501
INTO,
502+
INVISIBLE,
502503
INVOKER,
503504
IO,
504505
IS,

src/parser/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8144,6 +8144,8 @@ impl<'a> Parser<'a> {
81448144
Keyword::REPLACE,
81458145
])?,
81468146
)))
8147+
} else if self.parse_keyword(Keyword::INVISIBLE) {
8148+
Ok(Some(ColumnOption::Invisible))
81478149
} else {
81488150
Ok(None)
81498151
}

tests/sqlparser_common.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17138,7 +17138,7 @@ fn test_parse_semantic_view_table_factor() {
1713817138
}
1713917139

1714017140
let ast_sql = r#"SELECT * FROM SEMANTIC_VIEW(
17141-
my_model
17141+
my_model
1714217142
DIMENSIONS DATE_PART('year', date_col), region_name
1714317143
METRICS orders.revenue, orders.count
1714417144
WHERE active = true
@@ -17193,3 +17193,56 @@ fn parse_adjacent_string_literal_concatenation() {
1719317193
let sql = "SELECT * FROM t WHERE col = 'Hello' \n ' ' \t 'World!'";
1719417194
dialects.one_statement_parses_to(sql, r"SELECT * FROM t WHERE col = 'Hello World!'");
1719517195
}
17196+
17197+
#[test]
17198+
fn parse_invisible_column() {
17199+
let sql = r#"CREATE TABLE t (foo INT, bar INT INVISIBLE)"#;
17200+
let stmt = verified_stmt(sql);
17201+
match stmt {
17202+
Statement::CreateTable(CreateTable { columns, .. }) => {
17203+
assert_eq!(
17204+
columns,
17205+
vec![
17206+
ColumnDef {
17207+
name: "foo".into(),
17208+
data_type: DataType::Int(None),
17209+
options: vec![]
17210+
},
17211+
ColumnDef {
17212+
name: "bar".into(),
17213+
data_type: DataType::Int(None),
17214+
options: vec![ColumnOptionDef {
17215+
name: None,
17216+
option: ColumnOption::Invisible
17217+
}]
17218+
}
17219+
]
17220+
);
17221+
}
17222+
_ => panic!("Unexpected statement {stmt}"),
17223+
}
17224+
17225+
let sql = r#"ALTER TABLE t ADD COLUMN bar INT INVISIBLE"#;
17226+
let stmt = verified_stmt(sql);
17227+
match stmt {
17228+
Statement::AlterTable { operations, .. } => {
17229+
assert_eq!(
17230+
operations,
17231+
vec![AlterTableOperation::AddColumn {
17232+
column_keyword: true,
17233+
if_not_exists: false,
17234+
column_def: ColumnDef {
17235+
name: "bar".into(),
17236+
data_type: DataType::Int(None),
17237+
options: vec![ColumnOptionDef {
17238+
name: None,
17239+
option: ColumnOption::Invisible
17240+
}]
17241+
},
17242+
column_position: None
17243+
}]
17244+
);
17245+
}
17246+
_ => panic!("Unexpected statement {stmt}"),
17247+
}
17248+
}

0 commit comments

Comments
 (0)