[
https://issues.apache.org/jira/browse/CALCITE-4327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17212046#comment-17212046
]
Vladimir Sitnikov commented on CALCITE-4327:
--------------------------------------------
{quote} I think we should replace the NullPointerException, when someone calls
RelBuilder.scan(String...) from within a RelOptCall with a better
exception{quote}
Well, a better exception is better, however, it won't solve my need :)
I need to create a scan.
{quote}The problem you highlight - having the wrong kind of RelBuilder for the
task at hand - doesn't occur very often.{quote}
There are 37 usages of RelBuilderFactory#create (29 main code, 9 test code),
out of which 26 main code uses explicitly pass {{null}} schema, and 7 uses in
test code pass {{null}} as well. It sounds weird that most of the uses pass
null.
Should we make the field mutable?
Then it could be adjusted before calling {{scan}} in the rule code.
At the same time, we could remove {{RelOptSchema}} parameter from
{{RelBuilderFactory#create}}
> 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)