nuno-faria commented on code in PR #27524:
URL: https://github.com/apache/datafusion/pull/27524#discussion_r4605060504


##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -374,9 +371,25 @@ pub enum DistinctFromStyle {
     Spaceship,
 }
 
+/// `ArrayTypeStyle` to use for unparsing Arrow list types
+#[derive(Clone, Copy, PartialEq, Debug)]
+pub enum ArrayTypeStyle {
+    /// `INT[]`, and `INT[3]` for a fixed-size list, as in PostgreSQL and 
DuckDB
+    SquareBracket,
+    /// `ARRAY<INT>`, as in BigQuery. A fixed-size list and a list of lists are
+    /// not supported.
+    AngleBracket,

Review Comment:
   I'm not sure it makes sense to reject the angle brackets for nested arrays, 
since DataFusion itself supports it:
   ```
   > select 1::array<array<int>>;
   +----------+
   | Int64(1) |
   +----------+
   | [[1]]    |
   +----------+
   ```



##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -1846,6 +1811,32 @@ impl Unparser<'_> {
         }))
     }
 
+    fn array_to_ast_dtype(
+        &self,
+        data_type: &DataType,
+        inner: &FieldRef,
+        size: Option<i32>,
+    ) -> Result<ast::DataType> {
+        let elem = Box::new(self.arrow_dtype_to_ast_dtype(inner)?);
+        let elem_def = match (self.dialect.array_type_style(), size) {
+            (ArrayTypeStyle::SquareBracket, size) => {
+                ast::ArrayElemTypeDef::SquareBracket(elem, size.map(|s| s as 
u64))
+            }
+            // BigQuery, the only dialect with this style, rejects an array of 
arrays.
+            (ArrayTypeStyle::AngleBracket, None)
+                if !matches!(*elem, ast::DataType::Array(_)) =>
+            {
+                ast::ArrayElemTypeDef::AngleBracket(elem)
+            }

Review Comment:
   Similar to the comment above, ideally this should not be defined by a 
specific dialect. Would it make sense to add a "supports nested arrays" method 
instead?



##########
datafusion/sql/src/unparser/expr.rs:
##########


Review Comment:
   Should we add these two as well?



-- 
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]

Reply via email to