我正在使用Apache Calcite从Excel中读取数据。Excel具有带有以下字段的“薪金”表
整数编号
整数emp_id
整数工资
我有以下model.json
{
"version": "1.0",
"defaultSchema": "excelSchema",
"schemas": [{
"name" : "excelSchema",
"type": "custom",
"factory": "com.syncnicia.testbais.excel.ExcelSchemaFactory",
"operand": {
"directory": "sheets/"
}
}]
}
这是我的方解石连接代码
Connection connection = DriverManager.getConnection("jdbc:calcite:model=src/main/resources/model.json");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
我可以使用以下代码从上述连接中获取数据。
Statement st1 = calciteConnection.createStatement();
ResultSet resultSet = st1.executeQuery("select * from \"excelSchema\".\"salary\"");
System.out.println("SALARY DATA IS");
while (resultSet.next()){
System.out.println("SALARY data is : ");
for (int i2 = 1; i2 <= resultSet.getMetaData().getColumnCount(); i2++) {
System.out.print(resultSet.getMetaData().getColumnLabel(i2)+" = "+resultSet.getObject(i2)+", ");
}
}
上面的代码工作正常,它显示了薪水表中的所有条目,但是当我尝试使用以下代码插入同一张表即excel中时
String insertSql = "INSERT INTO \"excelSchema\".\"salary\" values(5,345,0909944)";
Statement insertSt = calciteConnection.createStatement();
boolean insertResult = insertSt.execute(insertSql);
System.out.println("InsertResult is "+insertResult);
我正在关注异常
Exception in execute qry Error while executing SQL "INSERT INTO "employeeSchema"."salary" values(5,345,0909944)": 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#302:Subset#1.ENUMERABLE.[], the relevant part of the original plan is as follows
299:LogicalTableModify(table=[[employeeSchema, salary]], operation=[INSERT], flattened=[false])
293:LogicalValues(subset=[rel#298:Subset#0.NONE.[]], tuples=[[{ 5, 345, 909944 }]])
Root: rel#302:Subset#1.ENUMERABLE.[]
Original rel:
LogicalTableModify(table=[[employeeSchema, salary]], operation=[INSERT], flattened=[false]): rowcount = 1.0, cumulative cost = {2.0 rows, 1.0 cpu, 0.0 io}, id = 296
LogicalValues(tuples=[[{ 5, 345, 909944 }]]): rowcount = 1.0, cumulative cost = {1.0 rows, 1.0 cpu, 0.0 io}, id = 293
Sets:
Set#0, type: RecordType(INTEGER id, INTEGER emp_id, INTEGER salary)
rel#298:Subset#0.NONE.[], best=null, importance=0.81
rel#293:LogicalValues.NONE.[[0, 1, 2], [1, 2], [2]](type=RecordType(INTEGER id, INTEGER emp_id, INTEGER salary),tuples=[{ 5, 345, 909944 }]), rowcount=1.0, cumulative cost={inf}
rel#305:Subset#0.ENUMERABLE.[], best=rel#304, importance=0.405
rel#304:EnumerableValues.ENUMERABLE.[[0, 1, 2], [1, 2], [2]](type=RecordType(INTEGER id, INTEGER emp_id, INTEGER salary),tuples=[{ 5, 345, 909944 }]), rowcount=1.0, cumulative cost={1.0 rows, 1.0 cpu, 0.0 io}
Set#1, type: RecordType(BIGINT ROWCOUNT)
rel#300:Subset#1.NONE.[], best=null, importance=0.9
rel#299:LogicalTableModify.NONE.[](input=RelSubset#298,table=[employeeSchema, salary],operation=INSERT,flattened=false), rowcount=1.0, cumulative cost={inf}
rel#302:Subset#1.ENUMERABLE.[], best=null, importance=1.0
rel#303:AbstractConverter.ENUMERABLE.[](input=RelSubset#300,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, INTEGER emp_id, INTEGER salary)";
rel293 [label="rel#293:LogicalValues.NONE.[[0, 1, 2], [1, 2], [2]]\ntype=RecordType(INTEGER id, INTEGER emp_id, INTEGER salary),tuples=[{ 5, 345, 909944 }]\nrows=1.0, cost={inf}",shape=box]
rel304 [label="rel#304:EnumerableValues.ENUMERABLE.[[0, 1, 2], [1, 2], [2]]\ntype=RecordType(INTEGER id, INTEGER emp_id, INTEGER salary),tuples=[{ 5, 345, 909944 }]\nrows=1.0, cost={1.0 rows, 1.0 cpu, 0.0 io}",color=blue,shape=box]
subset298 [label="rel#298:Subset#0.NONE.[]"]
subset305 [label="rel#305:Subset#0.ENUMERABLE.[]"]
}
subgraph cluster1{
label="Set 1 RecordType(BIGINT ROWCOUNT)";
rel299 [label="rel#299:LogicalTableModify\ninput=RelSubset#298,table=[employeeSchema, salary],operation=INSERT,flattened=false\nrows=1.0, cost={inf}",shape=box]
rel303 [label="rel#303:AbstractConverter\ninput=RelSubset#300,convention=ENUMERABLE,sort=[]\nrows=1.0, cost={inf}",shape=box]
subset300 [label="rel#300:Subset#1.NONE.[]"]
subset302 [label="rel#302:Subset#1.ENUMERABLE.[]",color=red]
}
root -> subset302;
subset298 -> rel293;
subset305 -> rel304[color=blue];
subset300 -> rel299; rel299 -> subset298;
subset302 -> rel303; rel303 -> subset300;
} 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#302:Subset#1.ENUMERABLE.[], the relevant part of the original plan is as follows
299:LogicalTableModify(table=[[employeeSchema, salary]], operation=[INSERT], flattened=[false])
293:LogicalValues(subset=[rel#298:Subset#0.NONE.[]], tuples=[[{ 5, 345, 909944 }]])
Root: rel#302:Subset#1.ENUMERABLE.[]
Original rel:
LogicalTableModify(table=[[employeeSchema, salary]], operation=[INSERT], flattened=[false]): rowcount = 1.0, cumulative cost = {2.0 rows, 1.0 cpu, 0.0 io}, id = 296
LogicalValues(tuples=[[{ 5, 345, 909944 }]]): rowcount = 1.0, cumulative cost = {1.0 rows, 1.0 cpu, 0.0 io}, id = 293
Sets:
Set#0, type: RecordType(INTEGER id, INTEGER emp_id, INTEGER salary)
rel#298:Subset#0.NONE.[], best=null, importance=0.81
rel#293:LogicalValues.NONE.[[0, 1, 2], [1, 2], [2]](type=RecordType(INTEGER id, INTEGER emp_id, INTEGER salary),tuples=[{ 5, 345, 909944 }]), rowcount=1.0, cumulative cost={inf}
rel#305:Subset#0.ENUMERABLE.[], best=rel#304, importance=0.405
rel#304:EnumerableValues.ENUMERABLE.[[0, 1, 2], [1, 2], [2]](type=RecordType(INTEGER id, INTEGER emp_id, INTEGER salary),tuples=[{ 5, 345, 909944 }]), rowcount=1.0, cumulative cost={1.0 rows, 1.0 cpu, 0.0 io}
Set#1, type: RecordType(BIGINT ROWCOUNT)
rel#300:Subset#1.NONE.[], best=null, importance=0.9
rel#299:LogicalTableModify.NONE.[](input=RelSubset#298,table=[employeeSchema, salary],operation=INSERT,flattened=false), rowcount=1.0, cumulative cost={inf}
rel#302:Subset#1.ENUMERABLE.[], best=null, importance=1.0
rel#303:AbstractConverter.ENUMERABLE.[](input=RelSubset#300,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, INTEGER emp_id, INTEGER salary)";
rel293 [label="rel#293:LogicalValues.NONE.[[0, 1, 2], [1, 2], [2]]\ntype=RecordType(INTEGER id, INTEGER emp_id, INTEGER salary),tuples=[{ 5, 345, 909944 }]\nrows=1.0, cost={inf}",shape=box]
rel304 [label="rel#304:EnumerableValues.ENUMERABLE.[[0, 1, 2], [1, 2], [2]]\ntype=RecordType(INTEGER id, INTEGER emp_id, INTEGER salary),tuples=[{ 5, 345, 909944 }]\nrows=1.0, cost={1.0 rows, 1.0 cpu, 0.0 io}",color=blue,shape=box]
subset298 [label="rel#298:Subset#0.NONE.[]"]
subset305 [label="rel#305:Subset#0.ENUMERABLE.[]"]
}
subgraph cluster1{
label="Set 1 RecordType(BIGINT ROWCOUNT)";
rel299 [label="rel#299:LogicalTableModify\ninput=RelSubset#298,table=[employeeSchema, salary],operation=INSERT,flattened=false\nrows=1.0, cost={inf}",shape=box]
rel303 [label="rel#303:AbstractConverter\ninput=RelSubset#300,convention=ENUMERABLE,sort=[]\nrows=1.0, cost={inf}",shape=box]
subset300 [label="rel#300:Subset#1.NONE.[]"]
subset302 [label="rel#302:Subset#1.ENUMERABLE.[]",color=red]
}
root -> subset302;
subset298 -> rel293;
subset305 -> rel304[color=blue];
subset300 -> rel299; rel299 -> subset298;
subset302 -> rel303; rel303 -> subset300;
}
请帮助我如何使用Apache Calcite将数据插入excel。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。