summaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/window/win_range_uint32.yql
blob: 1e163f250cd8449eb16b7205b64904acca2887e3 (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: uint32('1000'), b: 1, sum: uint32('1000'), count: 1|>,
    <|a: uint32('2000'), b: 1, sum: uint32('3000'), count: 2|>,
    <|a: uint32('2500'), b: 1, sum: uint32('4500'), count: 2|>,
    <|a: uint32('3000'), b: 1, sum: uint32('7500'), count: 3|>,
    <|a: uint32('5000'), b: 1, sum: uint32('5000'), count: 1|>,
];

$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 ASC
            RANGE BETWEEN uint32('1000') PRECEDING AND CURRENT ROW
        )
);

$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
;