Thanks for your help. I will try to use the file adapter.
Do you mean that the design of calcite does not support doing data transfers
between different data sources?If so,I will try other ways.
Also, maybe I should provide you with more details to avoid throwing NPE as an
error message.
When I was debugging, I noticed that after volcano planner optimisation,
RelRoot changes to EnumerableTableModify.ENUMERABLE.[]. The dynamically
generated code for the bindable interface by calling implement() after that is
as follows.
```
......
final java.util.Collection collection =
((org.apache.calcite.schema.ModifiableTable)
root.getRootSchema().getSubSchema("
mysql").getTable("calcite_test")).getModifiableCollection();
final int _count = collection.size();
……
```
The first line calls JdbcTable#getModifiableCollection. then this method
returns null directly.
So in the second line, a NullPointerException is thrown.
I am a bit confused about the design reason why JdbcTable's
getModifiableCollection method returns null directly.
I hope this detail will help you. I can provide the full generated code if you
need it.
Best,
Morsy
On 2023/09/06 19:22:57 Julian Hyde wrote:
> It’s fair to say that if Calcite throws a NullPointerException then it’s a
> bug. (Except if it’s Calcite calling your code, or if you called an API with
> a null value for a not-null parameter.)
>
> In this case, you are calling the CSV adapter and asking it to modify a
> table, something it is not designed to do. Calcite ought to give you a better
> error message.
>
> Note that the CSV adapter is intended as an example, and therefore has
> limited functionality and even more limited error-checking. The file adapter
> has a superset of the functionality, and is intended for production use, so
> you should try that.
>
> Julian
>
>
> > On Sep 3, 2023, at 7:54 PM, Morsy <[email protected]> wrote:
> >
> > Hi,
> > I have put the
> >
> > org.apache.calcite.adapter.csv.CsvScannableTable
> >
> > and its related classes (Factory, Reader......, etc.) into my test project.
> > When I tried to execute a sql like
> >
> > insert into mysql.calcite_test (select * from csv)
> >
> > an NPE was thrown. where `mysql` is recognised by JdbcSchema#Factory. When
> > I debugged, I found that the bind method of the dynamically generated
> > Bindable code called the JdbcTable's getModifiableCollection() method,
> > which returned null directly. the bind method's subsequent call to
> > collection.size() threw an NPE. This code is generated by
> > EnumerableTableModify.class.
> > After that, I tried to execute
> >
> > insert into mysql.calcite(select * from mysql2.calcite2)
> >
> > There are two JdbcSchema#Factory recognised data sources here, but I found
> > that the code that was eventually generated by
> > JdbcToEnumerableConverter.class executed
> >
> > insert into calcite(select * from mysql2.calcite)
> >
> > in `mysql2` without performing the insert in the `mysql` library.
> > Are these issues intentional with calcite or are they bugs?
>
>