Calcite uses MutableRel (and a sub-class for each logical operator type) as a 
working representation when it is recognizing  “free form” materializations 
(i.e. materializations that do not belong to a lattice). It seems that we don’t 
have coverage of all of the operator types. Some folks recently contributed an 
implementation of MutableJoin; see 
https://issues.apache.org/jira/browse/CALCITE-758 and referenced email 
discussion.

It’s not a bug on your part; it’s an incomplete implementation on Calcite’s 
part.

I checked the code. MutableSort exists, but no code ever calls MutableSort.of 
to create one. It’s probably a two-line fix. Please log a jira case, and a fix 
or pull request would be appreciated.

Julian


On Jun 22, 2015, at 12:20 PM, Maryann Xue <[email protected]> wrote:

> Hi Julian,
> 
> I got materialized view working for Phoenix secondary index after the
> walk-around fix in MaterializationService. But when I was trying with an
> "order-by" case, I got the below "cannot translate into MutableRel"
> exception. I managed to make it work by adding the translation from Sort
> rel to MutableSort. So is this a bug and it shouldn't have gone though this
> code path? And I'd like to understand what translation to MutableRel does
> here.
> 
> java.lang.RuntimeException: java.sql.SQLException: error while executing
> SQL "explain plan for select a_string from aTable order by a_string":
> cannot translate
> rel#23:LogicalSort.NONE.[0](input=rel#21:LogicalProject.NONE.[](input=rel#0:PhoenixTableScan.PHOENIX_SERVER.[[0,
> 1]](table=[phoenix, ATABLE]),A_STRING=$2),sort0=$0,dir0=ASC) to MutableRel
> at
> org.apache.phoenix.calcite.CalciteTest$Sql.getResult(CalciteTest.java:120)
> at
> org.apache.phoenix.calcite.CalciteTest$Sql.explainIs(CalciteTest.java:102)
> at org.apache.phoenix.calcite.CalciteTest.testIndex(CalciteTest.java:888)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> 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:325)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> 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.run(ParentRunner.java:363)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
> Caused by: java.sql.SQLException: error while executing SQL "explain plan
> for select a_string from aTable order by a_string": cannot translate
> rel#23:LogicalSort.NONE.[0](input=rel#21:LogicalProject.NONE.[](input=rel#0:PhoenixTableScan.PHOENIX_SERVER.[[0,
> 1]](table=[phoenix, ATABLE]),A_STRING=$2),sort0=$0,dir0=ASC) to MutableRel
> at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
> at
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:112)
> at
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:130)
> at
> org.apache.phoenix.calcite.CalciteTest$Sql.getResult(CalciteTest.java:114)
> ... 29 more
> Caused by: java.lang.RuntimeException: cannot translate
> rel#23:LogicalSort.NONE.[0](input=rel#21:LogicalProject.NONE.[](input=rel#0:PhoenixTableScan.PHOENIX_SERVER.[[0,
> 1]](table=[phoenix, ATABLE]),A_STRING=$2),sort0=$0,dir0=ASC) to MutableRel
> at
> org.apache.calcite.plan.SubstitutionVisitor.toMutable(SubstitutionVisitor.java:244)
> at
> org.apache.calcite.plan.SubstitutionVisitor.<init>(SubstitutionVisitor.java:185)
> at
> org.apache.calcite.plan.volcano.VolcanoPlanner.substitute(VolcanoPlanner.java:410)
> at
> org.apache.calcite.plan.volcano.VolcanoPlanner.useMaterialization(VolcanoPlanner.java:368)
> at
> org.apache.calcite.plan.volcano.VolcanoPlanner.useApplicableMaterializations(VolcanoPlanner.java:458)
> at
> org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:739)
> at org.apache.calcite.tools.Programs$5.run(Programs.java:272)
> at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:320)
> at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:142)
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:274)
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:188)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:669)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:570)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:539)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:173)
> at
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:560)
> at
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:477)
> at
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:109)
> ... 31 more
> 
> 
> Thanks,
> Maryann

Reply via email to