summaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/window/range_pg/win_range_pgfloat8.yql
blob: 00e96fc8681a7b3000aa55663806d50228f533f4 (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
PRAGMA WindowNewPipeline;

$data = [
    <|a: pgfloat8('-10.5'), b: 1, sum11: pgfloat8('-10.5'), count1: 1, sum22: NULL, count2: 0|>,
    <|a: pgfloat8('-5.0'), b: 1, sum11: pgfloat8('-15.5'), count1: 2, sum22: NULL, count2: 0|>,
    <|a: pgfloat8('0.0'), b: 1, sum11: pgfloat8('-5.0'), count1: 2, sum22: pgfloat8('-5.0'), count2: 1|>,
];

$win_result = (
    SELECT
        pg::sum(a) OVER w1 AS actual_sum11,
        COUNT(*) OVER w1 AS actual_count1,
        pg::sum(a) OVER w2 AS actual_sum22,
        COUNT(*) OVER w2 AS actual_count2,
        sum11,
        count1,
        sum22,
        count2,
    FROM
        AS_TABLE($data)
    WINDOW
        w1 AS (
            PARTITION COMPACT BY
                b
            ORDER BY
                a ASC
            RANGE BETWEEN pgfloat8('10.0') PRECEDING AND CURRENT ROW
        ),
        w2 AS (
            PARTITION COMPACT BY
                b
            ORDER BY
                a ASC
            RANGE BETWEEN pgfloat8('5.0') PRECEDING AND pgfloat8('0.5') PRECEDING
        )
);

SELECT
    Ensure(actual_sum11, sum11 IS NOT DISTINCT FROM actual_sum11),
    Ensure(actual_count1, count1 IS NOT DISTINCT FROM actual_count1),
    Ensure(actual_sum22, sum22 IS NOT DISTINCT FROM actual_sum22),
    Ensure(actual_count2, count2 IS NOT DISTINCT FROM actual_count2)
FROM
    $win_result
;