Skip to content

Commit cfb5f90

Browse files
altmannmarceloayman-sigma
authored andcommitted
Add support for INVISIBLE columns in MySQL (apache#2033)
1 parent 36741ed commit cfb5f90

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
@@ -8175,6 +8175,8 @@ impl<'a> Parser<'a> {
81758175
Keyword::REPLACE,
81768176
])?,
81778177
)))
8178+
} else if self.parse_keyword(Keyword::INVISIBLE) {
8179+
Ok(Some(ColumnOption::Invisible))
81788180
} else {
81798181
Ok(None)
81808182
}

tests/sqlparser_common.rs

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

1716617166
let ast_sql = r#"SELECT * FROM SEMANTIC_VIEW(
17167-
my_model
17167+
my_model
1716817168
DIMENSIONS DATE_PART('year', date_col), region_name
1716917169
METRICS orders.revenue, orders.count
1717017170
WHERE active = true
@@ -17219,3 +17219,56 @@ fn parse_adjacent_string_literal_concatenation() {
1721917219
let sql = "SELECT * FROM t WHERE col = 'Hello' \n ' ' \t 'World!'";
1722017220
dialects.one_statement_parses_to(sql, r"SELECT * FROM t WHERE col = 'Hello World!'");
1722117221
}
17222+
17223+
#[test]
17224+
fn parse_invisible_column() {
17225+
let sql = r#"CREATE TABLE t (foo INT, bar INT INVISIBLE)"#;
17226+
let stmt = verified_stmt(sql);
17227+
match stmt {
17228+
Statement::CreateTable(CreateTable { columns, .. }) => {
17229+
assert_eq!(
17230+
columns,
17231+
vec![
17232+
ColumnDef {
17233+
name: "foo".into(),
17234+
data_type: DataType::Int(None),
17235+
options: vec![]
17236+
},
17237+
ColumnDef {
17238+
name: "bar".into(),
17239+
data_type: DataType::Int(None),
17240+
options: vec![ColumnOptionDef {
17241+
name: None,
17242+
option: ColumnOption::Invisible
17243+
}]
17244+
}
17245+
]
17246+
);
17247+
}
17248+
_ => panic!("Unexpected statement {stmt}"),
17249+
}
17250+
17251+
let sql = r#"ALTER TABLE t ADD COLUMN bar INT INVISIBLE"#;
17252+
let stmt = verified_stmt(sql);
17253+
match stmt {
17254+
Statement::AlterTable { operations, .. } => {
17255+
assert_eq!(
17256+
operations,
17257+
vec![AlterTableOperation::AddColumn {
17258+
column_keyword: true,
17259+
if_not_exists: false,
17260+
column_def: ColumnDef {
17261+
name: "bar".into(),
17262+
data_type: DataType::Int(None),
17263+
options: vec![ColumnOptionDef {
17264+
name: None,
17265+
option: ColumnOption::Invisible
17266+
}]
17267+
},
17268+
column_position: None
17269+
}]
17270+
);
17271+
}
17272+
_ => panic!("Unexpected statement {stmt}"),
17273+
}
17274+
}

0 commit comments

Comments
 (0)