Skip to content

Commit ba13bb2

Browse files
committed
Implement Eq alongside Hash
1 parent b04f558 commit ba13bb2

File tree

6 files changed

+43
-47
lines changed

6 files changed

+43
-47
lines changed

src/sqlast/ddl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{ASTNode, SQLIdent, SQLObjectName, SQLType};
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 SQLColumnDef {
8686
pub name: SQLIdent,
8787
pub data_type: SQLType,
@@ -120,7 +120,7 @@ impl ToString for SQLColumnDef {
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<SQLIdent>,
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/sqlast/mod.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub type SQLIdent = String;
5353
/// The parser does not distinguish between expressions of different types
5454
/// (e.g. boolean vs string), so the caller must handle expressions of
5555
/// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary.
56-
#[derive(Debug, Clone, PartialEq, Hash)]
56+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5757
pub enum ASTNode {
5858
/// Identifier e.g. table name or column name
5959
SQLIdentifier(SQLIdent),
@@ -232,7 +232,7 @@ impl ToString for ASTNode {
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 SQLWindowSpec {
237237
pub partition_by: Vec<ASTNode>,
238238
pub order_by: Vec<SQLOrderByExpr>,
@@ -276,7 +276,7 @@ impl ToString for SQLWindowSpec {
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 SQLWindowFrame {
281281
pub units: SQLWindowFrameUnits,
282282
pub start_bound: SQLWindowFrameBound,
@@ -285,7 +285,7 @@ pub struct SQLWindowFrame {
285285
// TBD: EXCLUDE
286286
}
287287

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

321-
#[derive(Debug, Clone, PartialEq, Hash)]
321+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
322322
pub enum SQLWindowFrameBound {
323323
/// "CURRENT ROW"
324324
CurrentRow,
@@ -343,7 +343,7 @@ impl ToString for SQLWindowFrameBound {
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 SQLStatement {
348348
/// SELECT
349349
SQLQuery(Box<SQLQuery>),
@@ -437,13 +437,9 @@ pub enum SQLStatement {
437437
/// ROLLBACK [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ]
438438
SQLRollback { chain: bool },
439439
/// PEEK
440-
SQLPeek {
441-
name: SQLObjectName,
442-
},
440+
SQLPeek { name: SQLObjectName },
443441
/// TAIL
444-
SQLTail {
445-
name: SQLObjectName,
446-
},
442+
SQLTail { name: SQLObjectName },
447443
}
448444

449445
impl ToString for SQLStatement {
@@ -658,7 +654,7 @@ impl ToString for SQLStatement {
658654
}
659655

660656
/// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
661-
#[derive(Debug, Clone, PartialEq, Hash)]
657+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
662658
pub struct SQLObjectName(pub Vec<SQLIdent>);
663659

664660
impl ToString for SQLObjectName {
@@ -668,7 +664,7 @@ impl ToString for SQLObjectName {
668664
}
669665

670666
/// SQL assignment `foo = expr` as used in SQLUpdate
671-
#[derive(Debug, Clone, PartialEq, Hash)]
667+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
672668
pub struct SQLAssignment {
673669
pub id: SQLIdent,
674670
pub value: ASTNode,
@@ -681,7 +677,7 @@ impl ToString for SQLAssignment {
681677
}
682678

683679
/// SQL function
684-
#[derive(Debug, Clone, PartialEq, Hash)]
680+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
685681
pub struct SQLFunction {
686682
pub name: SQLObjectName,
687683
pub args: Vec<ASTNode>,
@@ -706,7 +702,7 @@ impl ToString for SQLFunction {
706702
}
707703

708704
/// Specifies the schema associated with a given Kafka topic.
709-
#[derive(Debug, Clone, PartialEq, Hash)]
705+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
710706
pub enum SourceSchema {
711707
/// The schema is specified directly in the contained string.
712708
Raw(String),
@@ -716,7 +712,7 @@ pub enum SourceSchema {
716712
}
717713

718714
/// External table's available file format
719-
#[derive(Debug, Clone, PartialEq, Hash)]
715+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
720716
pub enum FileFormat {
721717
TEXTFILE,
722718
SEQUENCEFILE,
@@ -765,7 +761,7 @@ impl FromStr for FileFormat {
765761
}
766762
}
767763

768-
#[derive(Debug, Clone, PartialEq, Hash)]
764+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
769765
pub enum SQLObjectType {
770766
Table,
771767
View,
@@ -784,7 +780,7 @@ impl SQLObjectType {
784780
}
785781
}
786782

787-
#[derive(Debug, Clone, PartialEq, Hash)]
783+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
788784
pub struct SQLOption {
789785
pub name: SQLIdent,
790786
pub value: Value,
@@ -796,7 +792,7 @@ impl ToString for SQLOption {
796792
}
797793
}
798794

799-
#[derive(Debug, Clone, PartialEq, Hash)]
795+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
800796
pub enum TransactionMode {
801797
AccessMode(TransactionAccessMode),
802798
IsolationLevel(TransactionIsolationLevel),
@@ -812,7 +808,7 @@ impl ToString for TransactionMode {
812808
}
813809
}
814810

815-
#[derive(Debug, Clone, PartialEq, Hash)]
811+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
816812
pub enum TransactionAccessMode {
817813
ReadOnly,
818814
ReadWrite,
@@ -828,7 +824,7 @@ impl ToString for TransactionAccessMode {
828824
}
829825
}
830826

831-
#[derive(Debug, Clone, PartialEq, Hash)]
827+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
832828
pub enum TransactionIsolationLevel {
833829
ReadUncommitted,
834830
ReadCommitted,

src/sqlast/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 SQLQuery {
1919
/// WITH (common table expressions, or CTEs)
2020
pub ctes: Vec<Cte>,
@@ -56,7 +56,7 @@ impl ToString for SQLQuery {
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 SQLSetExpr {
6161
/// Restricted SELECT .. FROM .. HAVING (no ORDER BY or set operations)
6262
Select(Box<SQLSelect>),
@@ -99,7 +99,7 @@ impl ToString for SQLSetExpr {
9999
}
100100
}
101101

102-
#[derive(Debug, Clone, PartialEq, Hash)]
102+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
103103
pub enum SQLSetOperator {
104104
Union,
105105
Except,
@@ -119,7 +119,7 @@ impl ToString for SQLSetOperator {
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 SQLSelect {
124124
pub distinct: bool,
125125
/// projection expressions
@@ -161,7 +161,7 @@ impl ToString for SQLSelect {
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: SQLIdent,
167167
pub query: SQLQuery,
@@ -179,7 +179,7 @@ impl ToString for Cte {
179179
}
180180

181181
/// One item of the comma-separated list following `SELECT`
182-
#[derive(Debug, Clone, PartialEq, Hash)]
182+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
183183
pub enum SQLSelectItem {
184184
/// Any expression, not followed by `[ AS ] alias`
185185
UnnamedExpression(ASTNode),
@@ -204,7 +204,7 @@ impl ToString for SQLSelectItem {
204204
}
205205
}
206206

207-
#[derive(Debug, Clone, PartialEq, Hash)]
207+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
208208
pub struct TableWithJoins {
209209
pub relation: TableFactor,
210210
pub joins: Vec<Join>,
@@ -221,7 +221,7 @@ impl ToString for TableWithJoins {
221221
}
222222

223223
/// A table name or a parenthesized subquery with an optional alias
224-
#[derive(Debug, Clone, PartialEq, Hash)]
224+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
225225
pub enum TableFactor {
226226
Table {
227227
name: SQLObjectName,
@@ -284,7 +284,7 @@ impl ToString for TableFactor {
284284
}
285285
}
286286

287-
#[derive(Debug, Clone, PartialEq, Hash)]
287+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
288288
pub struct TableAlias {
289289
pub name: SQLIdent,
290290
pub columns: Vec<SQLIdent>,
@@ -300,7 +300,7 @@ impl ToString for TableAlias {
300300
}
301301
}
302302

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

354-
#[derive(Debug, Clone, PartialEq, Hash)]
354+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
355355
pub enum JoinOperator {
356356
Inner(JoinConstraint),
357357
LeftOuter(JoinConstraint),
@@ -360,15 +360,15 @@ pub enum JoinOperator {
360360
Cross,
361361
}
362362

363-
#[derive(Debug, Clone, PartialEq, Hash)]
363+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
364364
pub enum JoinConstraint {
365365
On(ASTNode),
366366
Using(Vec<SQLIdent>),
367367
Natural,
368368
}
369369

370370
/// SQL ORDER BY expression
371-
#[derive(Debug, Clone, PartialEq, Hash)]
371+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
372372
pub struct SQLOrderByExpr {
373373
pub expr: ASTNode,
374374
pub asc: Option<bool>,
@@ -384,7 +384,7 @@ impl ToString for SQLOrderByExpr {
384384
}
385385
}
386386

387-
#[derive(Debug, Clone, PartialEq, Hash)]
387+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
388388
pub struct Fetch {
389389
pub with_ties: bool,
390390
pub percent: bool,
@@ -408,7 +408,7 @@ impl ToString for Fetch {
408408
}
409409
}
410410

411-
#[derive(Debug, Clone, PartialEq, Hash)]
411+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
412412
pub struct SQLValues(pub Vec<Vec<ASTNode>>);
413413

414414
impl ToString for SQLValues {

src/sqlast/sql_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 SQLUnaryOperator {
1616
Plus,
1717
Minus,
@@ -29,7 +29,7 @@ impl ToString for SQLUnaryOperator {
2929
}
3030

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

src/sqlast/sqltype.rs

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

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

src/sqlast/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),
@@ -102,7 +102,7 @@ impl ToString for Value {
102102
}
103103
}
104104

105-
#[derive(Debug, Clone, PartialEq, Hash)]
105+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
106106
pub enum SQLDateTimeField {
107107
Year,
108108
Month,

0 commit comments

Comments
 (0)