Skip to content

Commit 4b77bb9

Browse files
committed
ignore span in ValueWithSpan comparisons
fixes apache#1738 (comment)
1 parent c8246fb commit 4b77bb9

File tree

4 files changed

+239
-83
lines changed

4 files changed

+239
-83
lines changed

src/ast/spans.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@ use core::iter;
2121
use crate::tokenizer::Span;
2222

2323
use super::{
24-
dcl::SecondaryRoles, value::ValueWithSpan, AccessExpr, AlterColumnOperation, AlterIndexOperation, AlterTableOperation, Array, Assignment, AssignmentTarget, CloseCursor, ClusteredIndex, ColumnDef, ColumnOption, ColumnOptionDef, ConflictTarget, ConnectBy, ConstraintCharacteristics, CopySource, CreateIndex, CreateTable, CreateTableOptions, Cte, Delete, DoUpdate, ExceptSelectItem, ExcludeSelectItem, Expr, ExprWithAlias, Fetch, FromTable, Function, FunctionArg, FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList, FunctionArguments, GroupByExpr, HavingBound, IlikeSelectItem, Insert, Interpolate, InterpolateExpr, Join, JoinConstraint, JoinOperator, JsonPath, JsonPathElem, LateralView, MatchRecognizePattern, Measure, NamedWindowDefinition, ObjectName, ObjectNamePart, Offset, OnConflict, OnConflictAction, OnInsert, OrderBy, OrderByExpr, Partition, PivotValueSource, ProjectionSelect, Query, ReferentialAction, RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SqlOption, Statement, Subscript, SymbolDefinition, TableAlias, TableAliasColumnDef, TableConstraint, TableFactor, TableObject, TableOptionsClustered, TableWithJoins, UpdateTableFromKind, Use, Value, Values, ViewColumnDef, WildcardAdditionalOptions, With, WithFill
24+
dcl::SecondaryRoles, value::ValueWithSpan, AccessExpr, AlterColumnOperation,
25+
AlterIndexOperation, AlterTableOperation, Array, Assignment, AssignmentTarget, CloseCursor,
26+
ClusteredIndex, ColumnDef, ColumnOption, ColumnOptionDef, ConflictTarget, ConnectBy,
27+
ConstraintCharacteristics, CopySource, CreateIndex, CreateTable, CreateTableOptions, Cte,
28+
Delete, DoUpdate, ExceptSelectItem, ExcludeSelectItem, Expr, ExprWithAlias, Fetch, FromTable,
29+
Function, FunctionArg, FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList,
30+
FunctionArguments, GroupByExpr, HavingBound, IlikeSelectItem, Insert, Interpolate,
31+
InterpolateExpr, Join, JoinConstraint, JoinOperator, JsonPath, JsonPathElem, LateralView,
32+
MatchRecognizePattern, Measure, NamedWindowDefinition, ObjectName, ObjectNamePart, Offset,
33+
OnConflict, OnConflictAction, OnInsert, OrderBy, OrderByExpr, Partition, PivotValueSource,
34+
ProjectionSelect, Query, ReferentialAction, RenameSelectItem, ReplaceSelectElement,
35+
ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SqlOption, Statement, Subscript,
36+
SymbolDefinition, TableAlias, TableAliasColumnDef, TableConstraint, TableFactor, TableObject,
37+
TableOptionsClustered, TableWithJoins, UpdateTableFromKind, Use, Value, Values, ViewColumnDef,
38+
WildcardAdditionalOptions, With, WithFill,
2539
};
2640

2741
/// Given an iterator of spans, return the [Span::union] of all spans.
@@ -1960,7 +1974,6 @@ impl Spanned for TableAliasColumnDef {
19601974
}
19611975
}
19621976

1963-
19641977
impl Spanned for ValueWithSpan {
19651978
fn span(&self) -> Span {
19661979
self.span

src/ast/value.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,32 @@ use crate::{ast::Ident, tokenizer::Span};
3131
use sqlparser_derive::{Visit, VisitMut};
3232

3333
/// Primitive SQL values such as number and string
34-
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
34+
#[derive(Debug, Clone, Eq, Ord)]
3535
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3636
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3737
pub struct ValueWithSpan {
3838
pub value: Value,
3939
pub span: Span,
4040
}
4141

42+
impl PartialEq for ValueWithSpan {
43+
fn eq(&self, other: &Self) -> bool {
44+
self.value == other.value
45+
}
46+
}
47+
48+
impl PartialOrd for ValueWithSpan {
49+
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
50+
self.value.partial_cmp(&other.value)
51+
}
52+
}
53+
54+
impl core::hash::Hash for ValueWithSpan {
55+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
56+
self.value.hash(state);
57+
}
58+
}
59+
4260
impl From<ValueWithSpan> for Value {
4361
fn from(value: ValueWithSpan) -> Self {
4462
value.value

src/parser/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8628,9 +8628,15 @@ impl<'a> Parser<'a> {
86288628
Token::TripleDoubleQuotedRawStringLiteral(ref s) => {
86298629
ok_value(Value::TripleDoubleQuotedRawStringLiteral(s.clone()))
86308630
}
8631-
Token::NationalStringLiteral(ref s) => ok_value(Value::NationalStringLiteral(s.to_string())),
8632-
Token::EscapedStringLiteral(ref s) => ok_value(Value::EscapedStringLiteral(s.to_string())),
8633-
Token::UnicodeStringLiteral(ref s) => ok_value(Value::UnicodeStringLiteral(s.to_string())),
8631+
Token::NationalStringLiteral(ref s) => {
8632+
ok_value(Value::NationalStringLiteral(s.to_string()))
8633+
}
8634+
Token::EscapedStringLiteral(ref s) => {
8635+
ok_value(Value::EscapedStringLiteral(s.to_string()))
8636+
}
8637+
Token::UnicodeStringLiteral(ref s) => {
8638+
ok_value(Value::UnicodeStringLiteral(s.to_string()))
8639+
}
86348640
Token::HexStringLiteral(ref s) => ok_value(Value::HexStringLiteral(s.to_string())),
86358641
Token::Placeholder(ref s) => ok_value(Value::Placeholder(s.to_string())),
86368642
tok @ Token::Colon | tok @ Token::AtSign => {
@@ -8725,9 +8731,9 @@ impl<'a> Parser<'a> {
87258731
self.next_token();
87268732
Ok(Expr::Value(Value::DollarQuotedString(s).with_span(span)))
87278733
}
8728-
_ => Ok(Expr::Value(Value::SingleQuotedString(
8729-
self.parse_literal_string()?,
8730-
).with_span(span))),
8734+
_ => Ok(Expr::Value(
8735+
Value::SingleQuotedString(self.parse_literal_string()?).with_span(span),
8736+
)),
87318737
}
87328738
}
87338739

0 commit comments

Comments
 (0)