This is a copy of the equivalent implementation in sqlparser.
(
&mut self,
)
| 930 | |
| 931 | // This is a copy of the equivalent implementation in sqlparser. |
| 932 | fn parse_columns( |
| 933 | &mut self, |
| 934 | ) -> Result<(Vec<ColumnDef>, Vec<TableConstraint>), DataFusionError> { |
| 935 | let mut columns = vec![]; |
| 936 | let mut constraints = vec![]; |
| 937 | if !self.parser.consume_token(&Token::LParen) |
| 938 | || self.parser.consume_token(&Token::RParen) |
| 939 | { |
| 940 | return Ok((columns, constraints)); |
| 941 | } |
| 942 | |
| 943 | loop { |
| 944 | if let Some(constraint) = self.parser.parse_optional_table_constraint()? { |
| 945 | constraints.push(constraint); |
| 946 | } else if let Token::Word(_) = self.parser.peek_token().token { |
| 947 | let column_def = self.parse_column_def()?; |
| 948 | columns.push(column_def); |
| 949 | } else { |
| 950 | return self.expected( |
| 951 | "column name or constraint definition", |
| 952 | &self.parser.peek_token(), |
| 953 | ); |
| 954 | } |
| 955 | let comma = self.parser.consume_token(&Token::Comma); |
| 956 | if self.parser.consume_token(&Token::RParen) { |
| 957 | // allow a trailing comma, even though it's not in standard |
| 958 | break; |
| 959 | } else if !comma { |
| 960 | return self.expected( |
| 961 | "',' or ')' after column definition", |
| 962 | &self.parser.peek_token(), |
| 963 | ); |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | Ok((columns, constraints)) |
| 968 | } |
| 969 | |
| 970 | fn parse_column_def(&mut self) -> Result<ColumnDef, DataFusionError> { |
| 971 | let name = self.parser.parse_identifier()?; |
no test coverage detected