Support qualified column names in MATCH AGAINST clause (#1774)

This commit is contained in:
tomershaniii 2025-03-25 11:13:11 +02:00 committed by GitHub
parent 3a8a3bb7a5
commit 53aba68e2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 2 deletions

View file

@ -1027,7 +1027,7 @@ pub enum Expr {
/// [(1)]: https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html#function_match
MatchAgainst {
/// `(<col>, <col>, ...)`.
columns: Vec<Ident>,
columns: Vec<ObjectName>,
/// `<expr>`.
match_value: Value,
/// `<search modifier>`

View file

@ -2704,7 +2704,7 @@ impl<'a> Parser<'a> {
/// This method will raise an error if the column list is empty or with invalid identifiers,
/// the match expression is not a literal string, or if the search modifier is not valid.
pub fn parse_match_against(&mut self) -> Result<Expr, ParserError> {
let columns = self.parse_parenthesized_column_list(Mandatory, false)?;
let columns = self.parse_parenthesized_qualified_column_list(Mandatory, false)?;
self.expect_keyword_is(Keyword::AGAINST)?;

View file

@ -3454,3 +3454,32 @@ fn parse_cast_integers() {
.run_parser_method("CAST(foo AS UNSIGNED INTEGER(3))", |p| p.parse_expr())
.expect_err("CAST doesn't allow display width");
}
#[test]
fn parse_match_against_with_alias() {
let sql = "SELECT tbl.ProjectID FROM surveys.tbl1 AS tbl WHERE MATCH (tbl.ReferenceID) AGAINST ('AAA' IN BOOLEAN MODE)";
match mysql().verified_stmt(sql) {
Statement::Query(query) => match *query.body {
SetExpr::Select(select) => match select.selection {
Some(Expr::MatchAgainst {
columns,
match_value,
opt_search_modifier,
}) => {
assert_eq!(
columns,
vec![ObjectName::from(vec![
Ident::new("tbl"),
Ident::new("ReferenceID")
])]
);
assert_eq!(match_value, Value::SingleQuotedString("AAA".to_owned()));
assert_eq!(opt_search_modifier, Some(SearchModifier::InBooleanMode));
}
_ => unreachable!(),
},
_ => unreachable!(),
},
_ => unreachable!(),
}
}