Skip to content

Commit d304c23

Browse files
committed
Revert "feat: implement wildcard select ilike (apache#22)"
This reverts commit 9889b24, reversing changes made to 16cdc92.
1 parent 9889b24 commit d304c23

File tree

6 files changed

+3
-97
lines changed

6 files changed

+3
-97
lines changed

src/ast/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub use self::ddl::{
4040
pub use self::operator::{BinaryOperator, UnaryOperator};
4141
pub use self::query::{
4242
ConnectBy, Cte, CteAsMaterialized, Distinct, ExceptSelectItem, ExcludeSelectItem, Fetch,
43-
ForClause, ForJson, ForXml, GroupByExpr, IdentWithAlias, IlikeSelectItem, Join, JoinConstraint,
44-
JoinOperator, JsonTableColumn, JsonTableColumnErrorHandling, LateralView, LockClause, LockType,
43+
ForClause, ForJson, ForXml, GroupByExpr, IdentWithAlias, Join, JoinConstraint, JoinOperator,
44+
JsonTableColumn, JsonTableColumnErrorHandling, LateralView, LockClause, LockType,
4545
NamedWindowDefinition, NonBlock, Offset, OffsetRows, OrderByExpr, Query, RenameSelectItem,
4646
ReplaceSelectElement, ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SetOperator,
4747
SetQuantifier, Table, TableAlias, TableFactor, TableVersion, TableWithJoins, Top, TopQuantity,

src/ast/query.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,6 @@ impl fmt::Display for IdentWithAlias {
477477
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
478478
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
479479
pub struct WildcardAdditionalOptions {
480-
/// `[ILIKE...]`.
481-
/// Snowflake syntax: <https://docs.snowflake.com/en/sql-reference/sql/select>
482-
pub opt_ilike: Option<IlikeSelectItem>,
483480
/// `[EXCLUDE...]`.
484481
pub opt_exclude: Option<ExcludeSelectItem>,
485482
/// `[EXCEPT...]`.
@@ -495,9 +492,6 @@ pub struct WildcardAdditionalOptions {
495492

496493
impl fmt::Display for WildcardAdditionalOptions {
497494
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
498-
if let Some(ilike) = &self.opt_ilike {
499-
write!(f, " {ilike}")?;
500-
}
501495
if let Some(exclude) = &self.opt_exclude {
502496
write!(f, " {exclude}")?;
503497
}
@@ -514,29 +508,6 @@ impl fmt::Display for WildcardAdditionalOptions {
514508
}
515509
}
516510

517-
/// Snowflake `ILIKE` information.
518-
///
519-
/// # Syntax
520-
/// ```plaintext
521-
/// ILIKE <value>
522-
/// ```
523-
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
524-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
525-
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
526-
pub struct IlikeSelectItem {
527-
pub pattern: String,
528-
}
529-
530-
impl fmt::Display for IlikeSelectItem {
531-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
532-
write!(
533-
f,
534-
"ILIKE '{}'",
535-
value::escape_single_quote_string(&self.pattern)
536-
)?;
537-
Ok(())
538-
}
539-
}
540511
/// Snowflake `EXCLUDE` information.
541512
///
542513
/// # Syntax

src/parser/mod.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8775,13 +8775,7 @@ impl<'a> Parser<'a> {
87758775
pub fn parse_wildcard_additional_options(
87768776
&mut self,
87778777
) -> Result<WildcardAdditionalOptions, ParserError> {
8778-
let opt_ilike = if dialect_of!(self is GenericDialect | SnowflakeDialect) {
8779-
self.parse_optional_select_item_ilike()?
8780-
} else {
8781-
None
8782-
};
8783-
let opt_exclude = if opt_ilike.is_none()
8784-
&& dialect_of!(self is GenericDialect | DuckDbDialect | SnowflakeDialect)
8778+
let opt_exclude = if dialect_of!(self is GenericDialect | DuckDbDialect | SnowflakeDialect)
87858779
{
87868780
self.parse_optional_select_item_exclude()?
87878781
} else {
@@ -8807,30 +8801,13 @@ impl<'a> Parser<'a> {
88078801
};
88088802

88098803
Ok(WildcardAdditionalOptions {
8810-
opt_ilike,
88118804
opt_exclude,
88128805
opt_except,
88138806
opt_rename,
88148807
opt_replace,
88158808
})
88168809
}
88178810

8818-
pub fn parse_optional_select_item_ilike(
8819-
&mut self,
8820-
) -> Result<Option<IlikeSelectItem>, ParserError> {
8821-
let opt_ilike = if self.parse_keyword(Keyword::ILIKE) {
8822-
let next_token = self.next_token();
8823-
let pattern = match next_token.token {
8824-
Token::SingleQuotedString(s) => s,
8825-
_ => return self.expected("ilike pattern", next_token),
8826-
};
8827-
Some(IlikeSelectItem { pattern })
8828-
} else {
8829-
None
8830-
};
8831-
Ok(opt_ilike)
8832-
}
8833-
88348811
/// Parse an [`Exclude`](ExcludeSelectItem) information for wildcard select items.
88358812
///
88368813
/// If it is not possible to parse it, will return an option.

tests/sqlparser_common.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6560,7 +6560,6 @@ fn lateral_function() {
65606560
distinct: None,
65616561
top: None,
65626562
projection: vec![SelectItem::Wildcard(WildcardAdditionalOptions {
6563-
opt_ilike: None,
65646563
opt_exclude: None,
65656564
opt_except: None,
65666565
opt_rename: None,

tests/sqlparser_duckdb.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ fn test_select_union_by_name() {
148148
distinct: None,
149149
top: None,
150150
projection: vec![SelectItem::Wildcard(WildcardAdditionalOptions {
151-
opt_ilike: None,
152151
opt_exclude: None,
153152
opt_except: None,
154153
opt_rename: None,
@@ -184,7 +183,6 @@ fn test_select_union_by_name() {
184183
distinct: None,
185184
top: None,
186185
projection: vec![SelectItem::Wildcard(WildcardAdditionalOptions {
187-
opt_ilike: None,
188186
opt_exclude: None,
189187
opt_except: None,
190188
opt_rename: None,

tests/sqlparser_snowflake.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,42 +1615,3 @@ fn test_select_wildcard_with_replace() {
16151615
});
16161616
assert_eq!(expected, select.projection[0]);
16171617
}
1618-
1619-
#[test]
1620-
fn test_select_wildcard_with_ilike() {
1621-
let select = snowflake_and_generic().verified_only_select(r#"SELECT * ILIKE '%id%' FROM tbl"#);
1622-
let expected = SelectItem::Wildcard(WildcardAdditionalOptions {
1623-
opt_ilike: Some(IlikeSelectItem {
1624-
pattern: "%id%".to_owned(),
1625-
}),
1626-
..Default::default()
1627-
});
1628-
assert_eq!(expected, select.projection[0]);
1629-
}
1630-
1631-
#[test]
1632-
fn test_select_wildcard_with_ilike_double_quote() {
1633-
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE "%id" FROM tbl"#);
1634-
assert_eq!(
1635-
res.unwrap_err().to_string(),
1636-
"sql parser error: Expected ilike pattern, found: \"%id\""
1637-
);
1638-
}
1639-
1640-
#[test]
1641-
fn test_select_wildcard_with_ilike_number() {
1642-
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE 42 FROM tbl"#);
1643-
assert_eq!(
1644-
res.unwrap_err().to_string(),
1645-
"sql parser error: Expected ilike pattern, found: 42"
1646-
);
1647-
}
1648-
1649-
#[test]
1650-
fn test_select_wildcard_with_ilike_replace() {
1651-
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE '%id%' EXCLUDE col FROM tbl"#);
1652-
assert_eq!(
1653-
res.unwrap_err().to_string(),
1654-
"sql parser error: Expected end of statement, found: EXCLUDE"
1655-
);
1656-
}

0 commit comments

Comments
 (0)