Hi everyone,

Thanks for your reply.


Following your advices, i tried to use server module to execute 
`insert/update/delete` on my custom tables, which can be considered as JAVA 
object, e.g, Map<String, Object>. The properties for 
DriverManager.getConnection() 
are same with:
```
CalciteAssert.propBuilder()
    .set(CalciteConnectionProperty.PARSER_FACTORY,
SqlDdlParserImpl.class.getName() + "#FACTORY")
    .set(CalciteConnectionProperty.MATERIALIZATIONS_ENABLED,
"true")
    .build());
```
But i got an exception shown below:


```
Caused by: org.apache.calcite.plan.RelOptPlanner$CannotPlanException: There are 
not enough rules to produce a node with desired properties: 
convention=ENUMERABLE, sort=[].
Missing conversion is LogicalTableModify[convention: NONE -> ENUMERABLE]
There is 1 empty subset: rel#9:Subset#1.ENUMERABLE.[], the relevant part of the 
original plan is as follows
6:LogicalTableModify(table=[[memory, test]], operation=[INSERT], 
flattened=[false])
  0:LogicalValues(subset=[rel#5:Subset#0.NONE.[]], tuples=[[{ 2, '1', '1' }]])


Root: rel#9:Subset#1.ENUMERABLE.[]
Original rel:
LogicalTableModify(table=[[memory, test]], operation=[INSERT], 
flattened=[false]): rowcount = 1.0, cumulative cost = {2.0 rows, 1.0 cpu, 0.0 
io}, id = 3
  LogicalValues(tuples=[[{ 2, '1', '1' }]]): rowcount = 1.0, cumulative cost = 
{1.0 rows, 1.0 cpu, 0.0 io}, id = 0


Sets:
Set#0, type: RecordType(INTEGER id, VARCHAR name, VARCHAR status)
rel#5:Subset#0.NONE.[], best=null, importance=0.81
rel#0:LogicalValues.NONE.[[0, 1, 2], [1, 2], [2]](type=RecordType(INTEGER id, 
VARCHAR name, VARCHAR status),tuples=[{ 2, '1', '1' }]), rowcount=1.0, 
cumulative cost={inf}
rel#12:Subset#0.ENUMERABLE.[], best=rel#11, importance=0.405
rel#11:EnumerableValues.ENUMERABLE.[[0, 1, 2], [1, 2], 
[2]](type=RecordType(INTEGER id, VARCHAR name, VARCHAR status),tuples=[{ 2, 
'1', '1' }]), rowcount=1.0, cumulative cost={1.0 rows, 1.0 cpu, 0.0 io}
Set#1, type: RecordType(BIGINT ROWCOUNT)
rel#7:Subset#1.NONE.[], best=null, importance=0.9
rel#6:LogicalTableModify.NONE.[](input=RelSubset#5,table=[memory, 
test],operation=INSERT,flattened=false), rowcount=1.0, cumulative cost={inf}
rel#9:Subset#1.ENUMERABLE.[], best=null, importance=1.0
rel#10:AbstractConverter.ENUMERABLE.[](input=RelSubset#7,convention=ENUMERABLE,sort=[]),
 rowcount=1.0, cumulative cost={inf}


Graphviz:
digraph G {
root [style=filled,label="Root"];
subgraph cluster0{
label="Set 0 RecordType(INTEGER id, VARCHAR name, VARCHAR status)";
rel0 [label="rel#0:LogicalValues.NONE.[[0, 1, 2], [1, 2], 
[2]]\ntype=RecordType(INTEGER id, VARCHAR name, VARCHAR status),tuples=[{ 2, 
'1', '1' }]\nrows=1.0, cost={inf}",shape=box]
rel11 [label="rel#11:EnumerableValues.ENUMERABLE.[[0, 1, 2], [1, 2], 
[2]]\ntype=RecordType(INTEGER id, VARCHAR name, VARCHAR status),tuples=[{ 2, 
'1', '1' }]\nrows=1.0, cost={1.0 rows, 1.0 cpu, 0.0 io}",color=blue,shape=box]
subset5 [label="rel#5:Subset#0.NONE.[]"]
subset12 [label="rel#12:Subset#0.ENUMERABLE.[]"]
}
subgraph cluster1{
label="Set 1 RecordType(BIGINT ROWCOUNT)";
rel6 [label="rel#6:LogicalTableModify\ninput=RelSubset#5,table=[memory, 
test],operation=INSERT,flattened=false\nrows=1.0, cost={inf}",shape=box]
rel10 
[label="rel#10:AbstractConverter\ninput=RelSubset#7,convention=ENUMERABLE,sort=[]\nrows=1.0,
 cost={inf}",shape=box]
subset7 [label="rel#7:Subset#1.NONE.[]"]
subset9 [label="rel#9:Subset#1.ENUMERABLE.[]",color=red]
}
root -> subset9;
subset5 -> rel0;
subset12 -> rel11[color=blue];
subset7 -> rel6; rel6 -> subset5;
subset9 -> rel10; rel10 -> subset7;
}
at 
org.apache.calcite.plan.volcano.RelSubset$CheapestPlanReplacer.visit(RelSubset.java:587)
at 
org.apache.calcite.plan.volcano.RelSubset.buildCheapestPlan(RelSubset.java:304)
at 
org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:647)
at org.apache.calcite.tools.Programs.lambda$standard$3(Programs.java:287)
at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:347)
at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:189)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:320)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:637)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:501)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:471)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 27 more


```


Otherwise, after reading doc again, `DDL extensions are only available in the 
calcite-server module. ` is expressed in doc. `update/insert/delete` are DML i 
think, is it necessary to use calcite server module for those DML?


Thanks for your help, and look forward to hearing from you. :)


Regards,
Trista






 Juan Pan


[email protected]
Juan Pan(Trista), Apache ShardingSphere


On 09/26/2019 05:54,Stamatis Zampetakis<[email protected]> wrote:
Hi Trista,

I think the server module is doing what you are asking for. Have a look in
ServerTest [1].
As Gelbana mentioned the implementation is based on implementations of the
ModifiableTable interface.

Best,
Stamatis

[1]
https://github.com/apache/calcite/blob/master/server/src/test/java/org/apache/calcite/test/ServerTest.java

On Wed, Sep 25, 2019 at 11:29 PM Mohamed Mohsen <[email protected]> wrote:

I haven't done that before but I would start investigating from this
interface [1]. Please share your experience if you get this done.

[1] org.apache.calcite.schema.ModifiableTable


On Wed, Sep 25, 2019 at 2:00 PM Juan Pan <[email protected]> wrote:

Hi everyone,


Thanks for your attention. I want to know the following description is
right or not?


"Modification has only been worked on for JDBC tables, not for any custom
tables currently.”


Query SQL on custom table is ok, so i am wondering whether i can execute
`update/insert/delete` SQL through Calcite on custom tables.


Can anyone give me some ideas?


Really thanks for your help.


Regards,
Trista






Juan Pan


[email protected]
Juan Pan(Trista), Apache ShardingSphere



Reply via email to