summaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/window/win_range_int16.yql
blob: fb5d2974f3cc90f5cb995d35c0b03ecee4f84a13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
PRAGMA WindowNewPipeline;

$data = [
    <|a: int16('-1000'), b: 1, sum: int16('-1500'), count: 5|>,
    <|a: int16('-500'), b: 1, sum: int16('-500'), count: 4|>,
    <|a: int16('0'), b: 1, sum: int16('0'), count: 3|>,
    <|a: NULL, b: 1, sum: NULL, count: 2|>,
    <|a: NULL, b: 1, sum: NULL, count: 2|>,
];

$win_result = (
    SELECT
        SUM(a) OVER w1 AS actual_sum,
        COUNT(*) OVER w1 AS actual_count,
        sum,
        count,
    FROM
        AS_TABLE($data)
    WINDOW
        w1 AS (
            PARTITION COMPACT BY
                b
            ORDER BY
                -a DESC
            RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
        )
);

$str = ($x) -> {
    return CAST($x as String) ?? "null";
};

SELECT
    Ensure(actual_sum, sum IS NOT DISTINCT FROM actual_sum, $str(actual_sum)),
    Ensure(actual_count, count IS NOT DISTINCT FROM actual_count, $str(actual_count))
FROM
    $win_result
;