Skip to content

Commit

Permalink
Add citext test
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Dec 2, 2024
1 parent ed208e0 commit 69c0ea4
Show file tree
Hide file tree
Showing 4 changed files with 676 additions and 56 deletions.
70 changes: 70 additions & 0 deletions contrib/try_convert/data/tt_citext.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
All the world's a stage,
And all the men and women merely players;
They have their exits and their entrances,
And one man in his time plays many parts,
His acts being seven ages. At first, the infant,
Mewling and puking in the nurse's arms.
Then the whining schoolboy, with his satchel
And shining morning face, creeping like snail
Unwillingly to school. And then the lover,
Sighing like furnace, with a woeful ballad
Made to his mistress' eyebrow. Then a soldier,
Full of strange oaths and bearded like the pard,
Jealous in honor, sudden and quick in quarrel,
Seeking the bubble reputation
Even in the cannon's mouth. And then the justice,
In fair round belly with good capon lined,
With eyes severe and beard of formal cut,
Full of wise saws and modern instances;
And so he plays his part. The sixth age shifts
Into the lean and slippered pantaloon,
With spectacles on nose and pouch on side;
His youthful hose, well saved, a world too wide
For his shrunk shank, and his big manly voice,
Turning again toward childish treble, pipes
And whistles in his sound. Last scene of all,
That ends this strange eventful history,
Is second childishness and mere oblivion,
Sans teeth, sans eyes, sans taste, sans everything.

std::to_string
C++ Strings library std::basic_string
Defined in header <string>
std::string to_string( int value );
std::string to_string( long value );
std::string to_string( long long value );
std::string to_string( unsigned value );
std::string to_string( unsigned long value );
std::string to_string( unsigned long long value );
std::string to_string( float value );
std::string to_string( double value );
std::string to_string( long double value );
Converts a numeric value to std::string.

Let buf be an internal to the conversion functions buffer, sufficiently large to contain the result of conversion.

1) Converts a signed integer to a string as if by std::sprintf(buf, "%d", value).
2) Converts a signed integer to a string as if by std::sprintf(buf, "%ld", value).
3) Converts a signed integer to a string as if by std::sprintf(buf, "%lld", value).
4) Converts an unsigned integer to a string as if by std::sprintf(buf, "%u", value).
5) Converts an unsigned integer to a string as if by std::sprintf(buf, "%lu", value).
6) Converts an unsigned integer to a string as if by std::sprintf(buf, "%llu", value).
7,8) Converts a floating point value to a string as if by std::sprintf(buf, "%f", value).
9) Converts a floating point value to a string as if by std::sprintf(buf, "%Lf", value).
(until C++26)
1-9) Converts a numeric value to a string as if by std::format("{}", value).
(since C++26)
Parameters
Return value
A string holding the converted value.

Exceptions
May throw std::bad_alloc from the std::string constructor.

Notes
With floating point types std::to_string may yield unexpected results as the number of significant digits in the returned string can be zero, see the example.
The return value may differ significantly from what std::cout prints by default, see the example.
std::to_string relies on the current C locale for formatting purposes, and therefore concurrent calls to std::to_string from multiple threads may result in partial serialization of calls.
The results of overloads for integer types do not rely on the current C locale, and thus implementations generally avoid access to the current C locale in these overloads for both correctness and performance. However, such avoidance is not guaranteed by the standard.
(until C++26)
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
66 changes: 52 additions & 14 deletions contrib/try_convert/generate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,34 @@
# # 'tsvector',
# # 'txid_snapshot',
# 'uuid',

'citext',
]

uncomparable_types = [
'json',
'xml',
]

extensions = [
'citext'
]

extension_types = [
'citext'
]

extension_casts = [
('citext', 'text'),
('citext', 'varchar'),
('citext', 'bpchar'),
('text', 'citext'),
('varchar', 'citext'),
('bpchar', 'citext'),
('boolean', 'citext'),
('inet', 'citext'),
]

print('Supported types:', ' '.join(supported_types))


Expand Down Expand Up @@ -80,7 +101,12 @@ def remove_empty_lines(t):
if name in supported_types:
supported_types_count += 1

print(f'Types found: {len(type_id_name)}, supported: {supported_types_count}')
supported_extension_types_count = 0
for name in extension_types:
if name in extension_types:
supported_extension_types_count += 1

print(f'Types found: {len(type_id_name)}, supported: {supported_types_count}, from ext: {len(extension_types)}, from ext sup {supported_extension_types_count}')


### GET CONVERTS
Expand Down Expand Up @@ -116,6 +142,12 @@ def remove_empty_lines(t):
f'-- end_ignore\n' \
f'\n' \

for extension in extensions:
test_header += \
f'-- start_ignore\n' \
f'CREATE EXTENSION IF NOT EXISTS {extension};\n' \
f'-- end_ignore\n' \

test_footer = 'reset search_path;'


Expand Down Expand Up @@ -157,6 +189,7 @@ 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'
test_load_data += f'CREATE TABLE tt_temp_citext (v citext) DISTRIBUTED BY (v);\n'

def copy_data(table_name, filename, type_name):
return f'DELETE FROM tt_temp;' \
Expand Down Expand Up @@ -209,20 +242,24 @@ def create_test(source_name, target_name, test_data):
text_tests_in = []
text_tests_out = []

for type_name in supported_types:
test_type_data = get_data(type_name)
text_types = [('text', 'tt_temp'), ('citext', 'tt_temp_citext')]

for text_type, text_type_table in text_types:

load_text_data_text = f'DELETE FROM tt_temp; COPY tt_temp from \'@abs_srcdir@/data/tt_{type_name}.data\';'
test_text_data = 'tt_temp'
for type_name in supported_types:

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

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)
load_text_data_text = f'DELETE FROM {text_type_table}; COPY {text_type_table} from \'@abs_srcdir@/data/tt_{type_name}.data\';'

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]
test_corrupted_text_data = f'(select (\'!@#%^&*\' || v || \'!@#%^&*\') from {text_type_table}) as t(v)'

to_text_in, to_text_out = create_test(type_name, text_type, test_type_data)
from_text_in, from_text_out = create_test(text_type, type_name, text_type_table)
from_corrupted_text_in, from_corrupted_text_out = create_test(text_type, type_name, test_corrupted_text_data)

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 All @@ -233,10 +270,11 @@ def create_test(source_name, target_name, test_data):
function_tests_in = []
function_tests_out = []

for (source_id, target_id, method) in casts:
type_casts = [(type_id_name[source_id], type_id_name[target_id]) for (source_id, target_id, method) in casts] \
+ extension_casts

for source_name, target_name in type_casts:

source_name = type_id_name[source_id]
target_name = type_id_name[target_id]
test_data = get_data(source_name)

if (source_name not in supported_types or target_name not in supported_types):
Expand Down
Loading

0 comments on commit 69c0ea4

Please sign in to comment.