Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.18.0
Description
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)
Attachments
Issue Links
- is related to
-
CALCITE-2963 IndexOutOfBoundsException in RelStructuredTypeFlattener when accessing nested fields
- Resolved
-
CALCITE-2962 RelStructuredTypeFlattener generates wrong types for nested column when flattenProjection
- Closed
- links to