You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Stamatis Zampetakis <za...@gmail.com> on 2019/03/05 08:13:47 UTC

Re: Error using prepared statement when connecting to druid

Hi Puneet,

It looks like a bug that is probably due to the use of parameters in the
query. I suspect that if you use the following statement

PreparedStatement st = connection.prepareStatement("SELECT __time, host
FROM canarytest WHERE (host = 'i-01e588977b1b23b88')");

it may work even if it is a prepared statement.

For this particular case, I think the error you get is possibly related
with DruidFilterRule that may not be able to transform the LogicalFilter
into a DruidQuery.

Please, log a JIRA issue and we can continue the discussion there.

Best,
Stamatis

Στις Δευ, 25 Φεβ 2019 στις 8:50 μ.μ., ο/η Puneet Jaiswal <pu...@gmail.com>
έγραψε:

> Hi,
> I am using avatica 1.13.0 to connect to druid 1.12.0. I get this error when
> using Prepared Statement to run a query. It works fine when I use Statement
> instead of Prepared Statements.
> Please take a look and suggest how to fix this?
>
> Test code
>
> String sql = "SELECT __time, host FROM canarytest WHERE (host = ?)";
> PreparedStatement st = connection.prepareStatement(sql);
> st.setString(1, "i-01e588977b1b23b88");
> data = st.executeQuery();
> while (data.next()) {
>   System.out.println(data.getInt("__time") + " " + data.getString("host"));
> }
>
> *Exception:*
> Exception in thread "main" org.apache.calcite.avatica.AvaticaSqlException:
> Error -1 (00000) : while preparing SQL: SELECT __time, host FROM canarytest
> WHERE (host = ?)
> at org.apache.calcite.avatica.Helper.createException(Helper.java:54)
> at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
> at
>
> org.apache.calcite.avatica.AvaticaConnection.prepareStatement(AvaticaConnection.java:358)
> at
>
> org.apache.calcite.avatica.AvaticaConnection.prepareStatement(AvaticaConnection.java:175)
> at DruidTest.main(DruidTest.java:70)
> org.apache.calcite.plan.RelOptPlanner$CannotPlanException: Node
> [rel#1412768:Subset#2.DRUID.[]] could not be implemented; planner state:
>
> Root: rel#1412768:Subset#2.DRUID.[]
> Original rel:
> LogicalFilter(subset=[rel#1412768:Subset#2.DRUID.[]], condition=[=($1,
> ?0)]): rowcount = 15.0, cumulative cost = {15.0 rows, 100.0 cpu, 0.0 io},
> id = 1412766
>   LogicalProject(subset=[rel#1412765:Subset#1.NONE.[]], __time=[$0],
> host=[$2]): rowcount = 100.0, cumulative cost = {100.0 rows, 200.0 cpu, 0.0
> io}, id = 1412764
>     LogicalTableScan(subset=[rel#1412763:Subset#0.NONE.[]], table=[[druid,
> canarytest]]): rowcount = 100.0, cumulative cost = {100.0 rows, 101.0 cpu,
> 0.0 io}, id = 1412753
>
> Sets:
> Set#0, type: RecordType(TIMESTAMP(3) __time, BIGINT count, VARCHAR host)
> rel#1412763:Subset#0.NONE.[], best=null, importance=0.7290000000000001
> rel#1412753:LogicalTableScan.NONE.[](table=[druid, canarytest]),
> rowcount=100.0, cumulative cost={inf}
>
> rel#1412777:DruidQueryRel.NONE.[](query={"queryType":"scan","dataSource":{"type":"table","name":"canarytest"},"intervals":{"type":"intervals","intervals":["-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"]},"virtualColumns":[],"resultFormat":"compactedList","batchSize":20480,"limit":9223372036854775807,"filter":null,"columns":["__time","count","host"],"legacy":false,"context":{},"descending":false,"granularity":{"type":"all"}},signature={__time:LONG,
> count:LONG, host:STRING}), rowcount=1.0, cumulative cost={inf}
> rel#1412781:Subset#0.DRUID.[], best=rel#1412780,
> importance=0.36450000000000005
>
> rel#1412780:DruidQueryRel.DRUID.[](query={"queryType":"scan","dataSource":{"type":"table","name":"canarytest"},"intervals":{"type":"intervals","intervals":["-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"]},"virtualColumns":[],"resultFormat":"compactedList","batchSize":20480,"limit":9223372036854775807,"filter":null,"columns":["__time","count","host"],"legacy":false,"context":{},"descending":false,"granularity":{"type":"all"}},signature={__time:LONG,
> count:LONG, host:STRING}), rowcount=1.0, cumulative cost={1.0 rows, 0.0
> cpu, 0.0 io}
> Set#1, type: RecordType(TIMESTAMP(3) __time, VARCHAR host)
> rel#1412765:Subset#1.NONE.[], best=null, importance=0.81
>
> rel#1412764:LogicalProject.NONE.[](input=rel#1412763:Subset#0.NONE.[],__time=$0,host=$2),
> rowcount=100.0, cumulative cost={inf}
>
> rel#1412779:DruidQueryRel.NONE.[](query={"queryType":"scan","dataSource":{"type":"table","name":"canarytest"},"intervals":{"type":"intervals","intervals":["-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"]},"virtualColumns":[],"resultFormat":"compactedList","batchSize":20480,"limit":9223372036854775807,"filter":null,"columns":["__time","host"],"legacy":false,"context":{},"descending":false,"granularity":{"type":"all"}},signature={__time:LONG,
> host:STRING}), rowcount=1.0, cumulative cost={inf}
> rel#1412784:Subset#1.DRUID.[], best=rel#1412783, importance=0.405
>
> rel#1412783:DruidQueryRel.DRUID.[](query={"queryType":"scan","dataSource":{"type":"table","name":"canarytest"},"intervals":{"type":"intervals","intervals":["-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"]},"virtualColumns":[],"resultFormat":"compactedList","batchSize":20480,"limit":9223372036854775807,"filter":null,"columns":["__time","host"],"legacy":false,"context":{},"descending":false,"granularity":{"type":"all"}},signature={__time:LONG,
> host:STRING}), rowcount=1.0, cumulative cost={1.002 rows, 0.0 cpu, 0.0 io}
> Set#2, type: RecordType(TIMESTAMP(3) __time, VARCHAR host)
> rel#1412767:Subset#2.NONE.[], best=null, importance=0.9
>
> rel#1412766:LogicalFilter.NONE.[](input=rel#1412765:Subset#1.NONE.[],condition==($1,
> ?0)), rowcount=15.0, cumulative cost={inf}
>
> rel#1412773:LogicalProject.NONE.[](input=rel#1412772:Subset#3.NONE.[],__time=$0,host=$2),
> rowcount=15.0, cumulative cost={inf}
> rel#1412768:Subset#2.DRUID.[], best=null, importance=1.0
>
> rel#1412769:AbstractConverter.DRUID.[](input=rel#1412767:Subset#2.NONE.[],convention=DRUID,sort=[]),
> rowcount=15.0, cumulative cost={inf}
> Set#3, type: RecordType(TIMESTAMP(3) __time, BIGINT count, VARCHAR host)
> rel#1412772:Subset#3.NONE.[], best=null, importance=0.81
>
> rel#1412770:LogicalFilter.NONE.[](input=rel#1412763:Subset#0.NONE.[],condition==($2,
> ?0)), rowcount=15.0, cumulative cost={inf}
>
>
> at
>
> org.apache.calcite.plan.volcano.RelSubset$CheapestPlanReplacer.visit(RelSubset.java:437)
> at
>
> org.apache.calcite.plan.volcano.RelSubset.buildCheapestPlan(RelSubset.java:296)
> at
>
> org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:662)
> at org.apache.calcite.tools.Programs$RuleSetProgram.run(Programs.java:339)
> at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:358)
> at org.apache.calcite.prepare.PlannerImpl.transform(PlannerImpl.java:337)
> at
>
> org.apache.druid.sql.calcite.planner.DruidPlanner.planWithDruidConvention(DruidPlanner.java:160)
> at
>
> org.apache.druid.sql.calcite.planner.DruidPlanner.plan(DruidPlanner.java:128)
> at
>
> org.apache.druid.sql.calcite.planner.DruidPlanner.plan(DruidPlanner.java:105)
> at
>
> org.apache.druid.sql.avatica.DruidStatement.prepare(DruidStatement.java:165)
> at org.apache.druid.sql.avatica.DruidMeta.prepare(DruidMeta.java:155)
> at
> org.apache.calcite.avatica.remote.LocalService.apply(LocalService.java:195)
> at
>
> org.apache.calcite.avatica.remote.Service$PrepareRequest.accept(Service.java:1216)
> at
>
> org.apache.calcite.avatica.remote.Service$PrepareRequest.accept(Service.java:1187)
> at
>
> org.apache.calcite.avatica.remote.AbstractHandler.apply(AbstractHandler.java:94)
> at org.apache.calcite.avatica.remote.JsonHandler.apply(JsonHandler.java:52)
> at
>
> org.apache.calcite.avatica.server.AvaticaJsonHandler.handle(AvaticaJsonHandler.java:130)
> at
>
> org.apache.druid.sql.avatica.DruidAvaticaHandler.handle(DruidAvaticaHandler.java:59)
> at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:61)
> at
>
> org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:169)
> at
>
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
> at org.eclipse.jetty.server.Server.handle(Server.java:531)
> at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
> at
> org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
> at
> org.eclipse.jetty.io
> .AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
> at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
> at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
> at
>
> org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
> at
>
> org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
> at
>
> org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
> at
>
> org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
> at
>
> org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
> at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
> at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
> at java.lang.Thread.run(Thread.java:748)
> Suppressed: org.apache.calcite.plan.RelOptPlanner$CannotPlanException: Node
> [rel#1412797:Subset#6.BINDABLE.[]] could not be implemented; planner state:
>
> Root: rel#1412797:Subset#6.BINDABLE.[]
> Original rel:
> LogicalFilter(subset=[rel#1412797:Subset#6.BINDABLE.[]], condition=[=($1,
> ?0)]): rowcount = 15.0, cumulative cost = {15.0 rows, 100.0 cpu, 0.0 io},
> id = 1412795
>   LogicalProject(subset=[rel#1412794:Subset#5.NONE.[]], __time=[$0],
> host=[$2]): rowcount = 100.0, cumulative cost = {100.0 rows, 200.0 cpu, 0.0
> io}, id = 1412793
>     LogicalTableScan(subset=[rel#1412792:Subset#4.NONE.[]], table=[[druid,
> canarytest]]): rowcount = 100.0, cumulative cost = {100.0 rows, 101.0 cpu,
> 0.0 io}, id = 1412753
>
> Sets:
> Set#4, type: RecordType(TIMESTAMP(3) __time, BIGINT count, VARCHAR host)
> rel#1412792:Subset#4.NONE.[], best=null, importance=0.7290000000000001
> rel#1412753:LogicalTableScan.NONE.[](table=[druid, canarytest]),
> rowcount=100.0, cumulative cost={inf}
>
> rel#1412813:DruidQueryRel.NONE.[](query={"queryType":"scan","dataSource":{"type":"table","name":"canarytest"},"intervals":{"type":"intervals","intervals":["-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"]},"virtualColumns":[],"resultFormat":"compactedList","batchSize":20480,"limit":9223372036854775807,"filter":null,"columns":["__time","count","host"],"legacy":false,"context":{},"descending":false,"granularity":{"type":"all"}},signature={__time:LONG,
> count:LONG, host:STRING}), rowcount=1.0, cumulative cost={inf}
> rel#1412827:Subset#4.BINDABLE.[], best=null, importance=0.81
>
> rel#1412826:InterpretableConverter.BINDABLE.[](input=rel#1412792:Subset#4.NONE.[]),
> rowcount=100.0, cumulative cost={inf}
> Set#5, type: RecordType(TIMESTAMP(3) __time, VARCHAR host)
> rel#1412794:Subset#5.NONE.[], best=null, importance=0.81
>
> rel#1412793:LogicalProject.NONE.[](input=rel#1412792:Subset#4.NONE.[],__time=$0,host=$2),
> rowcount=100.0, cumulative cost={inf}
>
> rel#1412814:DruidQueryRel.NONE.[](query={"queryType":"scan","dataSource":{"type":"table","name":"canarytest"},"intervals":{"type":"intervals","intervals":["-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"]},"virtualColumns":[],"resultFormat":"compactedList","batchSize":20480,"limit":9223372036854775807,"filter":null,"columns":["__time","host"],"legacy":false,"context":{},"descending":false,"granularity":{"type":"all"}},signature={__time:LONG,
> host:STRING}), rowcount=1.0, cumulative cost={inf}
> rel#1412817:Subset#5.BINDABLE.[], best=null, importance=0.9
>
> rel#1412821:InterpretableConverter.BINDABLE.[](input=rel#1412794:Subset#5.NONE.[]),
> rowcount=100.0, cumulative cost={inf}
>
> rel#1412830:BindableProject.BINDABLE.[](input=rel#1412827:Subset#4.BINDABLE.[],__time=$0,host=$2),
> rowcount=100.0, cumulative cost={inf}
> Set#6, type: RecordType(TIMESTAMP(3) __time, VARCHAR host)
> rel#1412796:Subset#6.NONE.[], best=null, importance=0.9
>
> rel#1412795:LogicalFilter.NONE.[](input=rel#1412794:Subset#5.NONE.[],condition==($1,
> ?0)), rowcount=15.0, cumulative cost={inf}
>
> rel#1412803:LogicalProject.NONE.[](input=rel#1412802:Subset#7.NONE.[],__time=$0,host=$2),
> rowcount=15.0, cumulative cost={inf}
> rel#1412797:Subset#6.BINDABLE.[], best=null, importance=1.0
>
> rel#1412798:AbstractConverter.BINDABLE.[](input=rel#1412796:Subset#6.NONE.[],convention=BINDABLE,sort=[]),
> rowcount=15.0, cumulative cost={inf}
>
> rel#1412799:InterpretableConverter.BINDABLE.[](input=rel#1412796:Subset#6.NONE.[]),
> rowcount=15.0, cumulative cost={inf}
>
> rel#1412812:BindableProject.BINDABLE.[](input=rel#1412811:Subset#7.BINDABLE.[],__time=$0,host=$2),
> rowcount=15.0, cumulative cost={inf}
>
> rel#1412818:BindableFilter.BINDABLE.[[]](input=rel#1412817:Subset#5.BINDABLE.[],condition==($1,
> ?0)), rowcount=15.0, cumulative cost={inf}
> Set#7, type: RecordType(TIMESTAMP(3) __time, BIGINT count, VARCHAR host)
> rel#1412802:Subset#7.NONE.[], best=null, importance=0.81
>
> rel#1412800:LogicalFilter.NONE.[](input=rel#1412792:Subset#4.NONE.[],condition==($2,
> ?0)), rowcount=15.0, cumulative cost={inf}
> rel#1412811:Subset#7.BINDABLE.[], best=null, importance=0.9
>
> rel#1412816:InterpretableConverter.BINDABLE.[](input=rel#1412802:Subset#7.NONE.[]),
> rowcount=15.0, cumulative cost={inf}
>
> rel#1412831:BindableFilter.BINDABLE.[[]](input=rel#1412827:Subset#4.BINDABLE.[],condition==($2,
> ?0)), rowcount=15.0, cumulative cost={inf}
>
>
> at
>
> org.apache.calcite.plan.volcano.RelSubset$CheapestPlanReplacer.visit(RelSubset.java:437)
> at
>
> org.apache.calcite.plan.volcano.RelSubset.buildCheapestPlan(RelSubset.java:296)
> at
>
> org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:662)
> at org.apache.calcite.tools.Programs$RuleSetProgram.run(Programs.java:339)
> at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:358)
> at org.apache.calcite.prepare.PlannerImpl.transform(PlannerImpl.java:337)
> at
>
> org.apache.druid.sql.calcite.planner.DruidPlanner.planWithBindableConvention(DruidPlanner.java:281)
> at
>
> org.apache.druid.sql.calcite.planner.DruidPlanner.plan(DruidPlanner.java:133)
> ... 27 more
>