|
| 1 | +#coding:utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +ID: issue-8589 |
| 5 | +ISSUE: https://github.com/FirebirdSQL/firebird/issues/8589 |
| 6 | +TITLE: PERCENT_RANK may return NaN instead of 0 |
| 7 | +DESCRIPTION: |
| 8 | +NOTES: |
| 9 | + [07.06.2025] pzotov |
| 10 | + Confirmed bug on 6.0.0.797-0-303e8d4 |
| 11 | + Checked on 6.0.0.797-bc305e6; 5.0.3.1369-fe53465; 4.0.6.3206-9580691 |
| 12 | +""" |
| 13 | + |
| 14 | +import pytest |
| 15 | +from firebird.qa import * |
| 16 | + |
| 17 | +db = db_factory() |
| 18 | + |
| 19 | +test_script = """ |
| 20 | +
|
| 21 | + set list on; |
| 22 | + recreate table test( |
| 23 | + id integer not null, |
| 24 | + the_int integer, |
| 25 | + primary key (id) |
| 26 | + ); |
| 27 | +
|
| 28 | + insert into test(the_int, id) values (5, 1); |
| 29 | + insert into test(the_int, id) values (6, 2); |
| 30 | + insert into test(the_int, id) values (7, 3); |
| 31 | + insert into test(the_int, id) values (13, 4); |
| 32 | + insert into test(the_int, id) values (5, 5); |
| 33 | +
|
| 34 | + select |
| 35 | + id, |
| 36 | + the_int, |
| 37 | + row_number() over(partition by t.the_int order by t.id), |
| 38 | + percent_rank() over(partition by t.the_int order by t.id), |
| 39 | + cume_dist() over(partition by t.the_int order by t.id) |
| 40 | + from test t |
| 41 | + order by 1; |
| 42 | +""" |
| 43 | + |
| 44 | +act = isql_act('db', test_script, substitutions = [('[\t ]+', ' ')]) |
| 45 | + |
| 46 | +expected_stdout = """ |
| 47 | + ID 1 |
| 48 | + THE_INT 5 |
| 49 | + ROW_NUMBER 1 |
| 50 | + PERCENT_RANK 0.000000000000000 |
| 51 | + CUME_DIST 0.5000000000000000 |
| 52 | +
|
| 53 | + ID 2 |
| 54 | + THE_INT 6 |
| 55 | + ROW_NUMBER 1 |
| 56 | + PERCENT_RANK 0.000000000000000 |
| 57 | + CUME_DIST 1.000000000000000 |
| 58 | +
|
| 59 | + ID 3 |
| 60 | + THE_INT 7 |
| 61 | + ROW_NUMBER 1 |
| 62 | + PERCENT_RANK 0.000000000000000 |
| 63 | + CUME_DIST 1.000000000000000 |
| 64 | +
|
| 65 | + ID 4 |
| 66 | + THE_INT 13 |
| 67 | + ROW_NUMBER 1 |
| 68 | + PERCENT_RANK 0.000000000000000 |
| 69 | + CUME_DIST 1.000000000000000 |
| 70 | +
|
| 71 | + ID 5 |
| 72 | + THE_INT 5 |
| 73 | + ROW_NUMBER 2 |
| 74 | + PERCENT_RANK 1.000000000000000 |
| 75 | + CUME_DIST 1.000000000000000 |
| 76 | +""" |
| 77 | + |
| 78 | +@pytest.mark.version('>=4.0.6') |
| 79 | +def test_1(act: Action): |
| 80 | + act.expected_stdout = expected_stdout |
| 81 | + act.execute(combine_output = True) |
| 82 | + assert act.clean_stdout == act.clean_expected_stdout |
| 83 | + |
0 commit comments