I spent some time on the first issue above. The following test can
reproduce it.
// FrameworksTest.java
@Test public void testMinMax() throws Exception {
Table table = new TableImpl();
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
SchemaPlus schema = rootSchema.add("x", new AbstractSchema());
schema.add("MYTABLE", table);
List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelDistributionTraitDef.INSTANCE);
SqlParser.Config parserConfig =
SqlParser.configBuilder(SqlParser.Config.DEFAULT)
.setCaseSensitive(false)
.build();
final FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(parserConfig)
.defaultSchema(schema)
.traitDefs(traitDefs)
// define the rules you want to apply
.ruleSets(
RuleSets.ofList(AbstractConverter.ExpandConversionRule.INSTANCE,
ProjectTableScanRule.INSTANCE))
.programs(Programs.ofRules(Programs.RULE_SET))
.build();
executeQuery(config, " select min(id) as mi, max(id) as ma from mytable
where id=1 group by id",
CalciteSystemProperty.DEBUG.value());
}
I opened a jira(CALCITE-322
<https://issues.apache.org/jira/projects/CALCITE/issues/CALCITE-3228>8) for
this. Besides, I found CALCITE-896
<https://issues.apache.org/jira/browse/CALCITE-896> which improves
AggregateRemoveRule causes this.
Best,
Chunwei
On Sun, Aug 4, 2019 at 7:05 AM Amit Chavan <[email protected]> wrote:
> Yes the table in question does implement the following interfaces -
> private static class TableImpl extends AbstractTable
> implements ModifiableTable, ScannableTable,
> ProjectableFilterableTable
>
> I am putting together a project that has some unit tests that will show the
> errors.
>
>
> On Sat, Aug 3, 2019 at 7:05 AM Stamatis Zampetakis <[email protected]>
> wrote:
>
> > I tried to reproduce the first problem related with ProjectTableScanRule
> > with the current master but I didn't succeed. I assumed that the table in
> > question implements the FilterableTable or ProjectableFilterableTable
> > interface but I guess I am missing some other important parameters.
> >
> > On Fri, Aug 2, 2019 at 9:17 PM Julian Hyde <[email protected]> wrote:
> >
> > > Do you think you are running into
> > > https://issues.apache.org/jira/browse/CALCITE-3145 <
> > > https://issues.apache.org/jira/browse/CALCITE-3145>?
> > >
> > > > On Aug 2, 2019, at 2:00 AM, Chunwei Lei <[email protected]>
> > wrote:
> > > >
> > > > Hi, Amit. Thank you for reporting this.
> > > >
> > > > I suggest you opening a jira to track this. Besides, it would be
> great
> > if
> > > > you can provide more
> > > > details to reproduce these issues.
> > > >
> > > >
> > > >
> > > >
> > > > Best,
> > > > Chunwei
> > > >
> > > >
> > > > On Fri, Aug 2, 2019 at 10:22 AM Amit Chavan <[email protected]>
> > wrote:
> > > >
> > > >> Hello,
> > > >>
> > > >> I wanted to see if I can get some help on issues I have noticed with
> > > >> calcite 1.20 release. These issues do not happen in the previous
> > > releases
> > > >> of calcite. I have confirmed that.
> > > >>
> > > >> Query - "SELECT MIN(n1) as mi, MAX(n1) as ma FROM tblspace1.tsql
> > WHERE
> > > >> k1='no_results' GROUP BY k1"
> > > >>
> > > >> java.lang.RuntimeException: Error while applying rule
> > > >> ProjectScanRule:interpreter, args
> > > >>
> > >
> >
> [rel#264:EnumerableProject.ENUMERABLE.[](input=RelSubset#263,MI=$1,MA=$1),
> > > >> rel#317:EnumerableInterpreter.ENUMERABLE.[](input=RelSubset#291),
> > > >> rel#290:BindableTableScan.BINDABLE.[](table=[tblspace1,
> > > >> tsql],filters=[=($0, 'no_results')])]
> > > >>
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:235)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:631)
> > > >> at herddb.sql.CalcitePlanner.runPlanner(CalcitePlanner.java:527)
> > > >> at herddb.sql.CalcitePlanner.translate(CalcitePlanner.java:293)
> > > >> at herddb.core.TestUtils.scan(TestUtils.java:70)
> > > >> at herddb.core.RawSQLTest.simpleMinMaxTest(RawSQLTest.java:1389)
> > > >> 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:497)
> > > >> 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.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.runners.ParentRunner.run(ParentRunner.java:363)
> > > >> at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
> > > >> at
> > > >>
> > > >>
> > >
> >
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
> > > >> at
> > > >>
> > > >>
> > >
> >
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
> > > >> at
> > > >>
> > > >>
> > >
> >
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
> > > >> at
> > > >>
> > com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
> > > >> Caused by: java.lang.IllegalArgumentException: source #1 is already
> > > mapped
> > > >> to target #1
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.util.mapping.Mappings$SurjectionWithInverse.set(Mappings.java:1326)
> > > >> at org.apache.calcite.rel.core.Project.getMapping(Project.java:279)
> > > >> at org.apache.calcite.rel.core.Project.getMapping(Project.java:250)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.rel.rules.ProjectTableScanRule.apply(ProjectTableScanRule.java:107)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.rel.rules.ProjectTableScanRule$2.onMatch(ProjectTableScanRule.java:83)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:208)
> > > >> ... 27 more
> > > >>
> > > >> Query 2-
> > > >> "UPDATE tblspace1.table1 set n1=1000"
> > > >> + "WHERE k1 in (SELECT fk FROM tblspace1.table2
> > WHERE
> > > >> k2=?)"
> > > >>
> > > >> java.lang.UnsupportedOperationException: class
> > > >> org.apache.calcite.sql.SqlBasicCall: `K1` IN (SELECT `table2`.`fk`
> AS
> > > `FK`
> > > >> FROM `tblspace1`.`table2` AS `TABLE2`
> > > >> WHERE `table2`.`k2` = ?)
> > > >>
> > > >> at org.apache.calcite.util.Util.needToImplement(Util.java:967)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType(SqlValidatorImpl.java:1579)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.sql2rel.SqlToRelConverter.findSubQueries(SqlToRelConverter.java:1802)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.sql2rel.SqlToRelConverter.findSubQueries(SqlToRelConverter.java:1776)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.sql2rel.SqlToRelConverter.replaceSubQueries(SqlToRelConverter.java:1011)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.sql2rel.SqlToRelConverter.convertUpdate(SqlToRelConverter.java:3570)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3172)
> > > >> at
> > > >>
> > > >>
> > >
> >
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:563)
> > > >> at org.apache.calcite.prepare.PlannerImpl.rel(PlannerImpl.java:254)
> > > >>
> > >
> > >
> >
>