Skip to content

Commit

Permalink
Add .data files usage in from_text tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Dec 2, 2024
1 parent e87af0c commit 3c5687a
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 73 deletions.
18 changes: 13 additions & 5 deletions contrib/try_convert/generate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ def remove_empty_lines(t):

test_load_data = '-- LOAD DATA\n'

test_load_data += f'CREATE TABLE tt_temp (v text) DISTRIBUTED BY (v);\n'

def copy_data(table_name, filename):
return f'COPY {table_name} from \'@abs_srcdir@/{filename}\';'

for type_name in supported_types:

table_name = f'tt_{type_name}'
Expand All @@ -159,7 +164,7 @@ def remove_empty_lines(t):

filename = f'data/{table_name}.data'

test_load_data += f'COPY {table_name} from \'@abs_srcdir@/{filename}\';\n'
test_load_data += copy_data(table_name, filename) + '\n'


## GET DATA
Expand Down Expand Up @@ -197,15 +202,18 @@ def create_test(source_name, target_name, test_data):

for type_name in supported_types:
test_type_data = get_data(type_name)
test_text_data = f'(select v::text from {test_type_data}) as t(v)'
test_corrupted_text_data = f'(select (\'!@#%^&*\' || v::text || \'!@#%^&*\') from {test_type_data}) as t(v)'

load_text_data_text = copy_data("tt_temp", f'data/tt_{type_name}.data')
test_text_data = 'tt_temp'

test_corrupted_text_data = f'(select (\'!@#%^&*\' || v || \'!@#%^&*\') from {test_type_data}) as t(v)'

to_text_in, to_text_out = create_test(type_name, 'text', test_type_data)
from_text_in, from_text_out = create_test('text', type_name, test_text_data)
from_corrupted_text_in, from_corrupted_text_out = create_test('text', type_name, test_corrupted_text_data)

text_tests_in += [to_text_in, from_text_in, from_corrupted_text_in]
text_tests_out += [to_text_out, from_text_out, from_corrupted_text_out]
text_tests_in += [to_text_in, load_text_data_text, from_text_in, from_corrupted_text_in]
text_tests_out += [to_text_out, load_text_data_text, from_text_out, from_corrupted_text_out]

# print(text_tests_in[0])
# print(text_tests_in[1])
Expand Down
86 changes: 52 additions & 34 deletions contrib/try_convert/input/try_convert.source
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ $func$
$func$;

-- LOAD DATA
CREATE TABLE tt_temp (v text) DISTRIBUTED BY (v);
CREATE TABLE tt_int8 (v int8) DISTRIBUTED BY (v);
COPY tt_int8 from '@abs_srcdir@/data/tt_int8.data';
CREATE TABLE tt_int4 (v int4) DISTRIBUTED BY (v);
Expand Down Expand Up @@ -219,56 +220,73 @@ COPY tt_text from '@abs_srcdir@/data/tt_text.data';

