6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-02-02 10:50:42 +01:00

Merge pull request #9 from ant-zuev/add_fbtest_datatypes

Add datatypes tests from fbtest.
This commit is contained in:
Pavel Zotov 2023-03-10 13:46:51 +03:00 committed by GitHub
commit ef8d683def
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 323 additions and 0 deletions

View File

@ -0,0 +1,150 @@
#coding:utf-8
"""
ID: decfloat.ordering-rules
TITLE: Test ordering of decfloat values
DESCRIPTION:
Test verifies work of:
- COMPARE_DECFLOAT - compares two DECFLOAT values to be equal, different or unordered.
Returns SMALLINT value which can be as follows:
0 - values are equal
1 - first value is less than second
2 - first value is greater than second
3 - values unordered (i.e. one or both is NAN / SNAN)
Unlike comparison operators ('<', '=', '>', etc.) comparison is exact - i.e.
COMPARE_DECFLOAT(2.17, 2.170) returns 2, not 0.
- TOTALORDER - compares two DECFLOAT values including any special value. The comparison is exact.
Returns SMALLINT value which can be as follows:
-1 - first value is less than second
0 - values are equal
1 - first value is greater than second
DECFLOAT values are ordered as follows:
-nan < -snan < -inf < -0.1 < -0.10 < -0 < 0 < 0.10 < 0.1 < inf < snan < nan
Checked on 4.0.0.1714.
FBTEST: functional.datatypes.decfloat_ordering_rules
"""
import pytest
from firebird.qa import *
db = db_factory()
test_script = """
set list on;
set decfloat traps to;
select
t.*
,decode( totalorder("-nan", "-snan"), -1, '-nan LSS -snan', 1, '-nan GTR -snan', 0, '-nan EQU -snan', 'UNKNOWN') as "totalorder(-nan, -snan)"
,decode( totalorder("-snan", "-inf"), -1, '-snan LSS -inf', 1, '-snan GTR -inf', 0, '-snan EQU -inf', 'UNKNOWN') as "totalorder(-snan, -inf)"
,decode( totalorder("-inf", "-0.1"), -1, '-inf LSS -0.1', 1, '-inf GTR -0.1', 0, '-inf EQU -0.1', 'UNKNOWN') as "totalorder(-inf, -0.1)"
,decode( totalorder("-0.1", "-0.10"), -1, '-0.1 LSS -0.10', 1, '-0.1 GTR -0.10', 0, '-0.1 EQU -0.10', 'UNKNOWN') as "totalorder(-0.1, -0.10)"
,decode( totalorder("-0.10", "-0"), -1, '-0.10 LSS -0', 1, '-0.10 GTR -0', 0, '-0.10 EQU -0', 'UNKNOWN') as "totalorder(-0.10, -0)"
,decode( totalorder("-0", "0"), -1, '-0 LSS 0', 1, '-0 GTR 0', 0, '-0 EQU 0', 'UNKNOWN') as "totalorder(-0, 0)"
,decode( totalorder("0", "0.10"), -1, '0 LSS 0.10', 1, '0 GTR 0.10', 0, '0 EQU 0.10', 'UNKNOWN') as "totalorder(0, 0.10)"
,decode( totalorder("0.10", "0.1"), -1, '0.10 LSS 0.1', 1, '0.10 GTR 0.1', 0, '0.10 EQU 0.1', 'UNKNOWN') as "totalorder(0.10, 0.1)"
,decode( totalorder("0.1", "inf"), -1, '0.1 LSS inf', 1, '0.1 GTR inf', 0, '0.1 EQU inf', 'UNKNOWN') as "totalorder(0.1, inf)"
,decode( totalorder("inf", "snan"), -1, 'inf LSS snan', 1, 'inf GTR snan', 0, 'inf EQU snan', 'UNKNOWN') as "totalorder(inf, snan)"
,decode( totalorder("snan", "nan"), -1, 'snan LSS nan', 1, 'snan GTR nan', 0, 'snan EQU nan', 'UNKNOWN') as "totalorder(snan, nan)"
,decode( compare_decfloat("-nan", "-snan"), 1, '-nan LSS -snan', 2, '-nan GTR -snan', 0, '-nan EQU -snan', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(-nan, -snan)"
,decode( compare_decfloat("-snan", "-inf"), 1, '-snan LSS -inf', 2, '-snan GTR -inf', 0, '-snan EQU -inf', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(-snan, -inf)"
,decode( compare_decfloat("-inf", "-0.1"), 1, '-inf LSS -0.1', 2, '-inf GTR -0.1', 0, '-inf EQU -0.1', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(-inf, -0.1)"
,decode( compare_decfloat("-0.1", "-0.10"), 1, '-0.1 LSS -0.10', 2, '-0.1 GTR -0.10', 0, '-0.1 EQU -0.10', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(-0.1, -0.10)"
,decode( compare_decfloat("-0.10", "-0"), 1, '-0.10 LSS -0', 2, '-0.10 GTR -0', 0, '-0.10 EQU -0', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(-0.10, -0)"
,decode( compare_decfloat("-0", "0"), 1, '-0 LSS 0', 2, '-0 GTR 0', 0, '-0 EQU 0', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(-0, 0)"
,decode( compare_decfloat("0", "0.10"), 1, '0 LSS 0.10', 2, '0 GTR 0.10', 0, '0 EQU 0.10', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(0, 0.10)"
,decode( compare_decfloat("0.10", "0.1"), 1, '0.10 LSS 0.1', 2, '0.10 GTR 0.1', 0, '0.10 EQU 0.1', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(0.10, 0.1)"
,decode( compare_decfloat("0.1", "inf"), 1, '0.1 LSS inf', 2, '0.1 GTR inf', 0, '0.1 EQU inf', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(0.1, inf)"
,decode( compare_decfloat("inf", "snan"), 1, 'inf LSS snan', 2, 'inf GTR snan', 0, 'inf EQU snan', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(inf, snan)"
,decode( compare_decfloat("snan", "nan"), 1, 'snan LSS nan', 2, 'snan GTR nan', 0, 'snan EQU nan', 3, 'Unordered', 'UNKNOWN' ) as "compare_decfloat(snan, nan)"
,iif( "-nan" < "-snan", '-nan LSS -snan', iif( "-nan" > "-snan", '-nan GTR -snan', iif("-nan" = "-snan", '-nan EQU -snan', 'UNKNOWN') ) ) as "arithmetic: -nan vs to -snan:"
,iif( "-snan" < "-inf", '-snan LSS -inf', iif( "-snan" > "-inf", '-snan GTR -inf', iif("-snan" = "-inf", '-snan EQU -inf', 'UNKNOWN') ) ) as "arithmetic: -snan vs to -inf:"
,iif( "-inf" < "-0.1", '-inf LSS -0.1', iif( "-inf" > "-0.1", '-inf GTR -0.1', iif("-inf" = "-0.1", '-inf EQU -0.1', 'UNKNOWN') ) ) as "arithmetic: -inf vs to -0.1:"
,iif( "-0.1" < "-0.10", '-0.1 LSS -0.10', iif( "-0.1" > "-0.10", '-0.1 GTR -0.10', iif("-0.1" = "-0.10", '-0.1 EQU -0.10', 'UNKNOWN') ) ) as "arithmetic: -0.1 vs to -0.10:"
,iif( "-0.10" < "-0", '-0.10 LSS -0', iif( "-0.10" > "-0", '-0.10 GTR -0', iif("-0.10" = "-0", '-0.10 EQU -0', 'UNKNOWN') ) ) as "arithmetic: -0.10 vs to -0:"
,iif( "-0" < "0", '-0 LSS 0', iif( "-0" > "0", '-0 GTR 0', iif("-0" = "0", '-0 EQU 0', 'UNKNOWN') ) ) as "arithmetic: -0 vs to 0:"
,iif( "0" < "0.10", '0 LSS 0.10', iif( "0" > "0.10", '0 GTR 0.10', iif("0" = "0.10", '0 EQU 0.10', 'UNKNOWN') ) ) as "arithmetic: 0 vs to 0.10:"
,iif( "0.10" < "0.1", '0.10 LSS 0.1', iif( "0.10" > "0.1", '0.10 GTR 0.1', iif("0.10" = "0.1", '0.10 EQU 0.1', 'UNKNOWN') ) ) as "arithmetic: 0.10 vs to 0.1:"
,iif( "0.1" < "inf", '0.1 LSS inf', iif( "0.1" > "inf", '0.1 GTR inf', iif("0.1" = "inf", '0.1 EQU inf', 'UNKNOWN') ) ) as "arithmetic: 0.1 vs to inf:"
,iif( "inf" < "snan", 'inf LSS snan', iif( "inf" > "snan", 'inf GTR snan', iif("inf" = "snan", 'inf EQU snan', 'UNKNOWN') ) ) as "arithmetic: inf vs to snan:"
,iif( "snan" < "nan", 'snan LSS nan', iif( "snan" > "nan", 'snan GTR nan', iif("snan" = "nan", 'snan EQU nan', 'UNKNOWN') ) ) as "arithmetic: snan vs to nan:"
from (
select
-cast('foo' as decfloat) as "-nan"
,-cast('snan' as decfloat) as "-snan"
,-cast(1/1e-9999 as decfloat) as "-inf"
,-cast(0.1 as decfloat) as "-0.1"
,-cast(0.10 as decfloat) as "-0.10"
,-cast(0 as decfloat) as "-0"
,cast(0 as decfloat) as "0"
,cast(0.10 as decfloat) as "0.10"
,cast(0.1 as decfloat) as "0.1"
,cast(1/1e-9999 as decfloat) as "inf"
,cast('snan' as decfloat) as "snan"
,cast('bar' as decfloat) as "nan"
from rdb$database
) t;
"""
act = isql_act('db', test_script, substitutions=[('[\\s]+', ' ')])
expected_stdout = """
-nan -NaN
-snan -sNaN
-inf -Infinity
-0.1 -0.1
-0.10 -0.10
-0 -0
0 0
0.10 0.10
0.1 0.1
inf Infinity
snan sNaN
nan NaN
totalorder(-nan, -snan) -nan LSS -snan
totalorder(-snan, -inf) -snan LSS -inf
totalorder(-inf, -0.1) -inf LSS -0.1
totalorder(-0.1, -0.10) -0.1 LSS -0.10
totalorder(-0.10, -0) -0.10 LSS -0
totalorder(-0, 0) -0 LSS 0
totalorder(0, 0.10) 0 LSS 0.10
totalorder(0.10, 0.1) 0.10 LSS 0.1
totalorder(0.1, inf) 0.1 LSS inf
totalorder(inf, snan) inf LSS snan
totalorder(snan, nan) snan LSS nan
compare_decfloat(-nan, -snan) Unordered
compare_decfloat(-snan, -inf) Unordered
compare_decfloat(-inf, -0.1) -inf LSS -0.1
compare_decfloat(-0.1, -0.10) -0.1 LSS -0.10
compare_decfloat(-0.10, -0) -0.10 LSS -0
compare_decfloat(-0, 0) -0 LSS 0
compare_decfloat(0, 0.10) 0 LSS 0.10
compare_decfloat(0.10, 0.1) 0.10 LSS 0.1
compare_decfloat(0.1, inf) 0.1 LSS inf
compare_decfloat(inf, snan) Unordered
compare_decfloat(snan, nan) Unordered
arithmetic: -nan vs to -snan: -nan EQU -snan
arithmetic: -snan vs to -inf: -snan EQU -inf
arithmetic: -inf vs to -0.1: -inf LSS -0.1
arithmetic: -0.1 vs to -0.10: -0.1 EQU -0.10
arithmetic: -0.10 vs to -0: -0.10 LSS -0
arithmetic: -0 vs to 0: -0 EQU 0
arithmetic: 0 vs to 0.10: 0 LSS 0.10
arithmetic: 0.10 vs to 0.1: 0.10 EQU 0.1
arithmetic: 0.1 vs to inf: 0.1 LSS inf
arithmetic: inf vs to snan: inf EQU snan
arithmetic: snan vs to nan: snan EQU nan
"""
@pytest.mark.version('>=4.0')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout

