You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Stamatis Zampetakis (JIRA)" <ji...@apache.org> on 2019/03/07 07:41:00 UTC

[jira] [Commented] (CALCITE-2900) RewriteRexShuttle generates wrong type during flatten for structured type when visitInputRef

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

Stamatis Zampetakis commented on CALCITE-2900:
----------------------------------------------

Thnanks for brining this up [~my7ym]! Can you provide a unit test which reproduces the problem. Possibly, you can use org.apache.calcite.test.BookstoreSchema which has already many levels of nesting and structured types. In the meanwhile, as a workaround, you may try to bypass the flattener since most likely the problem comes from there.

> RewriteRexShuttle generates wrong type during flatten for structured type when visitInputRef
> --------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-2900
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2900
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.18.0
>            Reporter: Will Yu
>            Priority: Blocker
>
> When we leverage Calcite to parse a SQL and generates a RelNode tree on top of a table with *structured* columns, Calcite throws an error about type mismatch shown at bottom.
> After a bit of debugging, the issue is suspected to happen in RewriteRexShuttle.visitFieldAccess. When the input is RexInputRef, such as $36.target_column, the newField type is calculated based on ONLY the index 36, WITHOUT considering the offset of target_column. The result is new field type is the type of the first sub-column of column $36, which causes the type mismatch.
>  
> Error and stacktrace:
> java.lang.AssertionError: type mismatch:
> ref:
> INTEGER NOT NULL
> input:
> VARCHAR CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL
> at org.apache.calcite.util.Litmus$1.fail(Litmus.java:31)
>  at org.apache.calcite.plan.RelOptUtil.eq(RelOptUtil.java:1832)
>  at org.apache.calcite.rex.RexChecker.visitInputRef(RexChecker.java:125)
>  at org.apache.calcite.rex.RexChecker.visitInputRef(RexChecker.java:57)
>  at org.apache.calcite.rex.RexInputRef.accept(RexInputRef.java:112)
>  at org.apache.calcite.rel.core.Project.isValid(Project.java:186)
>  at org.apache.calcite.rel.core.Project.<init>(Project.java:83)
>  at org.apache.calcite.rel.logical.LogicalProject.<init>(LogicalProject.java:62)
>  at org.apache.calcite.rel.logical.LogicalProject.create(LogicalProject.java:112)
>  at org.apache.calcite.rel.logical.LogicalProject.create(LogicalProject.java:100)
>  at org.apache.calcite.rel.core.RelFactories$ProjectFactoryImpl.createProject(RelFactories.java:140)
>  at org.apache.calcite.tools.RelBuilder.project(RelBuilder.java:1248)
>  at org.apache.calcite.tools.RelBuilder.projectNamed(RelBuilder.java:1304)
>  at org.apache.calcite.sql2rel.RelStructuredTypeFlattener.rewriteRel(RelStructuredTypeFlattener.java:506)
>  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.apache.calcite.util.ReflectUtil.invokeVisitorInternal(ReflectUtil.java:257)
>  at org.apache.calcite.util.ReflectUtil.invokeVisitor(ReflectUtil.java:214)
>  at org.apache.calcite.util.ReflectUtil$1.invokeVisitor(ReflectUtil.java:464)
>  at org.apache.calcite.sql2rel.RelStructuredTypeFlattener$RewriteRelVisitor.visit(RelStructuredTypeFlattener.java:759)
>  at org.apache.calcite.rel.SingleRel.childrenAccept(SingleRel.java:72)
>  at org.apache.calcite.rel.RelVisitor.visit(RelVisitor.java:44)
>  at org.apache.calcite.sql2rel.RelStructuredTypeFlattener$RewriteRelVisitor.visit(RelStructuredTypeFlattener.java:754)
>  at org.apache.calcite.sql2rel.RelStructuredTypeFlattener.rewrite(RelStructuredTypeFlattener.java:194)
>  at org.apache.calcite.sql2rel.SqlToRelConverter.flattenTypes(SqlToRelConverter.java:466)
>  at org.apache.calcite.prepare.PlannerImpl.rel(PlannerImpl.java:236)
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)