-- TEXT TESTS
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_int8) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int8) as v1, try_convert_by_sql(v, NULL::int8) as v2 from (select v::text from tt_int8) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int8) as v1, try_convert_by_sql(v, NULL::int8) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_int8) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_int8.data';
select * from (select try_convert(v, NULL::int8) as v1, try_convert_by_sql(v, NULL::int8) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int8) as v1, try_convert_by_sql(v, NULL::int8) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_int8) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_int4) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int4) as v1, try_convert_by_sql(v, NULL::int4) as v2 from (select v::text from tt_int4) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int4) as v1, try_convert_by_sql(v, NULL::int4) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_int4) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_int4.data';
select * from (select try_convert(v, NULL::int4) as v1, try_convert_by_sql(v, NULL::int4) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int4) as v1, try_convert_by_sql(v, NULL::int4) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_int4) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_int2) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int2) as v1, try_convert_by_sql(v, NULL::int2) as v2 from (select v::text from tt_int2) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int2) as v1, try_convert_by_sql(v, NULL::int2) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_int2) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_int2.data';
select * from (select try_convert(v, NULL::int2) as v1, try_convert_by_sql(v, NULL::int2) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int2) as v1, try_convert_by_sql(v, NULL::int2) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_int2) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_float8) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::float8) as v1, try_convert_by_sql(v, NULL::float8) as v2 from (select v::text from tt_float8) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::float8) as v1, try_convert_by_sql(v, NULL::float8) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_float8) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_float8.data';
select * from (select try_convert(v, NULL::float8) as v1, try_convert_by_sql(v, NULL::float8) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::float8) as v1, try_convert_by_sql(v, NULL::float8) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_float8) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_float4) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::float4) as v1, try_convert_by_sql(v, NULL::float4) as v2 from (select v::text from tt_float4) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::float4) as v1, try_convert_by_sql(v, NULL::float4) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_float4) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_float4.data';
select * from (select try_convert(v, NULL::float4) as v1, try_convert_by_sql(v, NULL::float4) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::float4) as v1, try_convert_by_sql(v, NULL::float4) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_float4) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_numeric) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::numeric) as v1, try_convert_by_sql(v, NULL::numeric) as v2 from (select v::text from tt_numeric) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::numeric) as v1, try_convert_by_sql(v, NULL::numeric) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_numeric) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_numeric.data';
select * from (select try_convert(v, NULL::numeric) as v1, try_convert_by_sql(v, NULL::numeric) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::numeric) as v1, try_convert_by_sql(v, NULL::numeric) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_numeric) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_bool) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::bool) as v1, try_convert_by_sql(v, NULL::bool) as v2 from (select v::text from tt_bool) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::bool) as v1, try_convert_by_sql(v, NULL::bool) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_bool) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_bool.data';
select * from (select try_convert(v, NULL::bool) as v1, try_convert_by_sql(v, NULL::bool) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::bool) as v1, try_convert_by_sql(v, NULL::bool) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_bool) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_date) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::date) as v1, try_convert_by_sql(v, NULL::date) as v2 from (select v::text from tt_date) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::date) as v1, try_convert_by_sql(v, NULL::date) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_date) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_date.data';
select * from (select try_convert(v, NULL::date) as v1, try_convert_by_sql(v, NULL::date) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::date) as v1, try_convert_by_sql(v, NULL::date) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_date) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_time) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::time) as v1, try_convert_by_sql(v, NULL::time) as v2 from (select v::text from tt_time) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::time) as v1, try_convert_by_sql(v, NULL::time) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_time) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_time.data';
select * from (select try_convert(v, NULL::time) as v1, try_convert_by_sql(v, NULL::time) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::time) as v1, try_convert_by_sql(v, NULL::time) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_time) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_timetz) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timetz) as v1, try_convert_by_sql(v, NULL::timetz) as v2 from (select v::text from tt_timetz) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timetz) as v1, try_convert_by_sql(v, NULL::timetz) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_timetz) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_timetz.data';
select * from (select try_convert(v, NULL::timetz) as v1, try_convert_by_sql(v, NULL::timetz) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timetz) as v1, try_convert_by_sql(v, NULL::timetz) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_timetz) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_timestamp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timestamp) as v1, try_convert_by_sql(v, NULL::timestamp) as v2 from (select v::text from tt_timestamp) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timestamp) as v1, try_convert_by_sql(v, NULL::timestamp) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_timestamp) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_timestamp.data';
select * from (select try_convert(v, NULL::timestamp) as v1, try_convert_by_sql(v, NULL::timestamp) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timestamp) as v1, try_convert_by_sql(v, NULL::timestamp) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_timestamp) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_timestamptz) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timestamptz) as v1, try_convert_by_sql(v, NULL::timestamptz) as v2 from (select v::text from tt_timestamptz) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timestamptz) as v1, try_convert_by_sql(v, NULL::timestamptz) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_timestamptz) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_timestamptz.data';
select * from (select try_convert(v, NULL::timestamptz) as v1, try_convert_by_sql(v, NULL::timestamptz) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::timestamptz) as v1, try_convert_by_sql(v, NULL::timestamptz) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_timestamptz) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_interval) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::interval) as v1, try_convert_by_sql(v, NULL::interval) as v2 from (select v::text from tt_interval) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::interval) as v1, try_convert_by_sql(v, NULL::interval) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_interval) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_interval.data';
select * from (select try_convert(v, NULL::interval) as v1, try_convert_by_sql(v, NULL::interval) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::interval) as v1, try_convert_by_sql(v, NULL::interval) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_interval) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_cidr) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::cidr) as v1, try_convert_by_sql(v, NULL::cidr) as v2 from (select v::text from tt_cidr) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::cidr) as v1, try_convert_by_sql(v, NULL::cidr) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_cidr) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_cidr.data';
select * from (select try_convert(v, NULL::cidr) as v1, try_convert_by_sql(v, NULL::cidr) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::cidr) as v1, try_convert_by_sql(v, NULL::cidr) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_cidr) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_inet) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::inet) as v1, try_convert_by_sql(v, NULL::inet) as v2 from (select v::text from tt_inet) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::inet) as v1, try_convert_by_sql(v, NULL::inet) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_inet) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_inet.data';
select * from (select try_convert(v, NULL::inet) as v1, try_convert_by_sql(v, NULL::inet) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::inet) as v1, try_convert_by_sql(v, NULL::inet) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_inet) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_macaddr) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::macaddr) as v1, try_convert_by_sql(v, NULL::macaddr) as v2 from (select v::text from tt_macaddr) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::macaddr) as v1, try_convert_by_sql(v, NULL::macaddr) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_macaddr) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_macaddr.data';
select * from (select try_convert(v, NULL::macaddr) as v1, try_convert_by_sql(v, NULL::macaddr) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::macaddr) as v1, try_convert_by_sql(v, NULL::macaddr) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_macaddr) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_text) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from (select v::text from tt_text) as t(v)) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from (select ('!@#%^&*' || v::text || '!@#%^&*') from tt_text) as t(v)) as t(v1, v2) where not (v1 = v2);
COPY tt_temp from '@abs_srcdir@/data/tt_text.data';
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from tt_temp) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::text) as v1, try_convert_by_sql(v, NULL::text) as v2 from (select ('!@#%^&*' || v || '!@#%^&*') from tt_text) as t(v)) as t(v1, v2) where not (v1 = v2);
-- FUNCTION TESTS
select * from (select try_convert(v, NULL::int2) as v1, try_convert_by_sql(v, NULL::int2) as v2 from tt_int8) as t(v1, v2) where not (v1 = v2);
select * from (select try_convert(v, NULL::int4) as v1, try_convert_by_sql(v, NULL::int4) as v2 from tt_int8) as t(v1, v2) where not (v1 = v2);
Expand Down
Loading

0 comments on commit 3c5687a

Please sign in to comment.