Implement Eq alongside Hash

It turns out implementing Hash alone is not very useful, as
std::collection::HashMap keys are required to implement both Hash and
Eq.

Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
This commit is contained in:
Jamie Brandon 2019-06-12 14:03:24 +01:00 committed by Nikhil Benesch
parent f7199ec99f
commit add898c2bd
No known key found for this signature in database
GPG key ID: FCF98542083C5A69
6 changed files with 40 additions and 40 deletions

View file

@ -13,7 +13,7 @@
use super::ObjectName; use super::ObjectName;
/// SQL data types /// SQL data types
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DataType { pub enum DataType {
/// Fixed-length character type e.g. CHAR(10) /// Fixed-length character type e.g. CHAR(10)
Char(Option<u64>), Char(Option<u64>),

View file

@ -3,7 +3,7 @@
use super::{DataType, Expr, Ident, ObjectName}; use super::{DataType, Expr, Ident, ObjectName};
/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation /// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AlterTableOperation { pub enum AlterTableOperation {
/// `ADD <table_constraint>` /// `ADD <table_constraint>`
AddConstraint(TableConstraint), AddConstraint(TableConstraint),
@ -22,7 +22,7 @@ impl ToString for AlterTableOperation {
/// A table-level constraint, specified in a `CREATE TABLE` or an /// A table-level constraint, specified in a `CREATE TABLE` or an
/// `ALTER TABLE ADD <constraint>` statement. /// `ALTER TABLE ADD <constraint>` statement.
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TableConstraint { pub enum TableConstraint {
/// `[ CONSTRAINT <name> ] { PRIMARY KEY | UNIQUE } (<columns>)` /// `[ CONSTRAINT <name> ] { PRIMARY KEY | UNIQUE } (<columns>)`
Unique { Unique {
@ -81,7 +81,7 @@ impl ToString for TableConstraint {
} }
/// SQL column definition /// SQL column definition
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ColumnDef { pub struct ColumnDef {
pub name: Ident, pub name: Ident,
pub data_type: DataType, pub data_type: DataType,
@ -120,7 +120,7 @@ impl ToString for ColumnDef {
/// For maximum flexibility, we don't distinguish between constraint and /// For maximum flexibility, we don't distinguish between constraint and
/// non-constraint options, lumping them all together under the umbrella of /// non-constraint options, lumping them all together under the umbrella of
/// "column options," and we allow any column option to be named. /// "column options," and we allow any column option to be named.
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ColumnOptionDef { pub struct ColumnOptionDef {
pub name: Option<Ident>, pub name: Option<Ident>,
pub option: ColumnOption, pub option: ColumnOption,
@ -138,7 +138,7 @@ impl ToString for ColumnOptionDef {
/// `ColumnOption`s are modifiers that follow a column definition in a `CREATE /// `ColumnOption`s are modifiers that follow a column definition in a `CREATE
/// TABLE` statement. /// TABLE` statement.
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ColumnOption { pub enum ColumnOption {
/// `NULL` /// `NULL`
Null, Null,

View file

@ -52,7 +52,7 @@ pub type Ident = String;
/// The parser does not distinguish between expressions of different types /// The parser does not distinguish between expressions of different types
/// (e.g. boolean vs string), so the caller must handle expressions of /// (e.g. boolean vs string), so the caller must handle expressions of
/// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary. /// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary.
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Expr { pub enum Expr {
/// Identifier e.g. table name or column name /// Identifier e.g. table name or column name
Identifier(Ident), Identifier(Ident),
@ -232,7 +232,7 @@ impl ToString for Expr {
} }
/// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`) /// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`)
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WindowSpec { pub struct WindowSpec {
pub partition_by: Vec<Expr>, pub partition_by: Vec<Expr>,
pub order_by: Vec<OrderByExpr>, pub order_by: Vec<OrderByExpr>,
@ -276,7 +276,7 @@ impl ToString for WindowSpec {
/// Specifies the data processed by a window function, e.g. /// Specifies the data processed by a window function, e.g.
/// `RANGE UNBOUNDED PRECEDING` or `ROWS BETWEEN 5 PRECEDING AND CURRENT ROW`. /// `RANGE UNBOUNDED PRECEDING` or `ROWS BETWEEN 5 PRECEDING AND CURRENT ROW`.
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WindowFrame { pub struct WindowFrame {
pub units: WindowFrameUnits, pub units: WindowFrameUnits,
pub start_bound: WindowFrameBound, pub start_bound: WindowFrameBound,
@ -285,7 +285,7 @@ pub struct WindowFrame {
// TBD: EXCLUDE // TBD: EXCLUDE
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WindowFrameUnits { pub enum WindowFrameUnits {
Rows, Rows,
Range, Range,
@ -318,7 +318,7 @@ impl FromStr for WindowFrameUnits {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WindowFrameBound { pub enum WindowFrameBound {
/// "CURRENT ROW" /// "CURRENT ROW"
CurrentRow, CurrentRow,
@ -343,7 +343,7 @@ impl ToString for WindowFrameBound {
/// A top-level statement (SELECT, INSERT, CREATE, etc.) /// A top-level statement (SELECT, INSERT, CREATE, etc.)
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Statement { pub enum Statement {
/// SELECT /// SELECT
Query(Box<Query>), Query(Box<Query>),
@ -588,7 +588,7 @@ impl ToString for Statement {
} }
/// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj /// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ObjectName(pub Vec<Ident>); pub struct ObjectName(pub Vec<Ident>);
impl ToString for ObjectName { impl ToString for ObjectName {
@ -598,7 +598,7 @@ impl ToString for ObjectName {
} }
/// SQL assignment `foo = expr` as used in SQLUpdate /// SQL assignment `foo = expr` as used in SQLUpdate
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Assignment { pub struct Assignment {
pub id: Ident, pub id: Ident,
pub value: Expr, pub value: Expr,
@ -611,7 +611,7 @@ impl ToString for Assignment {
} }
/// SQL function /// SQL function
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Function { pub struct Function {
pub name: ObjectName, pub name: ObjectName,
pub args: Vec<Expr>, pub args: Vec<Expr>,
@ -636,7 +636,7 @@ impl ToString for Function {
} }
/// External table's available file format /// External table's available file format
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum FileFormat { pub enum FileFormat {
TEXTFILE, TEXTFILE,
SEQUENCEFILE, SEQUENCEFILE,
@ -685,7 +685,7 @@ impl FromStr for FileFormat {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ObjectType { pub enum ObjectType {
Table, Table,
View, View,
@ -700,7 +700,7 @@ impl ObjectType {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SqlOption { pub struct SqlOption {
pub name: Ident, pub name: Ident,
pub value: Value, pub value: Value,
@ -712,7 +712,7 @@ impl ToString for SqlOption {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TransactionMode { pub enum TransactionMode {
AccessMode(TransactionAccessMode), AccessMode(TransactionAccessMode),
IsolationLevel(TransactionIsolationLevel), IsolationLevel(TransactionIsolationLevel),
@ -728,7 +728,7 @@ impl ToString for TransactionMode {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TransactionAccessMode { pub enum TransactionAccessMode {
ReadOnly, ReadOnly,
ReadWrite, ReadWrite,
@ -744,7 +744,7 @@ impl ToString for TransactionAccessMode {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TransactionIsolationLevel { pub enum TransactionIsolationLevel {
ReadUncommitted, ReadUncommitted,
ReadCommitted, ReadCommitted,

View file

@ -11,7 +11,7 @@
// limitations under the License. // limitations under the License.
/// Unary operators /// Unary operators
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UnaryOperator { pub enum UnaryOperator {
Plus, Plus,
Minus, Minus,
@ -29,7 +29,7 @@ impl ToString for UnaryOperator {
} }
/// Binary operators /// Binary operators
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BinaryOperator { pub enum BinaryOperator {
Plus, Plus,
Minus, Minus,

View file

@ -14,7 +14,7 @@ use super::*;
/// The most complete variant of a `SELECT` query expression, optionally /// The most complete variant of a `SELECT` query expression, optionally
/// including `WITH`, `UNION` / other set operations, and `ORDER BY`. /// including `WITH`, `UNION` / other set operations, and `ORDER BY`.
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Query { pub struct Query {
/// WITH (common table expressions, or CTEs) /// WITH (common table expressions, or CTEs)
pub ctes: Vec<Cte>, pub ctes: Vec<Cte>,
@ -56,7 +56,7 @@ impl ToString for Query {
/// A node in a tree, representing a "query body" expression, roughly: /// A node in a tree, representing a "query body" expression, roughly:
/// `SELECT ... [ {UNION|EXCEPT|INTERSECT} SELECT ...]` /// `SELECT ... [ {UNION|EXCEPT|INTERSECT} SELECT ...]`
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SetExpr { pub enum SetExpr {
/// Restricted SELECT .. FROM .. HAVING (no ORDER BY or set operations) /// Restricted SELECT .. FROM .. HAVING (no ORDER BY or set operations)
Select(Box<Select>), Select(Box<Select>),
@ -99,7 +99,7 @@ impl ToString for SetExpr {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SetOperator { pub enum SetOperator {
Union, Union,
Except, Except,
@ -119,7 +119,7 @@ impl ToString for SetOperator {
/// A restricted variant of `SELECT` (without CTEs/`ORDER BY`), which may /// A restricted variant of `SELECT` (without CTEs/`ORDER BY`), which may
/// appear either as the only body item of an `SQLQuery`, or as an operand /// appear either as the only body item of an `SQLQuery`, or as an operand
/// to a set operation like `UNION`. /// to a set operation like `UNION`.
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Select { pub struct Select {
pub distinct: bool, pub distinct: bool,
/// projection expressions /// projection expressions
@ -161,7 +161,7 @@ impl ToString for Select {
/// The names in the column list before `AS`, when specified, replace the names /// The names in the column list before `AS`, when specified, replace the names
/// of the columns returned by the query. The parser does not validate that the /// of the columns returned by the query. The parser does not validate that the
/// number of columns in the query matches the number of columns in the query. /// number of columns in the query matches the number of columns in the query.
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Cte { pub struct Cte {
pub alias: TableAlias, pub alias: TableAlias,
pub query: Query, pub query: Query,
@ -174,7 +174,7 @@ impl ToString for Cte {
} }
/// One item of the comma-separated list following `SELECT` /// One item of the comma-separated list following `SELECT`
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SelectItem { pub enum SelectItem {
/// Any expression, not followed by `[ AS ] alias` /// Any expression, not followed by `[ AS ] alias`
UnnamedExpr(Expr), UnnamedExpr(Expr),
@ -199,7 +199,7 @@ impl ToString for SelectItem {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TableWithJoins { pub struct TableWithJoins {
pub relation: TableFactor, pub relation: TableFactor,
pub joins: Vec<Join>, pub joins: Vec<Join>,
@ -216,7 +216,7 @@ impl ToString for TableWithJoins {
} }
/// A table name or a parenthesized subquery with an optional alias /// A table name or a parenthesized subquery with an optional alias
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TableFactor { pub enum TableFactor {
Table { Table {
name: ObjectName, name: ObjectName,
@ -283,7 +283,7 @@ impl ToString for TableFactor {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TableAlias { pub struct TableAlias {
pub name: Ident, pub name: Ident,
pub columns: Vec<Ident>, pub columns: Vec<Ident>,
@ -299,7 +299,7 @@ impl ToString for TableAlias {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Join { pub struct Join {
pub relation: TableFactor, pub relation: TableFactor,
pub join_operator: JoinOperator, pub join_operator: JoinOperator,
@ -352,7 +352,7 @@ impl ToString for Join {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum JoinOperator { pub enum JoinOperator {
Inner(JoinConstraint), Inner(JoinConstraint),
LeftOuter(JoinConstraint), LeftOuter(JoinConstraint),
@ -365,7 +365,7 @@ pub enum JoinOperator {
OuterApply, OuterApply,
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum JoinConstraint { pub enum JoinConstraint {
On(Expr), On(Expr),
Using(Vec<Ident>), Using(Vec<Ident>),
@ -373,7 +373,7 @@ pub enum JoinConstraint {
} }
/// SQL ORDER BY expression /// SQL ORDER BY expression
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OrderByExpr { pub struct OrderByExpr {
pub expr: Expr, pub expr: Expr,
pub asc: Option<bool>, pub asc: Option<bool>,
@ -389,7 +389,7 @@ impl ToString for OrderByExpr {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Fetch { pub struct Fetch {
pub with_ties: bool, pub with_ties: bool,
pub percent: bool, pub percent: bool,
@ -413,7 +413,7 @@ impl ToString for Fetch {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Values(pub Vec<Vec<Expr>>); pub struct Values(pub Vec<Vec<Expr>>);
impl ToString for Values { impl ToString for Values {

View file

@ -13,7 +13,7 @@
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
/// Primitive SQL values such as number and string /// Primitive SQL values such as number and string
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Value { pub enum Value {
/// Unsigned integer value /// Unsigned integer value
Long(u64), Long(u64),
@ -113,7 +113,7 @@ impl ToString for Value {
} }
} }
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DateTimeField { pub enum DateTimeField {
Year, Year,
Month, Month,