shihchengwei-lab commented on PR #30242:
URL: https://github.com/apache/flink/pull/30242#issuecomment-7378478534

   `APPROX_COUNT_DISTINCT` still passes the new streaming `OVER` validation and 
is executed as ordinary `COUNT`, so duplicate values silently inflate the 
result.
   
   At `de86d5a`, I compiled and executed this `INSERT` through 
`TableEnvironment.compilePlanSql` and the returned `CompiledPlan`:
   
   ```sql
   INSERT INTO MySink
   SELECT a, APPROX_COUNT_DISTINCT(c) OVER (
     PARTITION BY a ORDER BY rowtime
   )
   FROM MyTable;
   ```
   
   The input had three rows in one partition, all with `c = 1` and distinct 
event-time values. I expected planning to reject this unsupported streaming 
aggregate. Instead, the job completed and wrote running results `[1, 2, 3]`; 
with only one distinct value, the result must remain `[1, 1, 1]`.
   
   The serialized call keeps the internal name `$APPROX_COUNT_DISTINCT$1`, but 
has `distinct=false` and `approximate=false`. Calcite 1.41's 
`Window.Group#getAggregateCalls` constructs the window `AggregateCall` with 
`approximate=false`; `StreamOverAggregateUtil` then sees only `SqlKind.COUNT`, 
and `AggFunctionFactory` selects the regular count implementation. The same 
mis-lowering exists on base `9eafb15`, but this appears to be within this PR's 
validation contract: the new utility says it mirrors the stream-mode checks in 
`AggFunctionFactory`, where `APPROX_COUNT_DISTINCT` is explicitly rejected when 
`!isBounded`.
   
   Could the validation reject this operator even after the window conversion 
loses the approximate flag (or preserve the flag), and add this duplicate-input 
runtime case?
   
   AI assistance: traced the planner path, built and ran the fixed-head and 
base reproductions, and drafted this comment.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to