Skip to content

Commit ac555d7

Browse files
committed
Remove "SQL" prefix from types
The rationale here is the same as the last commit: since this crate exclusively parses SQL, there's no need to restate that in every type name. (The prefix seems to be an artifact of this crate's history as a submodule of Datafusion, where it was useful to explicitly call out which types were related to SQL parsing.) This commit has the additional benefit of making all type names consistent; over type we'd added some types which were not prefixed with "SQL".
1 parent cf655ad commit ac555d7

17 files changed

+817
-835
lines changed

examples/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ fn main() {
3030
);
3131

3232
let dialect: Box<dyn Dialect> = match std::env::args().nth(2).unwrap_or_default().as_ref() {
33-
"--ansi" => Box::new(AnsiSqlDialect {}),
33+
"--ansi" => Box::new(AnsiDialect {}),
3434
"--postgres" => Box::new(PostgreSqlDialect {}),
3535
"--ms" => Box::new(MsSqlDialect {}),
36-
"--generic" | "" => Box::new(GenericSqlDialect {}),
36+
"--generic" | "" => Box::new(GenericDialect {}),
3737
s => panic!("Unexpected parameter: {}", s),
3838
};
3939

examples/parse_select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#![warn(clippy::all)]
1414

15-
use sqlparser::dialect::GenericSqlDialect;
15+
use sqlparser::dialect::GenericDialect;
1616
use sqlparser::parser::*;
1717

