You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Vasudev (Jira)" <ji...@apache.org> on 2021/11/02 22:42:00 UTC

[jira] [Commented] (CALCITE-4849) Query SQL cannot complete materialized view rewrite properly

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

Vasudev commented on CALCITE-4849:
----------------------------------

I am facing this issue too but it happens to me when I execute the substituted plan, not during the substitution itself.

 

Also, I've found that when the query uses all the columns that are present in the SELECT condition of the materialized view, the issue disappears and the execution goes smoothly.

I've tried replicating it in the tests but because the error occurs during the execution for me, and because the tests compare plans as strings, I don't think it's possible (correct me if I'm wrong here).

> 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)