[ 
https://issues.apache.org/jira/browse/CALCITE-1525?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15719031#comment-15719031
 ] 

Gian Merlino commented on CALCITE-1525:
---------------------------------------

A couple of differences I noticed:

1) The Planner interface doesn't seem to have a way to support ?-style bind 
variables in prepared statements, but CalcitePrepareImpl/JDBC does.
2) PlannerImpl isn't able to validate "EXPLAIN PLAN FOR" queries, I get an 
exception like the one below on calling validate. It looks like 
CalcitePrepareImpl has some special code to handle EXPLAIN queries but 
PlannerImpl doesn't.

{code}
org.apache.calcite.tools.ValidationException: java.lang.NullPointerException
  at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:187)
  at 
io.druid.sql.calcite.table.DruidTableTest.testQuery(DruidTableTest.java:2387)
  at 
io.druid.sql.calcite.table.DruidTableTest.testQuery(DruidTableTest.java:2371)
  at 
io.druid.sql.calcite.table.DruidTableTest.testSelectSingleColumnWithLimitDescending(DruidTableTest.java:550)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
  at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
  at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
  at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
  at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
  at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
  at 
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
  at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.NullPointerException
  at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:898)
  at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:879)
  at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:208)
  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:232)
  at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:406)
  at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4255)
  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
  at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:854)
  at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:565)
  at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:185)
  ... 32 more
{code}

> Use "Planner" to handle query preparation process in CalcitePrepareImpl
> -----------------------------------------------------------------------
>
>                 Key: CALCITE-1525
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1525
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Assignee: Julian Hyde
>
> The query preparation process (parse, validate, convert SqlNode to RelNode, 
> plan) is complicated, and each step depends on state on the previous one. We 
> have two ways of managing that preparation process: 
> [CalcitePrepareImpl|https://calcite.apache.org/apidocs/org/apache/calcite/prepare/CalcitePrepareImpl.html]
>  (used by the JDBC driver) and 
> [org.apache.calcite.tools.Planner|https://calcite.apache.org/apidocs/org/apache/calcite/tools/Planner.html]
>  (your only practical option if your code doesn't live inside JDBC).
> We should make {{CalcitePrepareImpl}} use a {{Planner}} internally, get rid 
> of shared logic, and make them behave consistently.
> From [email 
> thread|https://mail-archives.apache.org/mod_mbox/calcite-dev/201611.mbox/%3C9499388B-64A4-4BB0-9957-7FABC913AA48%40apache.org%3E]
>  with [~gian]:
> {quote}
> Compare and contrast:
>  * 
> [CalcitePrepareImpl.getSqlToRelConverter|https://github.com/apache/calcite/blob/3f92157d5742dd10f3b828d22d7a753e0a2899cc/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java#L1114]
>  * 
> [PlannerImpl.rel|https://github.com/apache/calcite/blob/105bba1f83cd9631e8e1211d262e4886a4a863b7/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java#L225]
> {quote}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to