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


##########
tests/sqlparser_common.rs:
##########
@@ -11030,13 +11030,201 @@ fn parse_is_boolean() {
     let res = parse_sql_statements(sql);
     assert_eq!(
         ParserError::ParserError(
-            "Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [form] 
NORMALIZED FROM after IS, found: TRIM"
+            "Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [NOT] JSON 
[VALUE | SCALAR | ARRAY | OBJECT] [WITH | WITHOUT UNIQUE [KEYS]] | [form] 
NORMALIZED FROM after IS, found: TRIM"
                 .to_string()
         ),
         res.unwrap_err()
     );
 }
 
+#[test]
+fn parse_is_json_predicate() {
+    use self::Expr::*;
+
+    let sql = "a IS JSON";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: None,
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS NOT JSON";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: None,
+            unique_keys: None,
+            negated: true,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON VALUE";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Value),
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON SCALAR";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Scalar),
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON ARRAY";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Array),
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON OBJECT";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Object),
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON WITH UNIQUE KEYS";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: None,
+            unique_keys: Some(JsonKeyUniqueness::WithUniqueKeys),
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON WITHOUT UNIQUE KEYS";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: None,
+            unique_keys: Some(JsonKeyUniqueness::WithoutUniqueKeys),
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS NOT JSON OBJECT WITHOUT UNIQUE KEYS";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Object),
+            unique_keys: Some(JsonKeyUniqueness::WithoutUniqueKeys),
+            negated: true,
+        },
+        verified_expr(sql)
+    );
+
+    all_dialects().expr_parses_to("a IS JSON WITH UNIQUE", "a IS JSON WITH 
UNIQUE KEYS");
+    all_dialects().expr_parses_to("a IS JSON WITHOUT UNIQUE", "a IS JSON 
WITHOUT UNIQUE KEYS");
+
+    assert_matches!(
+        verified_expr("NOT a IS JSON"),
+        Expr::UnaryOp {
+            op: UnaryOperator::Not,
+            expr
+        } if matches!(&*expr, Expr::IsJson { .. })
+    );
+}
+
+#[test]
+fn parse_is_json_predicate_negative() {
+    let dialects = all_dialects();
+
+    let cases = [
+        (
+            "SELECT * FROM t WHERE a IS JSON WITH FROM",
+            &["Expected: UNIQUE", "found: FROM"][..],

Review Comment:
   can we drop the exact match on the error message (they tend to change as new 
features are added or code is refactored) and only assert that we get a parse 
failure?



##########
tests/sqlparser_common.rs:
##########
@@ -11030,13 +11030,201 @@ fn parse_is_boolean() {
     let res = parse_sql_statements(sql);
     assert_eq!(
         ParserError::ParserError(
-            "Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [form] 
NORMALIZED FROM after IS, found: TRIM"
+            "Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [NOT] JSON 
[VALUE | SCALAR | ARRAY | OBJECT] [WITH | WITHOUT UNIQUE [KEYS]] | [form] 
NORMALIZED FROM after IS, found: TRIM"
                 .to_string()
         ),
         res.unwrap_err()
     );
 }
 
+#[test]
+fn parse_is_json_predicate() {
+    use self::Expr::*;
+
+    let sql = "a IS JSON";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: None,
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS NOT JSON";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: None,
+            unique_keys: None,
+            negated: true,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON VALUE";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Value),
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON SCALAR";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Scalar),
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON ARRAY";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Array),
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON OBJECT";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Object),
+            unique_keys: None,
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON WITH UNIQUE KEYS";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: None,
+            unique_keys: Some(JsonKeyUniqueness::WithUniqueKeys),
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS JSON WITHOUT UNIQUE KEYS";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: None,
+            unique_keys: Some(JsonKeyUniqueness::WithoutUniqueKeys),
+            negated: false,
+        },
+        verified_expr(sql)
+    );
+
+    let sql = "a IS NOT JSON OBJECT WITHOUT UNIQUE KEYS";
+    assert_eq!(
+        IsJson {
+            expr: Box::new(Identifier(Ident::new("a"))),
+            kind: Some(JsonPredicateType::Object),
+            unique_keys: Some(JsonKeyUniqueness::WithoutUniqueKeys),
+            negated: true,
+        },
+        verified_expr(sql)
+    );
+
+    all_dialects().expr_parses_to("a IS JSON WITH UNIQUE", "a IS JSON WITH 
UNIQUE KEYS");
+    all_dialects().expr_parses_to("a IS JSON WITHOUT UNIQUE", "a IS JSON 
WITHOUT UNIQUE KEYS");
+
+    assert_matches!(
+        verified_expr("NOT a IS JSON"),
+        Expr::UnaryOp {
+            op: UnaryOperator::Not,
+            expr
+        } if matches!(&*expr, Expr::IsJson { .. })
+    );
+}
+
+#[test]
+fn parse_is_json_predicate_negative() {

Review Comment:
   ```suggestion
   fn parse_is_json_predicate_invalid() {
   ```



##########
tests/sqlparser_common.rs:
##########
@@ -11030,13 +11030,201 @@ fn parse_is_boolean() {
     let res = parse_sql_statements(sql);
     assert_eq!(
         ParserError::ParserError(
-            "Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [form] 
NORMALIZED FROM after IS, found: TRIM"
+            "Expected: [NOT] NULL | TRUE | FALSE | DISTINCT | [NOT] JSON 
[VALUE | SCALAR | ARRAY | OBJECT] [WITH | WITHOUT UNIQUE [KEYS]] | [form] 
NORMALIZED FROM after IS, found: TRIM"
                 .to_string()
         ),
         res.unwrap_err()
     );
 }
 
+#[test]
+fn parse_is_json_predicate() {
+    use self::Expr::*;
+
+    let sql = "a IS JSON";

Review Comment:
   can we simplify the tests a bit since the struct assertions have a lot of 
overlap we can have most of them only rely on the roundtrip `verified_expr` - I 
imagine it would suffice to only have one of the scenarios assert the returned 
struct
   



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