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


##########
tests/sqlparser_snowflake.rs:
##########
@@ -2447,6 +2447,49 @@ fn test_copy_into_with_transformations() {
     snowflake().parse_sql_statements(sql1).unwrap();
 }
 
+#[test]
+fn test_copy_into_with_cast_transformation() {
+    // Snowflake `COPY INTO` transformation lists support casts like
+    // `$1:"col"::TYPE` and `$1::TYPE`. These are distinct from the bare
+    // `$<n>[.<col>][:<elem>]` stage-load-select-item shape, so the parser
+    // must fall through to the generic select-item parser to handle the
+    // `::` cast operator.
+    //
+    // Regression: the Snowflake-specific parser used to successfully
+    // consume `$1:"col"` as a stage-load-select-item, leaving `::TYPE`
+    // behind and causing "Expected: FROM, found: ::" once the COPY INTO
+    // body tried to expect `FROM`.

Review Comment:
   ```suggestion
   ```



##########
tests/sqlparser_snowflake.rs:
##########
@@ -2447,6 +2447,49 @@ fn test_copy_into_with_transformations() {
     snowflake().parse_sql_statements(sql1).unwrap();
 }
 
+#[test]
+fn test_copy_into_with_cast_transformation() {
+    // Snowflake `COPY INTO` transformation lists support casts like
+    // `$1:"col"::TYPE` and `$1::TYPE`. These are distinct from the bare
+    // `$<n>[.<col>][:<elem>]` stage-load-select-item shape, so the parser
+    // must fall through to the generic select-item parser to handle the
+    // `::` cast operator.
+    //
+    // Regression: the Snowflake-specific parser used to successfully
+    // consume `$1:"col"` as a stage-load-select-item, leaving `::TYPE`
+    // behind and causing "Expected: FROM, found: ::" once the COPY INTO
+    // body tried to expect `FROM`.
+    let variants = [
+        concat!(
+            "COPY INTO my_company.emp_basic (a) FROM ",
+            r#"(SELECT $1:"A"::NUMBER(38, 0) FROM @stg)"#,
+        ),
+        concat!(
+            "COPY INTO my_company.emp_basic (a) FROM ",
+            "(SELECT $1::NUMBER(38, 0) FROM @stg)",
+        ),
+        concat!(
+            "COPY INTO my_company.emp_basic (a) FROM ",
+            "(SELECT $1:SEQUENCE::NUMBER(38, 0) FROM @stg)",
+        ),
+        concat!(
+            "COPY INTO my_company.emp_basic (a, b) FROM ",
+            r#"(SELECT $1:"A"::VARIANT, $1:"B"::TEXT FROM @stg)"#,
+        ),
+        // Mix with an ordinary stage-load-select-item in the same list,
+        // so we don't over-correct and break the existing shape.

Review Comment:
   ```suggestion
   ```



##########
src/dialect/snowflake.rs:
##########
@@ -1545,6 +1545,14 @@ fn parse_select_item_for_data_load(
         }
     }
 
+    // A trailing `::` means this is a cast expression (e.g.
+    // `$1:"col"::NUMBER(38,0)`), not a stage-load-select-item. Bail so
+    // `maybe_parse` rewinds and the caller falls through to
+    // `parse_select_item`, which handles the cast correctly.

Review Comment:
   ```suggestion
       // `$1:"col"::NUMBER(38,0)`), not a stage-load-select-item.
   ```



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