vlsi commented on code in PR #5428:
URL: https://github.com/apache/calcite/pull/5428#discussion_r4625949841
##########
piglet/src/main/java/org/apache/calcite/piglet/Handler.java:
##########
@@ -400,4 +400,16 @@ private ImmutableList<RexNode> toRex(Iterable<Ast.Node>
operands) {
private void register(String name) {
map.put(name, builder.peek());
}
+
+ /** Returns the relational expression registered under a given name.
+ *
+ * @throws IllegalArgumentException if no relational expression has that name
+ */
+ private RelNode get(String name) {
+ final RelNode relNode = map.get(name);
+ if (relNode == null) {
+ throw new IllegalArgumentException("unknown relation '" + name + "'");
Review Comment:
Piglet has no validation step before `Handler`: the parser builds the AST
and hands it straight to `Handler.handle`, and `Handler` is the only place that
resolves relation names. So a script with a typo such as `FILTER X BY DEPTNO`
reaches this code, and the error belongs to the user, not to an internal
invariant. That rules out `AssertionError`.
A separate validation pass would repeat the name tracking that `Handler.map`
already does. Unknown fields are reported the same way during building:
`RelBuilder.field` throws `IllegalArgumentException("field [X] not found; input
fields are: ...")`. I used `IllegalArgumentException` to match that, and to
match `toLiteral` in this class, which throws `IllegalArgumentException("not a
literal: " + node)`.
I also added the position of the reference to the message in a5c1c4c11a, so
it now reads `unknown relation 'X' at line 2, column 12`.
--
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]