LucaCappelletti94 commented on code in PR #3088:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/3088#discussion_r4766926165


##########
src/dialect/generic.rs:
##########
@@ -233,6 +235,11 @@ impl Dialect for GenericDialect {
         true
     }
 
+    /// The generic dialect reserves no keyword as a table name.
+    fn is_table_factor(&self, _kw: &Keyword, _parser: &mut Parser) -> bool {
+        true
+    }

Review Comment:
   `GenericDialect::is_table_factor` returning `true` for every keyword also 
unreserves `ON`, which #2633 reserved on purpose, and I thought I had added red 
tests for it but I must have been mistaken. Please do check well whether other 
such keywords should be included in the method.
   
   ```suggestion
       /// The generic dialect reserves only `ON` as a table name.
       fn is_table_factor(&self, kw: &Keyword, _parser: &mut Parser) -> bool {
           *kw != Keyword::ON
       }
   ```



##########
tests/sqlparser_common.rs:
##########
@@ -17810,13 +17814,59 @@ fn parse_select_without_projection() {
         ParserError::ParserError("Expected: an expression, found: 
EOF".to_string())
     );
 
-    let dialects = all_dialects_where(|d| !d.supports_empty_projections());
+    let dialects = all_dialects_where(|d| {
+        !d.supports_empty_projections() || 
!d.supports_empty_projections_without_from()
+    });
     assert_eq!(
         dialects.parse_sql_statements("SELECT").unwrap_err(),
         ParserError::ParserError("Expected: an expression, found: 
EOF".to_string())
     );
 }
 
+#[test]
+fn parse_generic_clause_keyword_as_first_select_item() {
+    let generic = TestedDialects::new(vec![Box::new(GenericDialect {})]);
+    for keyword in [
+        "into",
+        "where",
+        "group",
+        "having",
+        "window",
+        "order",
+        "limit",
+        "offset",
+        "fetch",
+        "for",
+        "union",
+        "intersect",
+        "except",
+    ] {
+        for sql in [
+            format!("SELECT {keyword} FROM t"),
+            format!("SELECT {keyword}, a FROM t"),
+            format!("SELECT {keyword} + 1 FROM t"),
+            format!("SELECT DISTINCT {keyword} FROM t"),
+        ] {
+            let select = generic.verified_only_select(&sql);
+            assert!(!select.projection.is_empty(), "{sql}");
+            assert_eq!(select.from.len(), 1, "{sql}");
+        }
+    }
+}
+
+#[test]
+fn parse_generic_reserved_keyword_as_table_name() {
+    let generic = TestedDialects::new(vec![Box::new(GenericDialect {})]);
+    for keyword in ["into", "limit", "having", "where", "on"] {

Review Comment:
   ```suggestion
       for keyword in ["into", "limit", "having", "where"] {
   ```



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