yoavcloud commented on code in PR #1467: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1467#discussion_r1798077237
########## src/parser/mod.rs: ########## @@ -11173,15 +11173,42 @@ impl<'a> Parser<'a> { self.peek_token().location ) } - expr => self - .parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS) - .map(|alias| match alias { - Some(alias) => SelectItem::ExprWithAlias { expr, alias }, - None => SelectItem::UnnamedExpr(expr), - }), + expr => { + if dialect_of!(self is MsSqlDialect) { + if let Some(select_item) = self.parse_mssql_alias_with_equal(&expr) { + return Ok(select_item); + } + } + self.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS) + .map(|alias| match alias { + Some(alias) => SelectItem::ExprWithAlias { expr, alias }, + None => SelectItem::UnnamedExpr(expr), + }) + } } } + /// Parse a [`SelectItem`] based on an MsSql syntax that uses the equal sign + /// to denote an alias, for example: SELECT col_alias = col FROM tbl + /// <https://learn.microsoft.com/en-us/sql/t-sql/queries/select-examples-transact-sql?view=sql-server-ver16#b-use-select-with-column-headings-and-calculations> + fn parse_mssql_alias_with_equal(&mut self, expr: &Expr) -> Option<SelectItem> { + if let Expr::BinaryOp { + left, op, right, .. + } = expr + { + if op == &BinaryOperator::Eq { + if let Expr::Identifier(ref alias) = **left { + return Some(SelectItem::ExprWithAlias { + expr: *right.clone(), + alias: alias.clone(), + }); + } + } + } + + None Review Comment: But this would make the function return two different types, as SelectItem is not an Expr variant, no? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org