iffyio commented on code in PR #2489:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2489#discussion_r3989261364


##########
src/dialect/mod.rs:
##########
@@ -1083,6 +1083,16 @@ pub trait Dialect: Debug + Any {
         false
     }
 
+    /// Returns true if this dialect supports structured `OBJECT` types.
+    ///
+    /// Example:
+    /// ```sql
+    /// CREATE TABLE t (o OBJECT(city VARCHAR, zip NUMBER NOT NULL));
+    /// ```
+    fn supports_structured_object_type(&self) -> bool {
+        false
+    }

Review Comment:
   I think we can remove the dialect method and have the parser always accept 
it if it shows up (note that we should ensure that a plain 'OBJECT' is still 
accepted as a datatype as today)



##########
tests/sqlparser_snowflake.rs:
##########
@@ -4912,3 +4912,38 @@ fn test_select_dollar_column_from_stage() {
     // With table function args, without alias
     snowflake().verified_stmt("SELECT $1, $2 FROM @mystage1(file_format => 
'myformat')");
 }
+#[test]
+fn test_structured_object_type() {
+    snowflake().verified_stmt(
+        "SELECT payload::OBJECT(address OBJECT(city VARCHAR NOT NULL), zip 
NUMBER) FROM t",
+    );
+
+    let select = snowflake().verified_only_select(
+        "SELECT CAST(payload AS OBJECT(city VARCHAR, zip NUMBER NOT NULL)) 
FROM t",
+    );
+    let Expr::Cast { data_type, .. } = 
expr_from_projection(only(&select.projection)) else {
+        unreachable!();
+    };
+    let DataType::Object(fields) = data_type else {
+        unreachable!();
+    };
+    assert_eq!(fields.len(), 2);
+    assert_eq!(fields[0].name, Ident::new("city"));
+    assert!(fields[0].options.is_empty());
+    assert_eq!(fields[1].name, Ident::new("zip"));
+    assert_eq!(fields[1].options.len(), 1);
+    assert_eq!(fields[1].options[0].option, ColumnOption::NotNull);
+
+    snowflake().verified_stmt("CREATE TABLE t (o OBJECT)");
+}
+
+#[test]
+fn test_structured_object_type_errors() {

Review Comment:
   ```suggestion
   
   ```
   we can merge both cases



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