Skip to content

Commit cdba436

Browse files
authored
Merge pull request apache#123 from benesch/eq
Implement Eq alongside Hash
2 parents f7199ec + add898c commit cdba436

File tree

6 files changed

+40
-40
lines changed

6 files changed

+40
-40
lines changed

src/ast/data_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use super::ObjectName;
1414

1515
/// SQL data types
16-
#[derive(Debug, Clone, PartialEq, Hash)]
16+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1717
pub enum DataType {
1818
/// Fixed-length character type e.g. CHAR(10)
1919
Char(Option<u64>),

src/ast/ddl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{DataType, Expr, Ident, ObjectName};
44

55
/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation
6-
#[derive(Debug, Clone, PartialEq, Hash)]
6+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
77
pub enum AlterTableOperation {
88
/// `ADD <table_constraint>`
99
AddConstraint(TableConstraint),
@@ -22,7 +22,7 @@ impl ToString for AlterTableOperation {
2222

2323
/// A table-level constraint, specified in a `CREATE TABLE` or an
2424
/// `ALTER TABLE ADD <constraint>` statement.
25-
#[derive(Debug, Clone, PartialEq, Hash)]
25+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2626
pub enum TableConstraint {
2727
/// `[ CONSTRAINT <name> ] { PRIMARY KEY | UNIQUE } (<columns>)`
2828
Unique {
@@ -81,7 +81,7 @@ impl ToString for TableConstraint {
8181
}
8282

8383
/// SQL column definition
84-
#[derive(Debug, Clone, PartialEq, Hash)]
84+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8585
pub struct ColumnDef {
8686
pub name: Ident,
8787
pub data_type: DataType,
@@ -120,7 +120,7 @@ impl ToString for ColumnDef {
120120
/// For maximum flexibility, we don't distinguish between constraint and
121121
/// non-constraint options, lumping them all together under the umbrella of
122122
/// "column options," and we allow any column option to be named.
123-
#[derive(Debug, Clone, PartialEq, Hash)]
123+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
124124
pub struct ColumnOptionDef {
125125
pub name: Option<Ident>,
126126
pub option: ColumnOption,
@@ -138,7 +138,7 @@ impl ToString for ColumnOptionDef {
138138

139139
/// `ColumnOption`s are modifiers that follow a column definition in a `CREATE
140140
/// TABLE` statement.
141-
#[derive(Debug, Clone, PartialEq, Hash)]
141+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
142142
pub enum ColumnOption {
143143
/// `NULL`
144144
Null,

src/ast/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub type Ident = String;
5252
/// The parser does not distinguish between expressions of different types
5353
/// (e.g. boolean vs string), so the caller must handle expressions of
5454
/// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary.
55-
#[derive(Debug, Clone, PartialEq, Hash)]
55+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5656
pub enum Expr {
5757
/// Identifier e.g. table name or column name
5858
Identifier(Ident),
@@ -232,7 +232,7 @@ impl ToString for Expr {
232232
}
233233

234234
/// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`)
235-
#[derive(Debug, Clone, PartialEq, Hash)]
235+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
236236
pub struct WindowSpec {
237237
pub partition_by: Vec<Expr>,
238238
pub order_by: Vec<OrderByExpr>,
@@ -276,7 +276,7 @@ impl ToString for WindowSpec {
276276

277277
/// Specifies the data processed by a window function, e.g.
278278
/// `RANGE UNBOUNDED PRECEDING` or `ROWS BETWEEN 5 PRECEDING AND CURRENT ROW`.
279-
#[derive(Debug, Clone, PartialEq, Hash)]
279+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
280280
pub struct WindowFrame {
281281
pub units: WindowFrameUnits,
282282
pub start_bound: WindowFrameBound,
@@ -285,7 +285,7 @@ pub struct WindowFrame {
285285
// TBD: EXCLUDE
286286
}
287287

288-
#[derive(Debug, Clone, PartialEq, Hash)]
288+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
289289
pub enum WindowFrameUnits {
290290
Rows,
291291
Range,
@@ -318,7 +318,7 @@ impl FromStr for WindowFrameUnits {
318318
}
319319
}
320320

321-
#[derive(Debug, Clone, PartialEq, Hash)]
321+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
322322
pub enum WindowFrameBound {
323323
/// "CURRENT ROW"
324324
CurrentRow,
@@ -343,7 +343,7 @@ impl ToString for WindowFrameBound {
343343

344344
/// A top-level statement (SELECT, INSERT, CREATE, etc.)
345345
#[allow(clippy::large_enum_variant)]
346-
#[derive(Debug, Clone, PartialEq, Hash)]
346+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
347347
pub enum Statement {
348348
/// SELECT
349349
Query(Box<Query>),
@@ -588,7 +588,7 @@ impl ToString for Statement {
588588
}
589589

590590
/// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
591-
#[derive(Debug, Clone, PartialEq, Hash)]
591+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
592592
pub struct ObjectName(pub Vec<Ident>);
593593

594594
impl ToString for ObjectName {
@@ -598,7 +598,7 @@ impl ToString for ObjectName {
598598
}
599599

600600
/// SQL assignment `foo = expr` as used in SQLUpdate
601-
#[derive(Debug, Clone, PartialEq, Hash)]
601+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
602602
pub struct Assignment {
603603
pub id: Ident,
604604
pub value: Expr,
@@ -611,7 +611,7 @@ impl ToString for Assignment {
611611
}
612612

613613
/// SQL function
614-
#[derive(Debug, Clone, PartialEq, Hash)]
614+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
615615
pub struct Function {
616616
pub name: ObjectName,
617617
pub args: Vec<Expr>,
@@ -636,7 +636,7 @@ impl ToString for Function {
636636
}
637637

638638
/// External table's available file format
639-
#[derive(Debug, Clone, PartialEq, Hash)]
639+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
640640
pub enum FileFormat {
641641
TEXTFILE,
642642
SEQUENCEFILE,
@@ -685,7 +685,7 @@ impl FromStr for FileFormat {
685685
}
686686
}
687687

688-
#[derive(Debug, Clone, PartialEq, Hash)]
688+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
689689
pub enum ObjectType {
690690
Table,
691691
View,
@@ -700,7 +700,7 @@ impl ObjectType {
700700
}
701701
}
702702

703-
#[derive(Debug, Clone, PartialEq, Hash)]
703+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
704704
pub struct SqlOption {
705705
pub name: Ident,
706706
pub value: Value,
@@ -712,7 +712,7 @@ impl ToString for SqlOption {
712712
}
713713
}
714714

715-
#[derive(Debug, Clone, PartialEq, Hash)]
715+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
716716
pub enum TransactionMode {
717717
AccessMode(TransactionAccessMode),
718718
IsolationLevel(TransactionIsolationLevel),
@@ -728,7 +728,7 @@ impl ToString for TransactionMode {
728728
}
729729
}
730730

731-
#[derive(Debug, Clone, PartialEq, Hash)]
731+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
732732
pub enum TransactionAccessMode {
733733
ReadOnly,
734734
ReadWrite,
@@ -744,7 +744,7 @@ impl ToString for TransactionAccessMode {
744744
}
745745
}
746746

747-
#[derive(Debug, Clone, PartialEq, Hash)]
747+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
748748
pub enum TransactionIsolationLevel {
749749
ReadUncommitted,
750750
ReadCommitted,

src/ast/operator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// limitations under the License.
1212

1313
/// Unary operators
14-
#[derive(Debug, Clone, PartialEq, Hash)]
14+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1515
pub enum UnaryOperator {
1616
Plus,
1717
Minus,
@@ -29,7 +29,7 @@ impl ToString for UnaryOperator {
2929
}
3030

3131
/// Binary operators
32-
#[derive(Debug, Clone, PartialEq, Hash)]
32+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3333
pub enum BinaryOperator {
3434
Plus,
3535
Minus,

src/ast/query.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::*;
1414

1515
/// The most complete variant of a `SELECT` query expression, optionally
1616
/// including `WITH`, `UNION` / other set operations, and `ORDER BY`.
17-
#[derive(Debug, Clone, PartialEq, Hash)]
17+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1818
pub struct Query {
1919
/// WITH (common table expressions, or CTEs)
2020
pub ctes: Vec<Cte>,
@@ -56,7 +56,7 @@ impl ToString for Query {
5656

5757
/// A node in a tree, representing a "query body" expression, roughly:
5858
/// `SELECT ... [ {UNION|EXCEPT|INTERSECT} SELECT ...]`
59-
#[derive(Debug, Clone, PartialEq, Hash)]
59+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6060
pub enum SetExpr {
6161
/// Restricted SELECT .. FROM .. HAVING (no ORDER BY or set operations)
6262
Select(Box<Select>),
@@ -99,7 +99,7 @@ impl ToString for SetExpr {
9999
}
100100
}
101101

102-
#[derive(Debug, Clone, PartialEq, Hash)]
102+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
103103
pub enum SetOperator {
104104
Union,
105105
Except,
@@ -119,7 +119,7 @@ impl ToString for SetOperator {
119119
/// A restricted variant of `SELECT` (without CTEs/`ORDER BY`), which may
120120
/// appear either as the only body item of an `SQLQuery`, or as an operand
121121
/// to a set operation like `UNION`.
122-
#[derive(Debug, Clone, PartialEq, Hash)]
122+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
123123
pub struct Select {
124124
pub distinct: bool,
125125
/// projection expressions
@@ -161,7 +161,7 @@ impl ToString for Select {
161161
/// The names in the column list before `AS`, when specified, replace the names
162162
/// of the columns returned by the query. The parser does not validate that the
163163
/// number of columns in the query matches the number of columns in the query.
164-
#[derive(Debug, Clone, PartialEq, Hash)]
164+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
165165
pub struct Cte {
166166
pub alias: TableAlias,
167167
pub query: Query,
@@ -174,7 +174,7 @@ impl ToString for Cte {
174174
}
175175

176176
/// One item of the comma-separated list following `SELECT`
177-
#[derive(Debug, Clone, PartialEq, Hash)]
177+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
178178
pub enum SelectItem {
179179
/// Any expression, not followed by `[ AS ] alias`
180180
UnnamedExpr(Expr),
@@ -199,7 +199,7 @@ impl ToString for SelectItem {
199199
}
200200
}
201201

202-
#[derive(Debug, Clone, PartialEq, Hash)]
202+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
203203
pub struct TableWithJoins {
204204
pub relation: TableFactor,
205205
pub joins: Vec<Join>,
@@ -216,7 +216,7 @@ impl ToString for TableWithJoins {
216216
}
217217

218218
/// A table name or a parenthesized subquery with an optional alias
219-
#[derive(Debug, Clone, PartialEq, Hash)]
219+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
220220
pub enum TableFactor {
221221
Table {
222222
name: ObjectName,
@@ -283,7 +283,7 @@ impl ToString for TableFactor {
283283
}
284284
}
285285

286-
#[derive(Debug, Clone, PartialEq, Hash)]
286+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
287287
pub struct TableAlias {
288288
pub name: Ident,
289289
pub columns: Vec<Ident>,
@@ -299,7 +299,7 @@ impl ToString for TableAlias {
299299
}
300300
}
301301

302-
#[derive(Debug, Clone, PartialEq, Hash)]
302+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
303303
pub struct Join {
304304
pub relation: TableFactor,
305305
pub join_operator: JoinOperator,
@@ -352,7 +352,7 @@ impl ToString for Join {
352352
}
353353
}
354354

355-
#[derive(Debug, Clone, PartialEq, Hash)]
355+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
356356
pub enum JoinOperator {
357357
Inner(JoinConstraint),
358358
LeftOuter(JoinConstraint),
@@ -365,15 +365,15 @@ pub enum JoinOperator {
365365
OuterApply,
366366
}
367367

368-
#[derive(Debug, Clone, PartialEq, Hash)]
368+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
369369
pub enum JoinConstraint {
370370
On(Expr),
371371
Using(Vec<Ident>),
372372
Natural,
373373
}
374374

375375
/// SQL ORDER BY expression
376-
#[derive(Debug, Clone, PartialEq, Hash)]
376+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
377377
pub struct OrderByExpr {
378378
pub expr: Expr,
379379
pub asc: Option<bool>,
@@ -389,7 +389,7 @@ impl ToString for OrderByExpr {
389389
}
390390
}
391391

392-
#[derive(Debug, Clone, PartialEq, Hash)]
392+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
393393
pub struct Fetch {
394394
pub with_ties: bool,
395395
pub percent: bool,
@@ -413,7 +413,7 @@ impl ToString for Fetch {
413413
}
414414
}
415415

416-
#[derive(Debug, Clone, PartialEq, Hash)]
416+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
417417
pub struct Values(pub Vec<Vec<Expr>>);
418418

419419
impl ToString for Values {

src/ast/value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use ordered_float::OrderedFloat;
1414

1515
/// Primitive SQL values such as number and string
16-
#[derive(Debug, Clone, PartialEq, Hash)]
16+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1717
pub enum Value {
1818
/// Unsigned integer value
1919
Long(u64),
@@ -113,7 +113,7 @@ impl ToString for Value {
113113
}
114114
}
115115

116-
#[derive(Debug, Clone, PartialEq, Hash)]
116+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
117117
pub enum DateTimeField {
118118
Year,
119119
Month,

0 commit comments

Comments
 (0)