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


##########
src/ast/query.rs:
##########
@@ -3135,12 +3135,32 @@ pub struct Values {
     /// Was there an explicit ROWs keyword (MySQL)?
     /// <https://dev.mysql.com/doc/refman/8.0/en/values.html>
     pub explicit_row: bool,
+    // MySql supports both VALUES and VALUE keywords.
+    // <https://dev.mysql.com/doc/refman/9.2/en/insert.html>

Review Comment:
   Can we add this documentation to the `ValuesKeyword` enum? (its ok if we 
want to duplicate it here as well, primarily thinking the comment is most 
visible on the enum itself)
   
   Also note it should be a doc comment rather than a regular code comment



##########
tests/sqlparser_mysql.rs:
##########
@@ -4353,3 +4362,41 @@ fn test_create_index_options() {
         "CREATE INDEX idx_name ON t(c1, c2) USING BTREE LOCK = EXCLUSIVE 
ALGORITHM = DEFAULT",
     );
 }
+
+#[test]
+fn test_insert_into_value() {
+    let sql = r"INSERT INTO t (id, name) VALUE ('AAA', 'BBB')";
+    match mysql_and_generic().verified_stmt(sql) {
+        Statement::Insert(Insert { source, .. }) => {
+            assert_eq!(
+                Some(Box::new(Query {
+                    with: None,
+                    body: Box::new(SetExpr::Values(Values {
+                        keyword: ValuesKeyword::Value,
+                        explicit_row: false,
+                        rows: vec![vec![
+                            Expr::Value(ValueWithSpan {
+                                value: 
Value::SingleQuotedString("AAA".to_string()),
+                                span: Span::empty(),
+                            }),
+                            Expr::Value(ValueWithSpan {
+                                value: 
Value::SingleQuotedString("BBB".to_string()),
+                                span: Span::empty(),
+                            }),
+                        ]],
+                    })),
+                    order_by: None,
+                    limit_clause: None,
+                    fetch: None,
+                    locks: vec![],
+                    for_clause: None,
+                    settings: None,
+                    format_clause: None,
+                    pipe_operators: vec![],
+                })),
+                source
+            );
+        }
+        _ => unreachable!(),
+    }

Review Comment:
   Also instead of adding a oneoff test here, can we add a test case to the 
existing test function 
[here](https://github.com/SatoriCyber/datafusion-sqlparser-rs/blob/0ebcaae646d4f52c23462b9715fd92f9fd335b7b/tests/sqlparser_common.rs#L99)?



##########
src/ast/query.rs:
##########
@@ -3135,12 +3135,32 @@ pub struct Values {
     /// Was there an explicit ROWs keyword (MySQL)?
     /// <https://dev.mysql.com/doc/refman/8.0/en/values.html>
     pub explicit_row: bool,
+    // MySql supports both VALUES and VALUE keywords.
+    // <https://dev.mysql.com/doc/refman/9.2/en/insert.html>

Review Comment:
   Actually given that we only support two values here, it would probably be 
simpler with a bool.
   ```rust
   value_keyword: bool
   ```



##########
tests/sqlparser_mysql.rs:
##########
@@ -4353,3 +4362,41 @@ fn test_create_index_options() {
         "CREATE INDEX idx_name ON t(c1, c2) USING BTREE LOCK = EXCLUSIVE 
ALGORITHM = DEFAULT",
     );
 }
+
+#[test]
+fn test_insert_into_value() {
+    let sql = r"INSERT INTO t (id, name) VALUE ('AAA', 'BBB')";
+    match mysql_and_generic().verified_stmt(sql) {
+        Statement::Insert(Insert { source, .. }) => {
+            assert_eq!(
+                Some(Box::new(Query {
+                    with: None,
+                    body: Box::new(SetExpr::Values(Values {
+                        keyword: ValuesKeyword::Value,
+                        explicit_row: false,
+                        rows: vec![vec![
+                            Expr::Value(ValueWithSpan {
+                                value: 
Value::SingleQuotedString("AAA".to_string()),
+                                span: Span::empty(),
+                            }),
+                            Expr::Value(ValueWithSpan {
+                                value: 
Value::SingleQuotedString("BBB".to_string()),
+                                span: Span::empty(),
+                            }),
+                        ]],
+                    })),
+                    order_by: None,
+                    limit_clause: None,
+                    fetch: None,
+                    locks: vec![],
+                    for_clause: None,
+                    settings: None,
+                    format_clause: None,
+                    pipe_operators: vec![],
+                })),
+                source
+            );
+        }
+        _ => unreachable!(),
+    }

Review Comment:
   ```suggestion
       mysql_and_generic().verified_stmt(sql);
   ```
   I think this format should suffice since we cover the AST assertions in 
other tests



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