Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support select Row() #3152

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e_test/batch/types/struct_ty.slt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ select Row('foo', 'bar', null);
(foo,bar,NULL)

query T
select Row(1,2+3,4*5+1);
select Row();
----
(1,5,21)
()

query T
select Row(null);
Expand Down
20 changes: 17 additions & 3 deletions src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,7 @@ impl Parser {
op: UnaryOperator::Not,
expr: Box::new(self.parse_subexpr(Self::UNARY_NOT_PREC)?),
}),
Keyword::ROW => Ok(Expr::Row(
self.parse_token_wrapped_exprs(&Token::LParen, &Token::RParen)?,
)),
Keyword::ROW => self.parse_row_expr(),
Keyword::ARRAY => Ok(Expr::Array(
self.parse_token_wrapped_exprs(&Token::LBracket, &Token::RBracket)?,
)),
Expand Down Expand Up @@ -2201,6 +2199,22 @@ impl Parser {
}
}

pub fn parse_row_expr(&mut self) -> Result<Expr, ParserError> {
if self.consume_token(&Token::LParen) {
if self.consume_token(&Token::RParen) {
Ok(Expr::Row(vec![]))
} else {
self.prev_token();
Ok(Expr::Row(self.parse_token_wrapped_exprs(
&Token::LParen,
&Token::RParen,
)?))
}
} else {
self.expected("(", self.peek_token())
}
}

/// Parse a comma-separated list from a wrapped expression
pub fn parse_token_wrapped_exprs(
&mut self,
Expand Down