Hi, all :wave: random question: Should filtering ...
# random
j
Hi, all πŸ‘‹ random question: Should filtering be done before window function, or Flink optimizer will do that for us? Example query:
Copy code
WITH topN AS (
    SELECT *,
        ROW_NUMBER() OVER (PARTITION BY window_start, window_end, col4 ORDER BY cnt DESC) as rowNumber
    FROM (
        SELECT window_start,
            window_end,
            col4,
            col5,
            COUNT(DISTINCT col6) as cnt
        FROM TABLE(
            HOP(TABLE $inputTable, DESCRIPTOR(time_ltz), INTERVAL $windowSlide, INTERVAL $windowSize)
        )
        WHERE 1=1
            AND col1 = 'A'
            AND col2 = 'B'
            AND col3 = 'C'
        GROUP BY window_start, window_end, col4, col5
    )
)
SELECT ..., count(*)
FROM topN
WHERE rowNumber <= $num
GROUP BY window_start, window_end
Would it be better if
WHERE 1=1 AND col1=… AND col2=…
is before(defined in a view maybe) TABLE() function?
m
You can have a look at the generated optimized plan with EXPLAIN. See https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/sql/explain/ if you end up with a difference or if the plan is actually the same πŸ™‚
❀️ 1
j
Thanks! Will check it out πŸ‘Œ