ryanschneider commented on code in PR #1927:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1927#discussion_r2193394552


##########
tests/sqlparser_common.rs:
##########
@@ -15974,3 +15974,133 @@ fn parse_create_procedure_with_parameter_modes() {
         _ => unreachable!(),
     }
 }
+
+#[test]
+fn parse_not_null_unsupported() {
+    // Only DuckDB and SQLite support `x NOT NULL` as an expression
+    // All other dialects fail to parse.
+    let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOT NULL FROM t"#;
+    let dialects =
+        all_dialects_except(|d| 
d.supports_is_not_null_alias(IsNotNullAlias::NotSpaceNull));
+    let res = dialects.parse_sql_statements(sql);
+    assert_eq!(
+        ParserError::ParserError("Expected: end of statement, found: 
NULL".to_string()),
+        res.unwrap_err()
+    );
+}
+
+#[test]
+fn parse_not_null_supported() {
+    // DuckDB and SQLite support `x NOT NULL` as an alias for `x IS NOT NULL`
+    let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOT NULL FROM t"#;
+    let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x IS NOT NULL FROM 
t"#;
+    let dialects =
+        all_dialects_where(|d| 
d.supports_is_not_null_alias(IsNotNullAlias::NotSpaceNull));
+    let stmt = dialects.one_statement_parses_to(sql, canonical);
+    match stmt {
+        Statement::Query(qry) => match *qry.body {
+            SetExpr::Select(select) => {
+                assert_eq!(select.projection.len(), 1);
+                match select.projection.first().unwrap() {
+                    UnnamedExpr(expr) => {
+                        let fake_span = Span {
+                            start: Location { line: 0, column: 0 },
+                            end: Location { line: 0, column: 0 },
+                        };
+                        assert_eq!(
+                            *expr,
+                            Expr::IsNotNull(Box::new(Identifier(Ident {
+                                value: "x".to_string(),
+                                quote_style: None,
+                                span: fake_span,
+                            })),),
+                        );
+                    }
+                    _ => unreachable!(),
+                }
+            }
+            _ => unreachable!(),
+        },
+        _ => unreachable!(),
+    }
+}
+
+#[test]
+fn parse_notnull_unsupported() {
+    // Only Postgres, DuckDB, and SQLite support `x NOTNULL` as an expression
+    // All other dialects consider `x NOTNULL` like `x AS NOTNULL` and thus
+    // consider `NOTNULL` an alias for x.
+    let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOTNULL FROM t"#;
+    let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x AS NOTNULL FROM 
t"#;

Review Comment:
   Thanks!  I simplified the tests in 431fca3682cfc78ee61a2493f85f23, thanks 
for the pointers they are much more readable now!



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to