View File

@ -0,0 +1,55 @@
#coding:utf-8
"""
ID: int128.agregate-functions
ISSUE: 6585
JIRA: CORE-6344
TITLE: Basic test for aggregation functions against INT128 datatype
DESCRIPTION:
Test verifies https://github.com/FirebirdSQL/firebird/commit/17b287f9ce882e27de76c416175ad0453520528e
(Postfix for CORE-6344 - fixed SUM() & AVG()).
FBTEST: functional.datatypes.int128-agregate-functions
"""
import pytest
from firebird.qa import *
db = db_factory()
test_script = """
set list on;
recreate table test(i128_least int128 , i128_great int128);
insert into test(i128_least, i128_great) values(-170141183460469231731687303715884105728, 170141183460469231731687303715884105727);
select sum(i128_least) as agg_sum_a from test;
select sum(i128_great) as agg_sum_b from test;
select avg(i128_least) as agg_avg_a from test;
select avg(i128_great) as agg_avg_b from test;
select min(i128_least) as agg_min_a from test;
select min(i128_great) as agg_min_b from test;
select max(i128_least) as agg_max_a from test;
select max(i128_great) as agg_max_b from test;
"""
act = isql_act('db', test_script)
expected_stdout = """
AGG_SUM_A -170141183460469231731687303715884105728
AGG_SUM_B 170141183460469231731687303715884105727
AGG_AVG_A -170141183460469231731687303715884105728
AGG_AVG_B 170141183460469231731687303715884105727
AGG_MIN_A -170141183460469231731687303715884105728
AGG_MIN_B 170141183460469231731687303715884105727
AGG_MAX_A -170141183460469231731687303715884105728
AGG_MAX_B 170141183460469231731687303715884105727
"""
@pytest.mark.version('>=4.0')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout

View File

@ -0,0 +1,118 @@
#coding:utf-8
"""
ID: miscelan.binding
TITLE: Test ability for DECFLOAT values to be represented as other data types using LEGACY keyword.
DESCRIPTION:
We check here that values from DECFLOAT will be actually converted to legacy datatypes
according to following table from sql.extensions\README.set_bind.md:
----------------------------------------------------------
| Native datatype | Legacy datatype |
|--------------------------|-----------------------------|
| BOOLEAN | CHAR(5) |
| DECFLOAT | DOUBLE PRECISION |
| NUMERIC(38) | NUMERIC(18) |
| TIME WITH TIME ZONE | TIME WITHOUT TIME ZONE |
| TIMESTAMP WITH TIME ZONE | TIMESTAMP WITHOUT TIME ZONE |
----------------------------------------------------------
SQLDA must contain the same datatypes when we use either explicit rule or LEGACY keyword.
Checked on 4.0.0.1691 SS: 1.113s.
WARNING, 11.03.2020.
Test verifies binding of TIME WITH TIMEZONE data and uses America/Los_Angeles timezone.
But there is daylight saving time in the USA, they change clock at the begining of March.
For this reason query like: "select time '10:00 America/Los_Angeles' from ..." will return
different values depending on current date. For example, if we are in Moscow timezone then
returned value will be either 20:00 in February or 21:00 in March.
Result for other timezone (e.g. Tokyo) will be differ, etc.
For this reason, special replacement will be done in 'substitution' section: we replace
value of hours with '??' because it is no matter what's the time there, we have to ensure
only the ability to work with such time using SET BIND clause.
FBTEST: functional.datatypes.miscelan-binding
"""
import pytest
from firebird.qa import *
db = db_factory()
test_script = """
set list on;
set sqlda_display on;
-- Legacy, explicit and implicit:
set bind of boolean to char(5);
select not false and true as "check_bind_bool_to_char" from rdb$database;
set bind of boolean to legacy;
select not false and true as "check_bind_bool_to_legacy" from rdb$database;
set bind of decfloat to double precision;
select 3.141592653589793238462643383279502884197169399375105820974944592307816406286 as "check_bind_decfloat_to_double" from rdb$database;
set bind of decfloat to legacy;
select 3.141592653589793238462643383279502884197169399375105820974944592307816406286 as "check_bind_decfloat_to_legacy" from rdb$database;
set bind of numeric(38) to numeric(18); -- this is mentioned in http://tracker.firebirdsql.org/browse/CORE-6057
select 3.141592653589793238462643383279502884197169399375105820974944592307816406286 as "check_bind_n38_to_n18" from rdb$database;
set bind of numeric(38) to legacy;
select 3.141592653589793238462643383279502884197169399375105820974944592307816406286 as "check_bind_n38_to_legacy" from rdb$database;
set bind of time with time zone to time without time zone;
select time '10:00 America/Los_Angeles' as "check_bind_time_with_zone_to_time" from rdb$database;
set bind of time with time zone to legacy;
select time '10:00 America/Los_Angeles' as "check_bind_time_with_zone_to_legacy" from rdb$database;
set bind of timestamp with time zone to timestamp without time zone;
select timestamp '2018-01-01 12:00 GMT' as "check_bind_timestamp_with_zone_to_timestamp" from rdb$database;
set bind of timestamp with time zone to legacy;
select timestamp '2018-01-01 12:00 GMT' as "check_bind_timestamp_with_zone_to_legacy" from rdb$database;
"""
act = isql_act('db', test_script, substitutions=[ (' \d{2}:00:00.0000', ' ??:00:00.0000'), ('charset.*', ''), ('.*alias:.*', ''), ('^((?!(sqltype|check_bind_)).)*$',''), ('[ \t]+',' ') ])
expected_stdout = """
01: sqltype: 452 TEXT Nullable scale: 0 subtype: 0 len: 5
check_bind_bool_to_char TRUE
01: sqltype: 452 TEXT Nullable scale: 0 subtype: 0 len: 5
check_bind_bool_to_legacy TRUE
01: sqltype: 480 DOUBLE scale: 0 subtype: 0 len: 8
check_bind_decfloat_to_double 3.141592653589793
01: sqltype: 480 DOUBLE scale: 0 subtype: 0 len: 8
check_bind_decfloat_to_legacy 3.141592653589793
01: sqltype: 480 DOUBLE scale: 0 subtype: 0 len: 8
check_bind_n38_to_n18 3.141592653589793
01: sqltype: 480 DOUBLE scale: 0 subtype: 0 len: 8
check_bind_n38_to_legacy 3.141592653589793
01: sqltype: 560 TIME scale: 0 subtype: 0 len: 4
check_bind_time_with_zone_to_time ??:00:00.0000
01: sqltype: 560 TIME scale: 0 subtype: 0 len: 4
check_bind_time_with_zone_to_legacy ??:00:00.0000
01: sqltype: 510 TIMESTAMP scale: 0 subtype: 0 len: 8
check_bind_timestamp_with_zone_to_timestamp 2018-01-01 ??:00:00.0000
01: sqltype: 510 TIMESTAMP scale: 0 subtype: 0 len: 8
check_bind_timestamp_with_zone_to_legacy 2018-01-01 ??:00:00.0000
"""
@pytest.mark.version('>=4.0')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout