Add support of DROP|CLEAR|MATERIALIZE PROJECTION syntax for ClickHouse (#1417)

This commit is contained in:
hulk 2024-09-11 03:26:07 +08:00 committed by GitHub
parent 4875dadbf5
commit a7b49b5072
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 198 additions and 0 deletions

View file

@ -359,6 +359,102 @@ fn parse_alter_table_add_projection() {
);
}
#[test]
fn parse_alter_table_drop_projection() {
match clickhouse_and_generic().verified_stmt("ALTER TABLE t0 DROP PROJECTION IF EXISTS my_name")
{
Statement::AlterTable {
name, operations, ..
} => {
assert_eq!(name, ObjectName(vec!["t0".into()]));
assert_eq!(1, operations.len());
assert_eq!(
operations[0],
AlterTableOperation::DropProjection {
if_exists: true,
name: "my_name".into(),
}
)
}
_ => unreachable!(),
}
// allow to skip `IF EXISTS`
clickhouse_and_generic().verified_stmt("ALTER TABLE t0 DROP PROJECTION my_name");
assert_eq!(
clickhouse_and_generic()
.parse_sql_statements("ALTER TABLE t0 DROP PROJECTION")
.unwrap_err(),
ParserError("Expected: identifier, found: EOF".to_string())
);
}
#[test]
fn parse_alter_table_clear_and_materialize_projection() {
for keyword in ["CLEAR", "MATERIALIZE"] {
match clickhouse_and_generic().verified_stmt(
format!("ALTER TABLE t0 {keyword} PROJECTION IF EXISTS my_name IN PARTITION p0",)
.as_str(),
) {
Statement::AlterTable {
name, operations, ..
} => {
assert_eq!(name, ObjectName(vec!["t0".into()]));
assert_eq!(1, operations.len());
assert_eq!(
operations[0],
if keyword == "CLEAR" {
AlterTableOperation::ClearProjection {
if_exists: true,
name: "my_name".into(),
partition: Some(Ident::new("p0")),
}
} else {
AlterTableOperation::MaterializeProjection {
if_exists: true,
name: "my_name".into(),
partition: Some(Ident::new("p0")),
}
}
)
}
_ => unreachable!(),
}
// allow to skip `IF EXISTS`
clickhouse_and_generic().verified_stmt(
format!("ALTER TABLE t0 {keyword} PROJECTION my_name IN PARTITION p0",).as_str(),
);
// allow to skip `IN PARTITION partition_name`
clickhouse_and_generic()
.verified_stmt(format!("ALTER TABLE t0 {keyword} PROJECTION my_name",).as_str());
assert_eq!(
clickhouse_and_generic()
.parse_sql_statements(format!("ALTER TABLE t0 {keyword} PROJECTION",).as_str())
.unwrap_err(),
ParserError("Expected: identifier, found: EOF".to_string())
);
assert_eq!(
clickhouse_and_generic()
.parse_sql_statements(
format!("ALTER TABLE t0 {keyword} PROJECTION my_name IN PARTITION",).as_str()
)
.unwrap_err(),
ParserError("Expected: identifier, found: EOF".to_string())
);
assert_eq!(
clickhouse_and_generic()
.parse_sql_statements(
format!("ALTER TABLE t0 {keyword} PROJECTION my_name IN",).as_str()
)
.unwrap_err(),
ParserError("Expected: end of statement, found: IN".to_string())
);
}
}
#[test]
fn parse_optimize_table() {
clickhouse_and_generic().verified_stmt("OPTIMIZE TABLE t0");