From 4402ed6047ce6877d4c483aa03d0a6156bc671b6 Mon Sep 17 00:00:00 2001 From: cykbls01 <2541601705@qq.com> Date: Sun, 12 Jun 2022 23:05:14 -0400 Subject: [PATCH] fix --- e2e_test/batch/types/struct_ty.slt | 4 ++-- src/sqlparser/src/parser.rs | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/e2e_test/batch/types/struct_ty.slt b/e2e_test/batch/types/struct_ty.slt index 280200c63767d..fdbaac82d9459 100644 --- a/e2e_test/batch/types/struct_ty.slt +++ b/e2e_test/batch/types/struct_ty.slt @@ -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); diff --git a/src/sqlparser/src/parser.rs b/src/sqlparser/src/parser.rs index 0bbada7b86260..ffbf063c32007 100644 --- a/src/sqlparser/src/parser.rs +++ b/src/sqlparser/src/parser.rs @@ -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)?, )), @@ -2201,6 +2199,22 @@ impl Parser { } } + pub fn parse_row_expr(&mut self) -> Result { + 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,