Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-23751

Testing Window Top-N after Windowing TVF

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Blocker
    • Resolution: Resolved
    • None
    • 1.14.0
    • Tests

    Description

      Currently, Flink not only supports Window Top-N which follows after Window Aggregation. but also supports Window Top-N follows after Windowing TVF.

      The following example shows how to calculate Top 3 items which have the highest price for every tumbling 10 minutes window.

      SELECT * FROM Bid;
      +------------------+-------+------+-------------+
      | bidtime | price | item | supplier_id |
      +------------------+-------+------+-------------+
      | 2020-04-15 08:05 | 4.00 | A | supplier1 |
      | 2020-04-15 08:06 | 4.00 | C | supplier2 |
      | 2020-04-15 08:07 | 2.00 | G | supplier1 |
      | 2020-04-15 08:08 | 2.00 | B | supplier3 |
      | 2020-04-15 08:09 | 5.00 | D | supplier4 |
      | 2020-04-15 08:11 | 2.00 | B | supplier3 |
      | 2020-04-15 08:13 | 1.00 | E | supplier1 |
      | 2020-04-15 08:15 | 3.00 | H | supplier2 |
      | 2020-04-15 08:17 | 6.00 | F | supplier5 |
      +------------------+-------+------+-------------+
      
      Flink SQL> SELECT *
       FROM (
       SELECT *, ROW_NUMBER() OVER (PARTITION BY window_start, window_end ORDER BY price DESC) as rownum
       FROM TABLE(
       TUMBLE(TABLE Bid, DESCRIPTOR(bidtime), INTERVAL '10' MINUTES))
       ) WHERE rownum <= 3;
      +------------------+-------+------+-------------+------------------+------------------+--------+
      | bidtime | price | item | supplier_id | window_start | window_end | rownum |
      +------------------+-------+------+-------------+------------------+------------------+--------+
      | 2020-04-15 08:05 | 4.00 | A | supplier1 | 2020-04-15 08:00 | 2020-04-15 08:10 | 2 |
      | 2020-04-15 08:06 | 4.00 | C | supplier2 | 2020-04-15 08:00 | 2020-04-15 08:10 | 3 |
      | 2020-04-15 08:09 | 5.00 | D | supplier4 | 2020-04-15 08:00 | 2020-04-15 08:10 | 1 |
      | 2020-04-15 08:11 | 2.00 | B | supplier3 | 2020-04-15 08:10 | 2020-04-15 08:20 | 3 |
      | 2020-04-15 08:15 | 3.00 | H | supplier2 | 2020-04-15 08:10 | 2020-04-15 08:20 | 2 |
      | 2020-04-15 08:17 | 6.00 | F | supplier5 | 2020-04-15 08:10 | 2020-04-15 08:20 | 1 |
      +------------------+-------+------+-------------+------------------+------------------+--------+
      

      Note: Currently, Flink only supports Window Top-N follows after Windowing TVF with Tumble Windows, Hop Windows and Cumulate Windows. Window Top-N follows after Windowing TVF with Session windows will be supported in the near future.

       

       

      Attachments

        Issue Links

          Activity

            People

              martijnvisser Martijn Visser
              jingzhang Jing Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: