iffyio commented on code in PR #2356:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2356#discussion_r3649666596
##########
src/ast/data_type.rs:
##########
@@ -1163,6 +1165,8 @@ pub enum ArrayElemTypeDef {
SquareBracket(Box<DataType>, Option<u64>),
/// Parenthesis style, e.g. `Array(Int64)`.
Parenthesis(Box<DataType>),
+ /// Keyword style with an optional size, e.g. `INT ARRAY` or `INT
ARRAY[4]`.
+ Keyword(Box<DataType>, Option<u64>),
Review Comment:
```suggestion
/// Qualified by a data type and optional size, e.g. `INT ARRAY` or `INT
ARRAY[4]`.
Qualified(Box<DataType>, Option<u64>),
```
##########
src/dialect/generic.rs:
##########
@@ -209,6 +209,10 @@ impl Dialect for GenericDialect {
true
}
+ fn supports_array_typedef_with_keyword(&self) -> bool {
Review Comment:
```suggestion
fn supports_type_qualified_array(&self) -> bool {
```
actually I wonder can we have the parser always accept the syntax (it doesnt
seem like it would be ambiguous)?
##########
src/parser/mod.rs:
##########
@@ -2904,15 +2903,19 @@ impl<'a> Parser<'a> {
self.expect_token(&Token::LParen)?;
let expr = self.parse_expr()?;
self.expect_keyword_is(Keyword::AS)?;
- let data_type = self.parse_data_type()?;
- let array = self.parse_keyword(Keyword::ARRAY);
+ let mut data_type = self.parse_data_type()?;
+ // A trailing `ARRAY` keyword makes the target an array type, e.g.
MySQL's
+ // `CAST(... AS UNSIGNED ARRAY)`. PostgreSQL already consumes it while
+ // parsing the data type, so the guard avoids wrapping it twice.
+ if !matches!(data_type, DataType::Array(_)) &&
self.parse_keyword(Keyword::ARRAY) {
+ data_type =
DataType::Array(ArrayElemTypeDef::Keyword(Box::new(data_type), None));
+ }
Review Comment:
not sure I follow the intent here, I imagined parse_data_type() already
should produce the new variant here, removing the need for any special handling?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]