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

Xurenhe commented on CALCITE-4818:
----------------------------------

Yes, you are right, there is a bug of rowtype.
After reviewing pr, I propose you add one test case:
{code:java}
//代码占位符
SELECT s1+1 AS new_s1, s2+1 AS new_s2 FROM (SELECT SUM(comm) AS s1, 
SUM(DISTINCT comm) AS s2 FROM emp)

LogicalProject(NEW_S1=[+($0, 1)], NEW_S2=[+($1, 1)])
  LogicalAggregate(group=[{}], S1=[SUM($0)], S2=[SUM(DISTINCT $0)])
    LogicalProject(COMM=[$6])
      LogicalTableScan(table=[[CATALOG, SALES, EMP]]{code}
type mismatch:
aggCall type:
BIGINT
inferred type:
DECIMAL(19, 0)
java.lang.AssertionError: type mismatch:
aggCall type:
BIGINT
inferred type:
DECIMAL(19, 0)
 at org.apache.calcite.util.Litmus$1.fail(Litmus.java:32)
 at org.apache.calcite.plan.RelOptUtil.eq(RelOptUtil.java:2211)
 at 
org.apache.calcite.rel.core.Aggregate.typeMatchesInferred(Aggregate.java:448)
 at org.apache.calcite.rel.core.Aggregate.<init>(Aggregate.java:175)
 at 
org.apache.calcite.rel.logical.LogicalAggregate.<init>(LogicalAggregate.java:72)
 at 
org.apache.calcite.rel.logical.LogicalAggregate.copy(LogicalAggregate.java:154)
 at 
org.apache.calcite.rel.logical.LogicalAggregate.copy(LogicalAggregate.java:48)
 at 
org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.convertSingletonDistinct(AggregateExpandDistinctAggregatesRule.java:407)
 at 
org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.onMatch(AggregateExpandDistinctAggregatesRule.java:213)

> AggregateExpandDistinctAggregatesRule must infer correct data type for top 
> aggregate calls
> ------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4818
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4818
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.27.0
>            Reporter: Taras Ledkov
>            Assignee: Taras Ledkov
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.28.0
>
>
> When SUM data type derivation is more complex, e.g.:
> {code}
> SUM(TINYINT | SMALLINT | INTEGER) -> BIGINT
> SUM(BIGINT) -> DECIMAL
> {code}
> The rule {{AggregateExpandDistinctAggregatesRule}} creates the top aggregate 
> calls with invalid type for not distinct calls.
> e.g. {{SELECT SUM(comm), SUM(DISTINCT comm) FROM emp}}
> Please take a look at the reproducer in the PR.
> *Proposed fix:*  infer type of top aggregates by input row type. Pass 
> {{null}} type to the call method {{AggregateCall#create}}.



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

Reply via email to