1818
fn main() {
@@ -21,7 +21,7 @@ fn main() {
2121
WHERE a > b AND b < 100 \
2222
ORDER BY a DESC, b";
2323

24-
let dialect = GenericSqlDialect {};
24+
let dialect = GenericDialect {};
2525

2626
let ast = Parser::parse_sql(&dialect, sql.to_string()).unwrap();
2727

src/ast/data_type.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
use super::SQLObjectName;
13+
use super::ObjectName;
1414

1515
/// SQL data types
1616
#[derive(Debug, Clone, PartialEq, Hash)]
17-
pub enum SQLType {
17+
pub enum DataType {
1818
/// Fixed-length character type e.g. CHAR(10)
1919
Char(Option<u64>),
2020
/// Variable-length character type e.g. VARCHAR(10)
@@ -60,44 +60,44 @@ pub enum SQLType {
6060
/// Bytea
6161
Bytea,
6262
/// Custom type such as enums
63-
Custom(SQLObjectName),
63+
Custom(ObjectName),
6464
/// Arrays
65-
Array(Box<SQLType>),
65+
Array(Box<DataType>),
6666
}
6767

68-
impl ToString for SQLType {
68+
impl ToString for DataType {
6969
fn to_string(&self) -> String {
7070
match self {
71-
SQLType::Char(size) => format_type_with_optional_length("char", size),
72-
SQLType::Varchar(size) => format_type_with_optional_length("character varying", size),
73-
SQLType::Uuid => "uuid".to_string(),
74-
SQLType::Clob(size) => format!("clob({})", size),
75-
SQLType::Binary(size) => format!("binary({})", size),
76-
SQLType::Varbinary(size) => format!("varbinary({})", size),
77-
SQLType::Blob(size) => format!("blob({})", size),
78-
SQLType::Decimal(precision, scale) => {
71+
DataType::Char(size) => format_type_with_optional_length("char", size),
72+
DataType::Varchar(size) => format_type_with_optional_length("character varying", size),
73+
DataType::Uuid => "uuid".to_string(),
74+
DataType::Clob(size) => format!("clob({})", size),
75+
DataType::Binary(size) => format!("binary({})", size),
76+
DataType::Varbinary(size) => format!("varbinary({})", size),
77+
DataType::Blob(size) => format!("blob({})", size),
78+
DataType::Decimal(precision, scale) => {
7979
if let Some(scale) = scale {
8080
format!("numeric({},{})", precision.unwrap(), scale)
8181
} else {
8282
format_type_with_optional_length("numeric", precision)
8383
}
8484
}
85-
SQLType::Float(size) => format_type_with_optional_length("float", size),
86-
SQLType::SmallInt => "smallint".to_string(),
87-
SQLType::Int => "int".to_string(),
88-
SQLType::BigInt => "bigint".to_string(),
89-
SQLType::Real => "real".to_string(),
90-
SQLType::Double => "double".to_string(),
91-
SQLType::Boolean => "boolean".to_string(),
92-
SQLType::Date => "date".to_string(),
93-
SQLType::Time => "time".to_string(),
94-
SQLType::Timestamp => "timestamp".to_string(),
95-
SQLType::Interval => "interval".to_string(),
96-
SQLType::Regclass => "regclass".to_string(),
97-
SQLType::Text => "text".to_string(),
98-
SQLType::Bytea => "bytea".to_string(),
99-
SQLType::Array(ty) => format!("{}[]", ty.to_string()),
100-
SQLType::Custom(ty) => ty.to_string(),
85+
DataType::Float(size) => format_type_with_optional_length("float", size),
86+
DataType::SmallInt => "smallint".to_string(),
87+
DataType::Int => "int".to_string(),
88+
DataType::BigInt => "bigint".to_string(),
89+
DataType::Real => "real".to_string(),
90+
DataType::Double => "double".to_string(),
91+
DataType::Boolean => "boolean".to_string(),
92+
DataType::Date => "date".to_string(),
93+
DataType::Time => "time".to_string(),
94+
DataType::Timestamp => "timestamp".to_string(),
95+
DataType::Interval => "interval".to_string(),
96+
DataType::Regclass => "regclass".to_string(),
97+
DataType::Text => "text".to_string(),
98+
DataType::Bytea => "bytea".to_string(),
99+
DataType::Array(ty) => format!("{}[]", ty.to_string()),
100+
DataType::Custom(ty) => ty.to_string(),
101101
}
102102
}
103103
}

src/ast/ddl.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! AST types specific to CREATE/ALTER variants of `SQLStatement`
22
//! (commonly referred to as Data Definition Language, or DDL)
3-
use super::{Expr, SQLIdent, SQLObjectName, SQLType};
3+
use super::{DataType, Expr, Ident, ObjectName};
44

55
/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation
66
#[derive(Debug, Clone, PartialEq, Hash)]
77
pub enum AlterTableOperation {
88
/// `ADD <table_constraint>`
99
AddConstraint(TableConstraint),
1010
/// TODO: implement `DROP CONSTRAINT <name>`
11-
DropConstraint { name: SQLIdent },
11+
DropConstraint { name: Ident },
1212
}
1313

1414
impl ToString for AlterTableOperation {
@@ -26,22 +26,22 @@ impl ToString for AlterTableOperation {
2626
pub enum TableConstraint {
2727
/// `[ CONSTRAINT <name> ] { PRIMARY KEY | UNIQUE } (<columns>)`
2828
Unique {
29-
name: Option<SQLIdent>,
30-
columns: Vec<SQLIdent>,
29+
name: Option<Ident>,
30+
columns: Vec<Ident>,
3131
/// Whether this is a `PRIMARY KEY` or just a `UNIQUE` constraint
3232
is_primary: bool,
3333
},
3434
/// A referential integrity constraint (`[ CONSTRAINT <name> ] FOREIGN KEY (<columns>)
3535
/// REFERENCES <foreign_table> (<referred_columns>)`)
3636
ForeignKey {
37-
name: Option<SQLIdent>,
38-
columns: Vec<SQLIdent>,
39-
foreign_table: SQLObjectName,
40-
referred_columns: Vec<SQLIdent>,
37+
name: Option<Ident>,
38+
columns: Vec<Ident>,
39+
foreign_table: ObjectName,
40+
referred_columns: Vec<Ident>,
4141
},
4242
/// `[ CONSTRAINT <name> ] CHECK (<expr>)`
4343
Check {
44-
name: Option<SQLIdent>,
44+
name: Option<Ident>,
4545
expr: Box<Expr>,
4646
},
4747
}
@@ -82,14 +82,14 @@ impl ToString for TableConstraint {
8282

8383
/// SQL column definition
8484
#[derive(Debug, Clone, PartialEq, Hash)]
85-
pub struct SQLColumnDef {
86-
pub name: SQLIdent,
87-
pub data_type: SQLType,
88-
pub collation: Option<SQLObjectName>,
85+
pub struct ColumnDef {
86+
pub name: Ident,
87+
pub data_type: DataType,
88+
pub collation: Option<ObjectName>,
8989
pub options: Vec<ColumnOptionDef>,
9090
}
9191

92-
impl ToString for SQLColumnDef {
92+
impl ToString for ColumnDef {
9393
fn to_string(&self) -> String {
9494
format!(
9595
"{} {}{}",
@@ -122,7 +122,7 @@ impl ToString for SQLColumnDef {
122122
/// "column options," and we allow any column option to be named.
123123
#[derive(Debug, Clone, PartialEq, Hash)]
124124
pub struct ColumnOptionDef {
125-
pub name: Option<SQLIdent>,
125+
pub name: Option<Ident>,
126126
pub option: ColumnOption,
127127
}
128128

@@ -153,8 +153,8 @@ pub enum ColumnOption {
153153
/// A referential integrity constraint (`[FOREIGN KEY REFERENCES
154154
/// <foreign_table> (<referred_columns>)`).
155155
ForeignKey {
156-
foreign_table: SQLObjectName,
157-
referred_columns: Vec<SQLIdent>,
156+
foreign_table: ObjectName,
157+
referred_columns: Vec<Ident>,
158158
},
159159
// `CHECK (<expr>)`
160160
Check(Expr),
@@ -187,7 +187,7 @@ impl ToString for ColumnOption {
187187
}
188188
}
189189

190-
fn format_constraint_name(name: &Option<SQLIdent>) -> String {
190+
fn format_constraint_name(name: &Option<Ident>) -> String {
191191
name.as_ref()
192192
.map(|name| format!("CONSTRAINT {} ", name))
193193
.unwrap_or_default()

0 commit comments

Comments
 (0)