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

ASF GitHub Bot commented on FLINK-5584:
---------------------------------------

Github user wuchong commented on the issue:

    https://github.com/apache/flink/pull/3175
  
    Hi @hongyuhong , thank your for your job. But it seems that you 
misunderstand the SQL OVER syntax. 
    The OVER clause defines a window or user-specified set of rows within a 
query result set. A window function then computes a value for each row in the 
window. It is similar to Row-Window proposed in 
[FLIP-11](https://cwiki.apache.org/confluence/display/FLINK/FLIP-11%3A+Table+API+Stream+Aggregations),
 but is different with Sliding Row-count window.
    
    For example, OVER (ROWS 2 PRECEDING) means that the window of rows that the 
function operates on is three rows in size, starting with 2 rows preceding 
until and including the current row.
    
    Say we have a table `T1` 
    
    ```
    t  a  
    -----
    1  1 
    2  5 
    3  3 
    4  5 
    5  4 
    6 11
    ```
    
    and the following SQL will yield:
    
    ```sql
    SELECT t, a, sum(a) OVER (ROWS 2 PRECEDING) FROM T1
    ```
    
    ```
    t  a  avg
    ----------
    1  1  1
    2  5  6
    3  3  9
    4  5  13
    5  4  12
    6 11  20
    ```
    
    For Row-window, we would need something more complex, especially when we 
need to order by timestamp. For example, to support event-time count-window 
row-window, we need to create a custom operator that collects records in a 
priority queue ordered by timestamp. Once a watermark is received for the upper 
bound of a window, the priority queue is used to evaluate the window function 
(based on count) and to purge too old records. 
    
    I would suggest this PR to wait for FLINK-4679. When FLINK-4679 is fixed, 
this PR can be easily supported IMO.


> Support Sliding-count row-window on streaming sql
> -------------------------------------------------
>
>                 Key: FLINK-5584
>                 URL: https://issues.apache.org/jira/browse/FLINK-5584
>             Project: Flink
>          Issue Type: New Feature
>          Components: Table API & SQL
>            Reporter: Yuhong Hong
>
> Calcite has already support sliding-count row-window, the grammar look like:
> select sum(amount) over (rows 10 preceding) from Order;
> select sum(amount) over (partition by user rows 10 preceding) from Order;
> And it will parse the sql as a LogicalWindow relnode, the logical Window 
> contains aggregate func info and window info, it's similar to Flink 
> LogicalWIndowAggregate, so we can add an convert rule to directly convert 
> LogicalWindow into DataStreamAggregate relnode, and if Calcite support more 
> grammar, we can extend the convert rule.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to