Skip to content

Commit 31e1b80

Browse files
authored
Revert "Add support for IS [NOT] [form] NORMALIZED (apache#1655)"
This reverts commit 2741fd0.
1 parent 0ac1fa0 commit 31e1b80

File tree

8 files changed

+17
-185
lines changed

8 files changed

+17
-185
lines changed

src/ast/mod.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub use self::trigger::{
8383

8484
pub use self::value::{
8585
escape_double_quote_string, escape_quoted_string, DateTimeField, DollarQuotedString,
86-
NormalizationForm, TrimWhereField, Value,
86+
TrimWhereField, Value,
8787
};
8888

8989
use crate::ast::helpers::stmt_data_loading::{
@@ -653,12 +653,6 @@ pub enum Expr {
653653
IsDistinctFrom(Box<Expr>, Box<Expr>),
654654
/// `IS NOT DISTINCT FROM` operator
655655
IsNotDistinctFrom(Box<Expr>, Box<Expr>),
656-
/// `<expr> IS [ NOT ] [ form ] NORMALIZED`
657-
IsNormalized {
658-
expr: Box<Expr>,
659-
form: Option<NormalizationForm>,
660-
negated: bool,
661-
},
662656
/// `[ NOT ] IN (val1, val2, ...)`
663657
InList {
664658
expr: Box<Expr>,
@@ -1124,7 +1118,7 @@ impl fmt::Display for LambdaFunction {
11241118
/// `OneOrManyWithParens` implements `Deref<Target = [T]>` and `IntoIterator`,
11251119
/// so you can call slice methods on it and iterate over items
11261120
/// # Examples
1127-
/// Accessing as a slice:
1121+
/// Acessing as a slice:
11281122
/// ```
11291123
/// # use sqlparser::ast::OneOrManyWithParens;
11301124
/// let one = OneOrManyWithParens::One("a");
@@ -1425,24 +1419,6 @@ impl fmt::Display for Expr {
14251419
if *regexp { "REGEXP" } else { "RLIKE" },
14261420
pattern
14271421
),
1428-
Expr::IsNormalized {
1429-
expr,
1430-
form,
1431-
negated,
1432-
} => {
1433-
let not_ = if *negated { "NOT " } else { "" };
1434-
if form.is_none() {
1435-
write!(f, "{} IS {}NORMALIZED", expr, not_)
1436-
} else {
1437-
write!(
1438-
f,
1439-
"{} IS {}{} NORMALIZED",
1440-
expr,
1441-
not_,
1442-
form.as_ref().unwrap()
1443-
)
1444-
}
1445-
}
14461422
Expr::SimilarTo {
14471423
negated,
14481424
expr,
@@ -8003,7 +7979,7 @@ where
80037979
/// ```sql
80047980
/// EXPLAIN (ANALYZE, VERBOSE TRUE, FORMAT TEXT) SELECT * FROM my_table;
80057981
///
8006-
/// VACUUM (VERBOSE, ANALYZE ON, PARALLEL 10) my_table;
7982+
/// VACCUM (VERBOSE, ANALYZE ON, PARALLEL 10) my_table;
80077983
/// ```
80087984
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
80097985
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

src/ast/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,10 +2821,10 @@ impl fmt::Display for ValueTableMode {
28212821
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
28222822
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
28232823
pub enum UpdateTableFromKind {
2824-
/// Update Statement where the 'FROM' clause is before the 'SET' keyword (Supported by Snowflake)
2824+
/// Update Statment where the 'FROM' clause is before the 'SET' keyword (Supported by Snowflake)
28252825
/// For Example: `UPDATE FROM t1 SET t1.name='aaa'`
28262826
BeforeSet(TableWithJoins),
2827-
/// Update Statement where the 'FROM' clause is after the 'SET' keyword (Which is the standard way)
2827+
/// Update Statment where the 'FROM' clause is after the 'SET' keyword (Which is the standard way)
28282828
/// For Example: `UPDATE SET t1.name='aaa' FROM t1`
28292829
AfterSet(TableWithJoins),
28302830
}

src/ast/spans.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,12 +1352,6 @@ impl Spanned for Expr {
13521352
escape_char: _,
13531353
any: _,
13541354
} => expr.span().union(&pattern.span()),
1355-
Expr::RLike { .. } => Span::empty(),
1356-
Expr::IsNormalized {
1357-
expr,
1358-
form: _,
1359-
negated: _,
1360-
} => expr.span(),
13611355
Expr::SimilarTo {
13621356
negated: _,
13631357
expr,
@@ -1393,6 +1387,7 @@ impl Spanned for Expr {
13931387
Expr::Array(array) => array.span(),
13941388
Expr::MatchAgainst { .. } => Span::empty(),
13951389
Expr::JsonAccess { value, path } => value.span().union(&path.span()),
1390+
Expr::RLike { .. } => Span::empty(),
13961391
Expr::AnyOp {
13971392
left,
13981393
compare_op: _,

src/ast/value.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -270,35 +270,6 @@ impl fmt::Display for DateTimeField {
270270
}
271271
}
272272

273-
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
274-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
275-
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
276-
/// The Unicode Standard defines four normalization forms, which are intended to eliminate
277-
/// certain distinctions between visually or functionally identical characters.
278-
///
279-
/// See [Unicode Normalization Forms](https://unicode.org/reports/tr15/) for details.
280-
pub enum NormalizationForm {
281-
/// Canonical Decomposition, followed by Canonical Composition.
282-
NFC,
283-
/// Canonical Decomposition.
284-
NFD,
285-
/// Compatibility Decomposition, followed by Canonical Composition.
286-
NFKC,
287-
/// Compatibility Decomposition.
288-
NFKD,
289-
}
290-
291-
impl fmt::Display for NormalizationForm {
292-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
293-
match self {
294-
NormalizationForm::NFC => write!(f, "NFC"),
295-
NormalizationForm::NFD => write!(f, "NFD"),
296-
NormalizationForm::NFKC => write!(f, "NFKC"),
297-
NormalizationForm::NFKD => write!(f, "NFKD"),
298-
}
299-
}
300-
}
301-
302273
pub struct EscapeQuotedString<'a> {
303274
string: &'a str,
304275
quote: char,

src/keywords.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,6 @@ define_keywords!(
535535
NESTED,
536536
NEW,
537537
NEXT,
538-
NFC,
539-
NFD,
540-
NFKC,
541-
NFKD,
542538
NO,
543539
NOBYPASSRLS,
544540
NOCREATEDB,
@@ -549,7 +545,6 @@ define_keywords!(
549545
NOORDER,
550546
NOREPLICATION,
551547
NORMALIZE,
552-
NORMALIZED,
553548
NOSCAN,
554549
NOSUPERUSER,
555550
NOT,

src/parser/mod.rs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,11 +3184,9 @@ impl<'a> Parser<'a> {
31843184
{
31853185
let expr2 = self.parse_expr()?;
31863186
Ok(Expr::IsNotDistinctFrom(Box::new(expr), Box::new(expr2)))
3187-
} else if let Ok(is_normalized) = self.parse_unicode_is_normalized(expr) {
3188-
Ok(is_normalized)
31893187
} else {
31903188
self.expected(
3191-
"[NOT] NULL | TRUE | FALSE | DISTINCT | [form] NORMALIZED FROM after IS",
3189+
"[NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS",
31923190
self.peek_token(),
31933191
)
31943192
}
@@ -3853,7 +3851,7 @@ impl<'a> Parser<'a> {
38533851
/// If the current token is the `expected` keyword, consume the token.
38543852
/// Otherwise, return an error.
38553853
///
3856-
// todo deprecate in favor of expected_keyword_is
3854+
// todo deprecate infavor of expected_keyword_is
38573855
pub fn expect_keyword(&mut self, expected: Keyword) -> Result<TokenWithSpan, ParserError> {
38583856
if self.parse_keyword(expected) {
38593857
Ok(self.get_current_token().clone())
@@ -8455,33 +8453,6 @@ impl<'a> Parser<'a> {
84558453
}
84568454
}
84578455

8458-
/// Parse a literal unicode normalization clause
8459-
pub fn parse_unicode_is_normalized(&mut self, expr: Expr) -> Result<Expr, ParserError> {
8460-
let neg = self.parse_keyword(Keyword::NOT);
8461-
let normalized_form = self.maybe_parse(|parser| {
8462-
match parser.parse_one_of_keywords(&[
8463-
Keyword::NFC,
8464-
Keyword::NFD,
8465-
Keyword::NFKC,
8466-
Keyword::NFKD,
8467-
]) {
8468-
Some(Keyword::NFC) => Ok(NormalizationForm::NFC),
8469-
Some(Keyword::NFD) => Ok(NormalizationForm::NFD),
8470-
Some(Keyword::NFKC) => Ok(NormalizationForm::NFKC),
8471-
Some(Keyword::NFKD) => Ok(NormalizationForm::NFKD),
8472-
_ => parser.expected("unicode normalization form", parser.peek_token()),
8473-
}
8474-
})?;
8475-
if self.parse_keyword(Keyword::NORMALIZED) {
8476-
return Ok(Expr::IsNormalized {
8477-
expr: Box::new(expr),
8478-
form: normalized_form,
8479-
negated: neg,
8480-
});
8481-
}
8482-
self.expected("unicode normalization form", self.peek_token())
8483-
}
8484-
84858456
pub fn parse_enum_values(&mut self) -> Result<Vec<EnumMember>, ParserError> {
84868457
self.expect_token(&Token::LParen)?;
84878458
let values = self.parse_comma_separated(|parser| {
@@ -9008,7 +8979,7 @@ impl<'a> Parser<'a> {
90088979
}
90098980
}
90108981

9011-
/// Parse a table object for insertion
8982+
/// Parse a table object for insetion
90128983
/// e.g. `some_database.some_table` or `FUNCTION some_table_func(...)`
90138984
pub fn parse_table_object(&mut self) -> Result<TableObject, ParserError> {
90148985
if self.dialect.supports_insert_table_function() && self.parse_keyword(Keyword::FUNCTION) {
@@ -11916,7 +11887,7 @@ impl<'a> Parser<'a> {
1191611887
} else {
1191711888
let mut name = self.parse_grantee_name()?;
1191811889
if self.consume_token(&Token::Colon) {
11919-
// Redshift supports namespace prefix for external users and groups:
11890+
// Redshift supports namespace prefix for extenrnal users and groups:
1192011891
// <Namespace>:<GroupName> or <Namespace>:<UserName>
1192111892
// https://docs.aws.amazon.com/redshift/latest/mgmt/redshift-iam-access-control-native-idp.html
1192211893
let ident = self.parse_identifier()?;
@@ -12912,7 +12883,7 @@ impl<'a> Parser<'a> {
1291212883
Ok(WithFill { from, to, step })
1291312884
}
1291412885

12915-
// Parse a set of comma separated INTERPOLATE expressions (ClickHouse dialect)
12886+
// Parse a set of comma seperated INTERPOLATE expressions (ClickHouse dialect)
1291612887
// that follow the INTERPOLATE keyword in an ORDER BY clause with the WITH FILL modifier
1291712888
pub fn parse_interpolations(&mut self) -> Result<Option<Interpolate>, ParserError> {
1291812889
if !self.parse_keyword(Keyword::INTERPOLATE) {
@@ -14461,7 +14432,7 @@ mod tests {
1446114432
assert_eq!(
1446214433
ast,
1446314434
Err(ParserError::ParserError(
14464-
"Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [form] NORMALIZED FROM after IS, found: a at Line: 1, Column: 16"
14435+
"Expected: [NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS, found: a at Line: 1, Column: 16"
1446514436
.to_string()
1446614437
))
1446714438
);

tests/sqlparser_common.rs

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4600,7 +4600,7 @@ fn run_explain_analyze(
46004600
expected_verbose: bool,
46014601
expected_analyze: bool,
46024602
expected_format: Option<AnalyzeFormat>,
4603-
expected_options: Option<Vec<UtilityOption>>,
4603+
exepcted_options: Option<Vec<UtilityOption>>,
46044604
) {
46054605
match dialect.verified_stmt(query) {
46064606
Statement::Explain {
@@ -4616,7 +4616,7 @@ fn run_explain_analyze(
46164616
assert_eq!(verbose, expected_verbose);
46174617
assert_eq!(analyze, expected_analyze);
46184618
assert_eq!(format, expected_format);
4619-
assert_eq!(options, expected_options);
4619+
assert_eq!(options, exepcted_options);
46204620
assert!(!query_plan);
46214621
assert!(!estimate);
46224622
assert_eq!("SELECT sqrt(id) FROM foo", statement.to_string());
@@ -9317,46 +9317,6 @@ fn parse_is_boolean() {
93179317
verified_expr(sql)
93189318
);
93199319

9320-
let sql = "a IS NORMALIZED";
9321-
assert_eq!(
9322-
IsNormalized {
9323-
expr: Box::new(Identifier(Ident::new("a"))),
9324-
form: None,
9325-
negated: false,
9326-
},
9327-
verified_expr(sql)
9328-
);
9329-
9330-
let sql = "a IS NOT NORMALIZED";
9331-
assert_eq!(
9332-
IsNormalized {
9333-
expr: Box::new(Identifier(Ident::new("a"))),
9334-
form: None,
9335-
negated: true,
9336-
},
9337-
verified_expr(sql)
9338-
);
9339-
9340-
let sql = "a IS NFKC NORMALIZED";
9341-
assert_eq!(
9342-
IsNormalized {
9343-
expr: Box::new(Identifier(Ident::new("a"))),
9344-
form: Some(NormalizationForm::NFKC),
9345-
negated: false,
9346-
},
9347-
verified_expr(sql)
9348-
);
9349-
9350-
let sql = "a IS NOT NFKD NORMALIZED";
9351-
assert_eq!(
9352-
IsNormalized {
9353-
expr: Box::new(Identifier(Ident::new("a"))),
9354-
form: Some(NormalizationForm::NFKD),
9355-
negated: true,
9356-
},
9357-
verified_expr(sql)
9358-
);
9359-
93609320
let sql = "a IS UNKNOWN";
93619321
assert_eq!(
93629322
IsUnknown(Box::new(Identifier(Ident::new("a")))),
@@ -9375,50 +9335,14 @@ fn parse_is_boolean() {
93759335
verified_stmt("SELECT f FROM foo WHERE field IS FALSE");
93769336
verified_stmt("SELECT f FROM foo WHERE field IS NOT FALSE");
93779337

9378-
verified_stmt("SELECT f FROM foo WHERE field IS NORMALIZED");
9379-
verified_stmt("SELECT f FROM foo WHERE field IS NFC NORMALIZED");
9380-
verified_stmt("SELECT f FROM foo WHERE field IS NFD NORMALIZED");
9381-
verified_stmt("SELECT f FROM foo WHERE field IS NOT NORMALIZED");
9382-
verified_stmt("SELECT f FROM foo WHERE field IS NOT NFKC NORMALIZED");
9383-
93849338
verified_stmt("SELECT f FROM foo WHERE field IS UNKNOWN");
93859339
verified_stmt("SELECT f FROM foo WHERE field IS NOT UNKNOWN");
93869340

93879341
let sql = "SELECT f from foo where field is 0";
93889342
let res = parse_sql_statements(sql);
93899343
assert_eq!(
93909344
ParserError::ParserError(
9391-
"Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [form] NORMALIZED FROM after IS, found: 0"
9392-
.to_string()
9393-
),
9394-
res.unwrap_err()
9395-
);
9396-
9397-
let sql = "SELECT s, s IS XYZ NORMALIZED FROM foo";
9398-
let res = parse_sql_statements(sql);
9399-
assert_eq!(
9400-
ParserError::ParserError(
9401-
"Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [form] NORMALIZED FROM after IS, found: XYZ"
9402-
.to_string()
9403-
),
9404-
res.unwrap_err()
9405-
);
9406-
9407-
let sql = "SELECT s, s IS NFKC FROM foo";
9408-
let res = parse_sql_statements(sql);
9409-
assert_eq!(
9410-
ParserError::ParserError(
9411-
"Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [form] NORMALIZED FROM after IS, found: FROM"
9412-
.to_string()
9413-
),
9414-
res.unwrap_err()
9415-
);
9416-
9417-
let sql = "SELECT s, s IS TRIM(' NFKC ') FROM foo";
9418-
let res = parse_sql_statements(sql);
9419-
assert_eq!(
9420-
ParserError::ParserError(
9421-
"Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [form] NORMALIZED FROM after IS, found: TRIM"
9345+
"Expected: [NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS, found: 0"
94229346
.to_string()
94239347
),
94249348
res.unwrap_err()
@@ -13079,7 +13003,7 @@ fn test_trailing_commas_in_from() {
1307913003
let sql = "SELECT a FROM b, WHERE c = 1";
1308013004
let _ = dialects.parse_sql_statements(sql).unwrap();
1308113005

13082-
// nested
13006+
// nasted
1308313007
let sql = "SELECT 1, 2 FROM (SELECT * FROM t,),";
1308413008
let _ = dialects.parse_sql_statements(sql).unwrap();
1308513009

tests/sqlparser_mysql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,7 @@ fn parse_kill() {
25722572
}
25732573

25742574
#[test]
2575-
fn parse_table_column_option_on_update() {
2575+
fn parse_table_colum_option_on_update() {
25762576
let sql1 = "CREATE TABLE foo (`modification_time` DATETIME ON UPDATE CURRENT_TIMESTAMP())";
25772577
match mysql().verified_stmt(sql1) {
25782578
Statement::CreateTable(CreateTable { name, columns, .. }) => {

0 commit comments

Comments
 (0)