Merge pull request #123 from benesch/eq

Implement Eq alongside Hash
This commit is contained in:
Nikhil Benesch 2019-06-25 17:45:12 -04:00 committed by GitHub
commit cdba43682f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 40 deletions

View file

@ -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>),

View file

@ -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),
@ -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 {
@ -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,
@ -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,
@ -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,

View file

@ -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),
@ -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>,
@ -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,
@ -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,
@ -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,
@ -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>),
@ -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 {
@ -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,
@ -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>,
@ -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,
@ -685,7 +685,7 @@ impl FromStr for FileFormat {
}
}
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ObjectType {
Table,
View,
@ -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,
@ -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),
@ -728,7 +728,7 @@ impl ToString for TransactionMode {
}
}
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TransactionAccessMode {
ReadOnly,
ReadWrite,
@ -744,7 +744,7 @@ impl ToString for TransactionAccessMode {
}
}
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TransactionIsolationLevel {
ReadUncommitted,
ReadCommitted,

View file

@ -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,
@ -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,

View file

@ -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>,
@ -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>),
@ -99,7 +99,7 @@ impl ToString for SetExpr {
}
}
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SetOperator {
Union,
Except,
@ -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
@ -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,
@ -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),
@ -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>,
@ -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,
@ -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>,
@ -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,
@ -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),
@ -365,7 +365,7 @@ pub enum JoinOperator {
OuterApply,
}
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum JoinConstraint {
On(Expr),
Using(Vec<Ident>),
@ -373,7 +373,7 @@ pub enum JoinConstraint {
}
/// 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>,
@ -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,
@ -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 {

View file

@ -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),
@ -113,7 +113,7 @@ impl ToString for Value {
}
}
#[derive(Debug, Clone, PartialEq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DateTimeField {
Year,
Month,