Skip to content

Commit 8a214f9

Browse files
authored
Implement Hive QL Parsing (#235)
1 parent 17f8eb9 commit 8a214f9

16 files changed

+1382
-170
lines changed

examples/cli.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ $ cargo run --feature json_example --example cli FILENAME.sql [--dialectname]
4040
"--postgres" => Box::new(PostgreSqlDialect {}),
4141
"--ms" => Box::new(MsSqlDialect {}),
4242
"--snowflake" => Box::new(SnowflakeDialect {}),
43+
"--hive" => Box::new(HiveDialect {}),
4344
"--generic" | "" => Box::new(GenericDialect {}),
4445
s => panic!("Unexpected parameter: {}", s),
4546
};

src/ast/data_type.rs

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub enum DataType {
6161
Regclass,
6262
/// Text
6363
Text,
64+
/// String
65+
String,
6466
/// Bytea
6567
Bytea,
6668
/// Custom type such as enums
@@ -101,6 +103,7 @@ impl fmt::Display for DataType {
101103
DataType::Interval => write!(f, "INTERVAL"),
102104
DataType::Regclass => write!(f, "REGCLASS"),
103105
DataType::Text => write!(f, "TEXT"),
106+
DataType::String => write!(f, "STRING"),
104107
DataType::Bytea => write!(f, "BYTEA"),
105108
DataType::Array(ty) => write!(f, "{}[]", ty),
106109
DataType::Custom(ty) => write!(f, "{}", ty),

src/ast/ddl.rs

+42-1
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,54 @@ pub enum AlterTableOperation {
3535
if_exists: bool,
3636
cascade: bool,
3737
},
38+
/// `RENAME TO PARTITION (partition=val)`
39+
RenamePartitions {
40+
old_partitions: Vec<Expr>,
41+
new_partitions: Vec<Expr>,
42+
},
43+
/// Add Partitions
44+
AddPartitions {
45+
if_not_exists: bool,
46+
new_partitions: Vec<Expr>,
47+
},
48+
DropPartitions {
49+
partitions: Vec<Expr>,
50+
if_exists: bool,
51+
},
3852
/// `RENAME [ COLUMN ] <old_column_name> TO <new_column_name>`
3953
RenameColumn {
4054
old_column_name: Ident,
4155
new_column_name: Ident,
4256
},
4357
/// `RENAME TO <table_name>`
44-
RenameTable { table_name: Ident },
58+
RenameTable { table_name: ObjectName },
4559
}
4660

4761
impl fmt::Display for AlterTableOperation {
4862
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4963
match self {
64+
AlterTableOperation::AddPartitions {
65+
if_not_exists,
66+
new_partitions,
67+
} => write!(
68+
f,
69+
"ADD{ine} PARTITION ({})",
70+
display_comma_separated(new_partitions),
71+
ine = if *if_not_exists { " IF NOT EXISTS" } else { "" }
72+
),
5073
AlterTableOperation::AddConstraint(c) => write!(f, "ADD {}", c),
5174
AlterTableOperation::AddColumn { column_def } => {
5275
write!(f, "ADD COLUMN {}", column_def.to_string())
5376
}
77+
AlterTableOperation::DropPartitions {
78+
partitions,
79+
if_exists,
80+
} => write!(
81+
f,
82+
"DROP{ie} PARTITION ({})",
83+
display_comma_separated(partitions),
84+
ie = if *if_exists { " IF EXISTS" } else { "" }
85+
),
5486
AlterTableOperation::DropConstraint { name } => write!(f, "DROP CONSTRAINT {}", name),
5587
AlterTableOperation::DropColumn {
5688
column_name,
@@ -63,6 +95,15 @@ impl fmt::Display for AlterTableOperation {
6395
column_name,
6496
if *cascade { " CASCADE" } else { "" }
6597
),
98+
AlterTableOperation::RenamePartitions {
99+
old_partitions,
100+
new_partitions,
101+
} => write!(
102+
f,
103+
"PARTITION ({}) RENAME TO PARTITION ({})",
104+
display_comma_separated(old_partitions),
105+
display_comma_separated(new_partitions)
106+
),
66107
AlterTableOperation::RenameColumn {
67108
old_column_name,
68109
new_column_name,

0 commit comments

Comments
 (0)