You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "yanjing.wang (Jira)" <ji...@apache.org> on 2022/02/14 04:28:00 UTC

[jira] [Updated] (CALCITE-4683) In-list to join causes field datatypes not matched

     [ https://issues.apache.org/jira/browse/CALCITE-4683?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

yanjing.wang updated CALCITE-4683:
----------------------------------
    Description: 
The sql query is 
{code:java}
SELECT * FROM (
SELECT '20210101' AS dt, deptno
FROM emp
GROUP BY deptno
) t
WHERE cast(deptno as varchar) in ('1')

{code}
When Calcite converts the in list to a join, the original leave rel will be replaced by a new rel, but the new rel hasn't been set as a leave rel, This will cause mismatched field type.

Finally, the query results

java.lang.AssertionError: Conversion to relational algebra failed to preserve datatypes:
validated type:
RecordType(CHAR(8) NOT NULL dt, INTEGER deptno) NOT NULL
converted type:
RecordType(INTEGER dt, INTEGER deptno) NOT NULL
rel:
LogicalProject(dt=[$0], deptno=[$1])
  LogicalJoin(condition=[=($2, $3)], joinType=[inner])
    LogicalProject(dt=['20210101'], deptno=[$0], deptno0=[CAST($0):VARCHAR])
      LogicalAggregate(group=[\{0}])
        LogicalProject(deptno=[$1])
          HiveTableScan(table=[[default, emp]])
    LogicalAggregate(group=[\{0}])
      LogicalValues(tuples=[[\{ '1' }]])

    at org.apache.calcite.sql2rel.SqlToRelConverter.checkConvertedType(SqlToRelConverter.java:467)
    at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:582)

  was:
The sql query is 
{code:java}
SELECT * FROM (
SELECT '20210101' AS dt, deptno
FROM emp
GROUP BY deptno
) t
WHERE cast(deptno as varchar) in ('1')

{code}
When Calcite converts the in list to a join, the original leave rel will be replaced by a new rel, but the new rel hasn't been set as a leave rel, This will cause mismatched field type.

Finally, the query results java.lang.AssertionError: Conversion to relational algebra failed to preserve datatypes. 


> In-list to join causes field datatypes not matched
> --------------------------------------------------
>
>                 Key: CALCITE-4683
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4683
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.26.0, 1.27.0
>         Environment: jdk8
>  
>            Reporter: yanjing.wang
>            Assignee: yanjing.wang
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.30.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> The sql query is 
> {code:java}
> SELECT * FROM (
> SELECT '20210101' AS dt, deptno
> FROM emp
> GROUP BY deptno
> ) t
> WHERE cast(deptno as varchar) in ('1')
> {code}
> When Calcite converts the in list to a join, the original leave rel will be replaced by a new rel, but the new rel hasn't been set as a leave rel, This will cause mismatched field type.
> Finally, the query results
> java.lang.AssertionError: Conversion to relational algebra failed to preserve datatypes:
> validated type:
> RecordType(CHAR(8) NOT NULL dt, INTEGER deptno) NOT NULL
> converted type:
> RecordType(INTEGER dt, INTEGER deptno) NOT NULL
> rel:
> LogicalProject(dt=[$0], deptno=[$1])
>   LogicalJoin(condition=[=($2, $3)], joinType=[inner])
>     LogicalProject(dt=['20210101'], deptno=[$0], deptno0=[CAST($0):VARCHAR])
>       LogicalAggregate(group=[\{0}])
>         LogicalProject(deptno=[$1])
>           HiveTableScan(table=[[default, emp]])
>     LogicalAggregate(group=[\{0}])
>       LogicalValues(tuples=[[\{ '1' }]])
>     at org.apache.calcite.sql2rel.SqlToRelConverter.checkConvertedType(SqlToRelConverter.java:467)
>     at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:582)



--
This message was sent by Atlassian Jira
(v8.20.1#820001)