[ 
https://issues.apache.org/jira/browse/CALCITE-4327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17212043#comment-17212043
 ] 

Julian Hyde commented on CALCITE-4327:
--------------------------------------

I think we should replace the {{NullPointerException}}, when someone calls 
{{RelBuilder.scan(String...)}} from within a {{RelOptCall}} with a better 
exception.

The fact is, {{RelBuilder}} serves two different purposes: translating a query 
language to initial RelNode tree, and transforming that RelNode tree by means 
of rules. The former purpose requires a namespace to look up tables. The second 
purpose doesn't. The problem you highlight - having the wrong kind of 
RelBuilder for the task at hand - doesn't occur very often.

Adding {{RelOptSchema}} as an argument would make {{RelBuilder}} a lot less 
useful for purpose 1. (Because people would need two objects instead of one.) 
Also, {{RelOptSchema}} is an old interface that I hope we will use less and 
less over time, and not something that most users should have to bother about.

I agree that {{PigRelBuilder}} is a bit of a mess. I don't know the solution, 
but it's an atypical use of {{RelBuilder}} so we shouldn't let it dominate the 
decision-making.

> RelBuilder#scan(...) should work when used in RelRule#onMatch as 
> call.builder()
> -------------------------------------------------------------------------------
>
>                 Key: CALCITE-4327
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4327
>             Project: Calcite
>          Issue Type: Sub-task
>          Components: core
>    Affects Versions: 1.26.0
>            Reporter: Vladimir Sitnikov
>            Priority: Major
>
> It turns out {{RelBuilder#relOptSchema}} is often null.
> For instance,
> {code:java}
> public abstract class RelOptRuleCall {
>   public RelBuilder builder() {
>     return rule.relBuilderFactory.create(rel(0).getCluster(), /* schema= */ 
> null);
>   }
> {code}
> It leads to NPE in user code.
> I suggest either populate {{relOptSchema}} with root schema by default or 
> remove the field to avoid confusion for those who would try {{scan(...)}} 
> method.
> It might make sense to add RelOptSchema parameter to 
> {{scan(Iterable<String>)}} method as well.
> Sample use case:
> {code:java}
>     @Override
>     public void onMatch(RelOptRuleCall call) {
>         List<String> indexName = ...;
>         RelBuilder relBuilder = call.builder()
>                 .scan(indexName);
> {code}
> {noformat}
> Caused by: java.lang.NullPointerException
>       at org.apache.calcite.tools.RelBuilder.scan(RelBuilder.java:1094)
>       at 
> com.github.vlsi.mat.calcite.schema.objects.InstanceAccessByClassIdRule.onMatch(InstanceAccessByClassIdRule.java:44)
>       at 
> org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:229)
>       ... 75 more
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to