summaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/window/win_range_int8.yql
blob: e90177abf38c28567b5f5427aa3ce2677ba82b78 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
PRAGMA WindowNewPipeline;

$data = [
    <|a: int8('-8'), b: 1, sum1: int8('-8'), count1: 1, sum2: NULL, count2: 0|>,
    <|a: int8('-5'), b: 1, sum1: int8('-13'), count1: 2, sum2: int8('-8'), count2: 1|>,
    <|a: int8('0'), b: 1, sum1: int8('-5'), count1: 2, sum2: NULL, count2: 0|>,
    <|a: NULL, b: 1, sum1: NULL, count1: 2, sum2: NULL, count2: 2|>,
    <|a: NULL, b: 1, sum1: NULL, count1: 2, sum2: NULL, count2: 2|>,
];

$win_result = (
    SELECT
        SUM(a) OVER w1 AS actual_sum1,
        COUNT(*) OVER w1 AS actual_count1,
        SUM(a) OVER w2 AS actual_sum2,
        COUNT(*) OVER w2 AS actual_count2,
        sum1,
        count1,
        sum2,
        count2,
    FROM
        AS_TABLE($data)
    WINDOW
        w1 AS (
            PARTITION COMPACT BY
                b
            ORDER BY
                a ASC
            RANGE BETWEEN int8('5') PRECEDING AND CURRENT ROW
        ),
        w2 AS (
            PARTITION COMPACT BY
                b
            ORDER BY
                a ASC
            RANGE BETWEEN int8('3') PRECEDING AND int8('2') PRECEDING
        )
);

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

SELECT
    Ensure(actual_sum1, sum1 IS NOT DISTINCT FROM actual_sum1, $str(actual_sum1)),
    Ensure(actual_count1, count1 IS NOT DISTINCT FROM actual_count1, $str(actual_count1)),
    Ensure(actual_sum2, sum2 IS NOT DISTINCT FROM actual_sum2, $str(actual_sum2)),
    Ensure(actual_count2, count2 IS NOT DISTINCT FROM actual_count2, $str(actual_count2))
FROM
    $win_result
;