Skip to content

Implement Eq alongside Hash #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use super::ObjectName;

/// SQL data types
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DataType {
/// Fixed-length character type e.g. CHAR(10)
Char(Option<u64>),
Expand Down
10 changes: 5 additions & 5 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::{DataType, Expr, Ident, ObjectName};

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

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

/// SQL column definition
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ColumnDef {
pub name: Ident,
pub data_type: DataType,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl ToString for ColumnDef {
/// For maximum flexibility, we don't distinguish between constraint and
/// non-constraint options, lumping them all together under the umbrella of
/// "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 name: Option<Ident>,
pub option: ColumnOption,
Expand All @@ -138,7 +138,7 @@ impl ToString for ColumnOptionDef {

/// `ColumnOption`s are modifiers that follow a column definition in a `CREATE
/// TABLE` statement.
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ColumnOption {
/// `NULL`
Null,
Expand Down
30 changes: 15 additions & 15 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub type Ident = String;
/// The parser does not distinguish between expressions of different types
/// (e.g. boolean vs string), so the caller must handle expressions of
/// 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 {
/// Identifier e.g. table name or column name
Identifier(Ident),
Expand Down Expand Up @@ -232,7 +232,7 @@ impl ToString for Expr {
}

/// 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 partition_by: Vec<Expr>,
pub order_by: Vec<OrderByExpr>,
Expand Down Expand Up @@ -276,7 +276,7 @@ impl ToString for WindowSpec {

/// Specifies the data processed by a window function, e.g.
/// `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 units: WindowFrameUnits,
pub start_bound: WindowFrameBound,
Expand All @@ -285,7 +285,7 @@ pub struct WindowFrame {
// TBD: EXCLUDE
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WindowFrameUnits {
Rows,
Range,
Expand Down Expand Up @@ -318,7 +318,7 @@ impl FromStr for WindowFrameUnits {
}
}

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

/// A top-level statement (SELECT, INSERT, CREATE, etc.)
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Statement {
/// SELECT
Query(Box<Query>),
Expand Down Expand Up @@ -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
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ObjectName(pub Vec<Ident>);

impl ToString for ObjectName {
Expand All @@ -598,7 +598,7 @@ impl ToString for ObjectName {
}

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

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

/// External table's available file format
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum FileFormat {
TEXTFILE,
SEQUENCEFILE,
Expand Down Expand Up @@ -685,7 +685,7 @@ impl FromStr for FileFormat {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ObjectType {
Table,
View,
Expand All @@ -700,7 +700,7 @@ impl ObjectType {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SqlOption {
pub name: Ident,
pub value: Value,
Expand All @@ -712,7 +712,7 @@ impl ToString for SqlOption {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TransactionMode {
AccessMode(TransactionAccessMode),
IsolationLevel(TransactionIsolationLevel),
Expand All @@ -728,7 +728,7 @@ impl ToString for TransactionMode {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TransactionAccessMode {
ReadOnly,
ReadWrite,
Expand All @@ -744,7 +744,7 @@ impl ToString for TransactionAccessMode {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TransactionIsolationLevel {
ReadUncommitted,
ReadCommitted,
Expand Down
4 changes: 2 additions & 2 deletions src/ast/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// limitations under the License.

/// Unary operators
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UnaryOperator {
Plus,
Minus,
Expand All @@ -29,7 +29,7 @@ impl ToString for UnaryOperator {
}

/// Binary operators
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BinaryOperator {
Plus,
Minus,
Expand Down
30 changes: 15 additions & 15 deletions src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::*;

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

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

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SetOperator {
Union,
Except,
Expand All @@ -119,7 +119,7 @@ impl ToString for SetOperator {
/// 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
/// to a set operation like `UNION`.
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Select {
pub distinct: bool,
/// projection expressions
Expand Down Expand Up @@ -161,7 +161,7 @@ impl ToString for Select {
/// 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
/// 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 alias: TableAlias,
pub query: Query,
Expand All @@ -174,7 +174,7 @@ impl ToString for Cte {
}

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

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

/// 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 {
Table {
name: ObjectName,
Expand Down Expand Up @@ -283,7 +283,7 @@ impl ToString for TableFactor {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TableAlias {
pub name: Ident,
pub columns: Vec<Ident>,
Expand All @@ -299,7 +299,7 @@ impl ToString for TableAlias {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Join {
pub relation: TableFactor,
pub join_operator: JoinOperator,
Expand Down Expand Up @@ -352,7 +352,7 @@ impl ToString for Join {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum JoinOperator {
Inner(JoinConstraint),
LeftOuter(JoinConstraint),
Expand All @@ -365,15 +365,15 @@ pub enum JoinOperator {
OuterApply,
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum JoinConstraint {
On(Expr),
Using(Vec<Ident>),
Natural,
}

/// SQL ORDER BY expression
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OrderByExpr {
pub expr: Expr,
pub asc: Option<bool>,
Expand All @@ -389,7 +389,7 @@ impl ToString for OrderByExpr {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Fetch {
pub with_ties: bool,
pub percent: bool,
Expand All @@ -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>>);

impl ToString for Values {
Expand Down
4 changes: 2 additions & 2 deletions src/ast/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use ordered_float::OrderedFloat;

/// Primitive SQL values such as number and string
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Value {
/// Unsigned integer value
Long(u64),
Expand Down Expand Up @@ -113,7 +113,7 @@ impl ToString for Value {
}
}

#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DateTimeField {
Year,
Month,
Expand Down