gianm commented on code in PR #5349:
URL: https://github.com/apache/calcite/pull/5349#discussion_r4408437366


##########
core/src/main/codegen/templates/Parser.jj:
##########
@@ -915,6 +923,138 @@ SqlNode LeafQuery(ExprContext exprContext) :
     e = TableConstructor() { return e; }
 |
     e = ExplicitTable(getPos()) { return e; }
+|
+    e = FromQuery() { return e; }
+}
+
+/**
+ * Parses a standalone FROM clause. Only valid under conformance levels
+ * that allow pipe syntax.
+ */
+SqlNode FromQuery() :
+{
+    final SqlNode fromClause;
+    final Span s;
+}
+{
+    <FROM> {
+        s = span();
+        if (!this.conformance.isPipeSyntaxAllowed()) {
+            throw SqlUtil.newContextException(getPos(),
+                RESOURCE.pipeSyntaxNotAllowed());
+        }
+    }
+    fromClause = FromClause()
+    // Report helpful error messages for common mistakes. (Generally, FROM
+    // must be followed by pipe operators.)
+    [
+        LOOKAHEAD(1)
+        (
+            <WHERE> {
+                throw SqlUtil.newContextException(getPos(),
+                    RESOURCE.pipeClauseNotAllowed("WHERE", "|> WHERE"));
+            }
+        |
+            <ORDER> {
+                throw SqlUtil.newContextException(getPos(),
+                    RESOURCE.fromQueryClauseNotAllowed("ORDER BY"));
+            }
+        |
+            <LIMIT> {
+                throw SqlUtil.newContextException(getPos(),
+                    RESOURCE.fromQueryClauseNotAllowed("LIMIT"));
+            }
+        |
+            <OFFSET> {
+                throw SqlUtil.newContextException(getPos(),
+                    RESOURCE.fromQueryClauseNotAllowed("OFFSET"));
+            }
+        |
+            <FETCH> {
+                throw SqlUtil.newContextException(getPos(),
+                    RESOURCE.fromQueryClauseNotAllowed("FETCH"));
+            }
+        |
+            ( <UNION> | <INTERSECT> | <EXCEPT> | <SET_MINUS> ) {
+                throw SqlUtil.newContextException(getPos(),
+                    RESOURCE.fromQueryInSetOpNotAllowed());
+            }
+        )
+    ]
+    { return new SqlFromQuery(s.end(this), fromClause); }
+}
+
+/**
+ * Reads optional pipe operators and applies them to the query {@code e}.
+ *
+ * <p>If {@code with}, {@code e} is a WITH, or an ORDER BY of a WITH, that is

Review Comment:
   Reworded it to try to be more clear:
   
   ```
   /**
    * Parses zero or more pipe operators that follow the query {@code e}.
    *
    * <p>The flag {@code with} signifies whether {@code e} is a WITH that is not
    * in parentheses, or an ORDER BY of such a WITH. If so, the operators are
    * applied to the body of the WITH, so that they can reference its CTEs.
    */
   ```



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

Reply via email to