[
https://issues.apache.org/jira/browse/CALCITE-3524?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17373109#comment-17373109
]
Julian Hyde commented on CALCITE-3524:
--------------------------------------
[~agajst], I see your point. In my example (the stack-based approach), it's
difficult to see the calls to {{scan}}, {{filter}} and {{project}} that become
the {{RelNode}}, and it's easy to miss the fact that {{inQuery}} pops off the
stack.
How about the following:
{code:java}
RelNode root = builder.scan("EMP")
.filter(
builder.in(builder.field("DEPTNO"),
b -> b.scan("DEPT")
.filter(
builder.call(SqlStdOperatorTable.EQUALS,
builder.field("DNAME"),
builder.literal("AAA")))
.project(builder.field("DEPTNO"))
.build()))
.build();
{code}
It is based on your example, but with 3 differences:
* In {{RexSubQuery.in}}, it was a mistake to put the {{RelNode}} parameter
before the {{Iterable<? extends RexNode>}} parameter. So let's fix that
mistake, and put the {{RelNode}} second.
* Changing the second parameter from {{RelNode}} to {{Function<RelBuilder,
RelNode>)}} makes it explicit when the {{RelNode}} is created. That becomes
important if your {{filter}} contains more than one {{IN}} or {{EXISTS}}.
* For brevity, let's have an overloaded variant (used here) where the first
argument is {{RexNode}}, not an iterable.
> Add methods to RelBuilder to create RexSubQuery
> -----------------------------------------------
>
> Key: CALCITE-3524
> URL: https://issues.apache.org/jira/browse/CALCITE-3524
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Amir Gajst
> Assignee: Julian Hyde
> Priority: Minor
> Labels: pull-request-available
> Fix For: 1.28.0
>
> Time Spent: 3.5h
> Remaining Estimate: 0h
>
> When building relational expressions, the simplest way is by using the
> RelBuilder which does not currently support creation of a RexSubQuery.
> We can add RexSubQuery creation functions to the RelBuilder to make it more
> "visible" and convenient to use.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)