moshap-firebolt commented on code in PR #2614:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2614#discussion_r4317996799


##########
tests/sqlparser_common.rs:
##########
@@ -6764,9 +6766,87 @@ fn parse_interval_require_unit() {
     )
 }
 
+#[test]
+fn parse_interval_string_without_qualifier() {
+    let dialects = all_dialects_where(|d| 
d.supports_interval_string_without_qualifier());
+    for sql in [
+        "SELECT INTERVAL '2 months'",
+        "SELECT INTERVAL '1' DAY",
+        "SELECT INTERVAL '1-2' YEAR TO MONTH",
+        "SELECT INTERVAL -'1' DAY",
+        "SELECT INTERVAL 3 DAY",
+        "SELECT INTERVAL -1 DAY, INTERVAL +2 HOURS",
+        "SELECT INTERVAL '2 seconds' * 2",
+        "SELECT INTERVAL \"2 months\"",
+        "SELECT INTERVAL \"1\" DAY",
+    ] {
+        dialects.verified_stmt(sql);
+    }
+    for sql in [
+        "SELECT INTERVAL 1",
+        "SELECT INTERVAL 1 + 1 DAY",
+        "SELECT INTERVAL x DAY",
+    ] {
+        assert!(
+            dialects.parse_sql_statements(sql).is_err(),
+            "{sql} should not parse"
+        );
+    }
+    dialects.verified_stmt("SELECT interval, x FROM t");
+    dialects.verified_stmt("SELECT max(interval) FROM t WHERE interval > 1");
+    dialects.verified_stmt("SELECT interval - 1, interval + 1 FROM t");
+    dialects.one_statement_parses_to("SELECT INTERVAL -1", "SELECT INTERVAL - 
1");
+    dialects.one_statement_parses_to(
+        "SELECT INTERVAL -'2 months'",
+        "SELECT INTERVAL - '2 months'",
+    );
+    dialects.verified_stmt(
+        "SELECT sum(a) OVER (ORDER BY ts RANGE BETWEEN '1 day' PRECEDING AND 
CURRENT ROW) FROM t",
+    );
+    assert_eq!(
+        dialects
+            .parse_sql_statements("SELECT INTERVAL '1' DAY TO")
+            .unwrap_err()
+            .to_string(),
+        "sql parser error: Expected: date/time field, found: EOF"

Review Comment:
   Thanks, done. Since this is third time you point out these issues, I had my 
agent generate comprehensive check against Spark 4.1 - it is not part of the 
PR, but the stats are:
   
   >  - All statements in the tests of both PRs (42): each now gets the same 
result as in Spark: accepted or rejected, and read as an interval or as a 
column.
     - About 4,800 generated statements: INTERVAL / interval with 18 kinds of 
value (signed and unsigned numbers, single- and double-quoted strings, columns, 
parentheses), 9 kinds of unit, and 20 kinds of following token (alias, TO, 
arithmetic, extra unit pairs, ::, FROM, …). They
       also ran inside 12 surrounding contexts: function arguments, WHERE, 
ORDER BY, GROUP BY, window frames, lambdas, VALUES, LIMIT, and others.
       - Spark errors raised after its grammar accepted the statement, such as 
"The value of from-to unit must be a string", count as accepted.
       - Nothing Spark accepts and main parsed is now rejected.
       - No statement changed between an interval and a column reading.
       - 1,198 statements changed from disagreeing with Spark to agreeing.
     - Newly accepted though Spark rejects them: INTERVAL '1' TO HOUR, which 
Generic and PostgreSQL also accept on main, and a string alias after a value 
(INTERVAL '1' '2', like SELECT 1 '2'). Both come from the shared parser, so I 
left them alone.
     - Gaps that predate this PR, left for follow-ups:
       - A trailing TO used as an alias, your case. main rejects it in every 
dialect.
       - Spark joins neighbouring string literals ('1' '2' is '12'), and the 
Spark tokenizer doesn't.
   



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