[jira] [Created] (FLINK-22313) Redundant CAST in plan when selecting window start and window end in window agg

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (FLINK-22313) Redundant CAST in plan when selecting window start and window end in window agg

Shang Yuanchun (Jira)
Caizhi Weng created FLINK-22313:
-----------------------------------

             Summary: Redundant CAST in plan when selecting window start and window end in window agg
                 Key: FLINK-22313
                 URL: https://issues.apache.org/jira/browse/FLINK-22313
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / API
    Affects Versions: 1.13.0
            Reporter: Caizhi Weng


Add the following test case to {{org.apache.flink.table.planner.plan.stream.sql.agg.WindowAggregateTest}} to reproduce this bug.

{code:scala}
@Test
def testSessionFunction(): Unit = {
  val sql =
    """
      |SELECT
      |    COUNT(*),
      |    SESSION_START(proctime, INTERVAL '15' MINUTE),
      |    SESSION_END(proctime, INTERVAL '15' MINUTE)
      |FROM MyTable
      |    GROUP BY SESSION(proctime, INTERVAL '15' MINUTE)
    """.stripMargin
  util.verifyExecPlan(sql)
}
{code}

The produced plan is
{code}
Calc(select=[EXPR$0, CAST(w$start) AS EXPR$1, CAST(w$end) AS EXPR$2])
+- GroupWindowAggregate(window=[SessionGroupWindow('w$, proctime, 900000)], properties=[w$start, w$end, w$proctime], select=[COUNT(*) AS EXPR$0, start('w$) AS w$start, end('w$) AS w$end, proctime('w$) AS w$proctime])
   +- Exchange(distribution=[single])
      +- Calc(select=[proctime])
         +- WatermarkAssigner(rowtime=[rowtime], watermark=[(rowtime - 1000:INTERVAL SECOND)])
            +- Calc(select=[PROCTIME() AS proctime, rowtime])
               +- TableSourceScan(table=[[default_catalog, default_database, MyTable, project=[rowtime]]], fields=[rowtime])
{code}

This is because the nullability indicated by {{PlannerWindowStart#getResultType}} and {{SqlGroupedWindowFunction#WindowStartEndReturnTypeInference}} are different. Actually time attribute and window start / end should always be not null.



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