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

xuyangzhong commented on FLINK-22455:
-------------------------------------

Hi, [~tartarus]. I'm trying to solve this issue recently, and i can't trigger 
this bug using real case by sql/table api and reproduce this question.

It seems like that only using table api will enter this function while using 
sql api don't use FlinkRelBuilder(you can see the code in Function 
LogicalWindowAggregateRuleBase and line 100-113). 

I create some tests like the following: 
{code:java}
// test1
Table result = tenv
 .from("orders")
 .window(Tumble.over(lit(4).seconds()).on($("rowtime")).as("mywindow"))
 .groupBy($("it1"), $("mywindow"))
 .select($("it1"), $("it2").count().as("b"), $("it2").count().as("b"), 
$("mywindow").start(), $("mywindow").end());
{code}
 

 
{code:java}
// test2
Table result = tenv
 .from("orders")
 .window(Tumble.over(lit(4).seconds()).on($("rowtime")).as("mywindow"))
 .groupBy($("it1"), $("mywindow"))
 .select($("it1"), $("it2").count().as("b1"), $("it2").count().as("b2"), 
$("mywindow").start(), $("mywindow").end());{code}
 

Test1 throws Exception directly because in function validateAndGetUniqueNames 
in ProjectionOperationFactory, names will be checked to avoid duplication. 
Test2 enters the function the issue mentioned but _aggCalls_ has one element 
because in the previous optimization, the $("it2").count will be merged to one 
expression although they have the different name "b1" and "b2".

According to the above, i think this code this issue mentioned perhaps have the 
logical bug indeed but won't be trigged by the real case by table/sql api.

So can you have a test case used by sql/table api  to help me solve the issue?

> FlinkRelBuilder#windowAggregate will throw ClassCastException when function 
> reuse
> ---------------------------------------------------------------------------------
>
>                 Key: FLINK-22455
>                 URL: https://issues.apache.org/jira/browse/FLINK-22455
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>            Reporter: tartarus
>            Priority: Minor
>              Labels: auto-deprioritized-major
>         Attachments: FlinkRelBuilderTest.scala
>
>
> If the input parameter aggCalls of FlinkRelBuilder#windowAggregate contains 
> the same aggregate function. Then it will throw ClassCastException, because 
> of the optimization of aggregate function reuse. We did not judge the return 
> value type, but direct type conversion;
> {code:java}
>     val aggregate = super.transform(
>       new UnaryOperator[RelBuilder.Config] {
>         override def apply(t: RelBuilder.Config)
>           : RelBuilder.Config = t.withPruneInputOfAggregate(false)
>       })
>       .push(build())
>       .aggregate(groupKey, aggCalls)
>       .build()
>       .asInstanceOf[LogicalAggregate]
> {code}
> I wrote a test that triggered this problem.
> You can use the attached code to reproduce this problem.



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

Reply via email to