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

jhkcool commented on CALCITE-4849:
----------------------------------

[~Chunwei Lei] I can not reproduce it in calcite unit test until now.
In our enviorment, It is also not inevitable.
But let me post below the usage when I have a problem, it may be useful. 
And if I don't reproduce it in the Calcite unit test by tomorrow, should I 
close this issue?

{code:java}
@Test void test() {
    List<Pair<String, String>> materializeList = new ArrayList<>();
    materializeList.add(new Pair<>("select \"empid\" from \"hr\".\"emps\"", 
"MV0"));
    materializeList.add(new Pair<>("select \"empid\", CAST(\"deptno\" AS 
TIMESTAMP) AS d0 from \"hr\".\"emps\"", "MV1"));
    materializeList.add(new Pair<>("select \"deptno\", CAST(\"empid\" AS 
TIMESTAMP) AS d0 from \"hr\".\"emps\"", "MV11"));
    materializeList.add(new Pair<>("select \"deptno\" from \"hr\".\"emps\"", 
"MV2"));
    materializeList.add(new Pair<>("select \"deptno\" from \"hr\".\"emps\"  
where \"empid\" > 20", "MV3"));
    materializeList.add(new Pair<>("select \"empid\" from \"hr\".\"emps\"  
where \"empid\" > 20", "MV4"));
    materializeList.add(new Pair<>("select \"deptno\",\"empid\" from 
\"hr\".\"emps\" where \"empid\" > 20 GROUP BY \"deptno\",\"empid\"", "MV5"));

    sql(materializeList, "select \"deptno\" from \"hr\".\"emps\" where 
\"empid\" > 30 GROUP BY \"deptno\"")
        .ok();
  }

protected Sql sql(List<Pair<String, String>> materializeList, String query) {
    return ImmutableBeans.create(Sql.class)
        .withMaterializations(materializeList)
        .withQuery(query)
        .withTester(this);
  }
{code}


> Query SQL cannot complete materialized view rewrite properly 
> -------------------------------------------------------------
>
>                 Key: CALCITE-4849
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4849
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.27.0
>            Reporter: jhkcool
>            Priority: Major
>
> {code:java}
> #materialization view MV:
> SELECT name,age FROM test WHERE age>20
> #query sql:
> SELECT name FROM test WHERE age>30
> #expect results after rewriting  
> SELECT name FROM MV WHERE age>30
> {code}
> but there is a exception:
> {code:java}
>  e.message: source #1 has no target in mapping [size=1, sourceCount=2, 
> targetCount=1, elements=[0:0]]
> Java exception follows:
> org.apache.calcite.util.mapping.Mappings$NoElementException: source #1 has no 
> target in mapping [size=1, sourceCount=2, targetCount=1, elements=[0:0]]
>         at 
> org.apache.calcite.util.mapping.Mappings$AbstractMapping.getTarget(Mappings.java:944)
>         at 
> org.apache.calcite.rex.RexPermuteInputsShuttle.visitInputRef(RexPermuteInputsShuttle.java:87)
>         at 
> org.apache.calcite.rex.RexPermuteInputsShuttle.visitInputRef(RexPermuteInputsShuttle.java:35)
>         at org.apache.calcite.rex.RexInputRef.accept(RexInputRef.java:114)
>         at org.apache.calcite.rex.RexShuttle.visitList(RexShuttle.java:161)
>         at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:113)
>         at 
> org.apache.calcite.rex.RexPermuteInputsShuttle.visitCall(RexPermuteInputsShuttle.java:102)
>         at 
> org.apache.calcite.rex.RexPermuteInputsShuttle.visitCall(RexPermuteInputsShuttle.java:35)
>         at org.apache.calcite.rex.RexCall.accept(RexCall.java:189)
>         at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trimFields(RelFieldTrimmer.java:438)
>         at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)
>         at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:531)
>         at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.dispatchTrimFields(RelFieldTrimmer.java:284)
>         at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trim(RelFieldTrimmer.java:171)
>         at 
> org.apache.calcite.plan.RelOptMaterializations.trimUnusedfields(RelOptMaterializations.java:232)
>         at 
> org.apache.calcite.plan.RelOptMaterializations.substitute(RelOptMaterializations.java:187)
>         at 
> org.apache.calcite.plan.RelOptMaterializations.useMaterializedViews(RelOptMaterializations.java:73)
>         at 
> org.apache.calcite.plan.volcano.VolcanoPlanner.registerMaterializations(VolcanoPlanner.java:323)
>         at 
> org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:527)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to