Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HiranmayaGundu committed Apr 20, 2024
1 parent 5aa4d9a commit 053b251
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,12 @@ impl fmt::Display for WildcardAdditionalOptions {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct IlikeSelectItem {
pub pattern: Expr,
pub pattern: String,
}

impl fmt::Display for IlikeSelectItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ILIKE {}", self.pattern)?;
write!(f, "ILIKE '{}'", self.pattern)?;
Ok(())
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8818,10 +8818,8 @@ impl<'a> Parser<'a> {
&mut self,
) -> Result<Option<IlikeSelectItem>, ParserError> {
let opt_ilike = if self.parse_keyword(Keyword::ILIKE) {
let pattern = self.parse_value()?;
Some(IlikeSelectItem {
pattern: Expr::Value(pattern),
})
let pattern = self.parse_literal_string()?;
Some(IlikeSelectItem { pattern })
} else {
None
};
Expand Down
20 changes: 19 additions & 1 deletion tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,13 +1621,31 @@ fn test_select_wildcard_with_ilike() {
let select = snowflake_and_generic().verified_only_select(r#"SELECT * ILIKE '%id%' FROM tbl"#);
let expected = SelectItem::Wildcard(WildcardAdditionalOptions {
opt_ilike: Some(IlikeSelectItem {
pattern: Expr::Value(Value::SingleQuotedString("%id%".to_owned())),
pattern: "%id%".to_owned(),
}),
..Default::default()
});
assert_eq!(expected, select.projection[0]);
}

#[test]
fn test_select_wildcard_with_ilike_non_literal() {
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE %id FROM tbl"#);
assert_eq!(
res.unwrap_err().to_string(),
"sql parser error: Expected literal string, found: %"
);
}

#[test]
fn test_select_wildcard_with_ilike_number() {
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE 42 FROM tbl"#);
assert_eq!(
res.unwrap_err().to_string(),
"sql parser error: Expected literal string, found: 42"
);
}

#[test]
fn test_select_wildcard_with_ilike_replace() {
let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE '%id%' EXCLUDE col FROM tbl"#);
Expand Down

0 comments on commit 053b251

Please sign in to comment.