6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 14:03:06 +01:00
firebird-qa/tests/bugs/core_5768_test.py

62 lines
1.9 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-26 21:10:46 +01:00
"""
ID: issue-6031
ISSUE: 6031
TITLE: Implement FILTER-clause for aggregate functions (introduced in SQL:2003).
This syntax allows for filtering before aggregation.
2022-01-26 21:10:46 +01:00
DESCRIPTION:
JIRA: CORE-5768
FBTEST: bugs.core_5768
2022-01-26 21:10:46 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
recreate table test(x int, y int, q int);
commit;
insert into test(x,y,q) values(null, null, 100);
insert into test(x,y,q) values(null, null, 200);
insert into test(x,y,q) values(1000, null, 111);
insert into test(x,y,q) values(1000, null, 222);
insert into test(x,y,q) values(1000, 1000, 555);
insert into test(x,y,q) values(1000, 1000, 777);
commit;
set list on;
2022-01-26 21:10:46 +01:00
select
2021-04-26 20:07:00 +02:00
sum( iif(x is null, q, null) ) sum_q_iif_x_is_null
,sum( q )filter( where x is null ) sum_q_filter_x_is_null
,min( sum_q_iif_y_is_null_over ) filter( where true ) chk_filter_where_true
,min( sum_q_filter_y_is_null_over ) filter( where null is null ) chk_filter_where_n_is_n
,min( 1 ) filter( where null ) chk_filter_where_null ------------------------------------- allowed! boolean but without left part ?..
,min( 1 ) filter( where not null ) chk_filter_where_not_null
from (
select x, y, q
2022-01-26 21:10:46 +01:00
,sum( iif(y is null, q, null) ) over() sum_q_iif_y_is_null_over
2021-04-26 20:07:00 +02:00
,sum( q )filter( where y is null) over() sum_q_filter_y_is_null_over
from test
)
;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
SUM_Q_IIF_X_IS_NULL 300
SUM_Q_FILTER_X_IS_NULL 300
CHK_FILTER_WHERE_TRUE 633
CHK_FILTER_WHERE_N_IS_N 633
CHK_FILTER_WHERE_NULL <null>
CHK_FILTER_WHERE_NOT_NULL <null>
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2022-01-26 21:10:46 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout