Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Blargian
Copy link
Member

Splits #86839.
Moves type conversion functions docs into the source code. Part 2/3.

Changelog category (leave one):

  • Documentation (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Copy link

clickhouse-gh bot commented Sep 12, 2025

Workflow [PR], commit [37e4e6c]

Summary:

job_name test_name status info comment
Integration tests (amd_binary, 1/5) failure
test_storage_kafka/test_batch_fast.py::test_kafka_no_holes_when_write_suffix_failed[generate_old_create_table_query] FAIL
Integration tests (amd_tsan, 4/6) failure
test_storage_kafka/test_batch_fast.py::test_kafka_no_holes_when_write_suffix_failed[generate_old_create_table_query] FAIL

@clickhouse-gh clickhouse-gh bot added the pr-documentation Documentation PRs for the specific code PR label Sep 12, 2025
@Blargian Blargian marked this pull request as ready for review September 19, 2025 09:33
@Blargian Blargian requested a review from rschu1ze September 19, 2025 09:33
@rschu1ze rschu1ze self-assigned this Sep 19, 2025
factory.registerFunction<FunctionReinterpret>();
FunctionDocumentation::Description description_reinterpretAsUInt8 = R"(
Performs byte reinterpretation by treating the input value as a value of type UInt8.
Unlike [`CAST`](#cast), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is meaningless.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meaningless --> undefined


factory.registerFunction<FunctionReinterpret>();
FunctionDocumentation::Description description_reinterpretAsUInt8 = R"(
Performs byte reinterpretation by treating the input value as a value of type UInt8.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler: Reinterprets the input value as a value of type UInt8.

In l. 544: Value to reinterpret as UInt8.

Please apply the same kind of changes also for the other functions in this file.

"Usage example",
R"(
SELECT
toInt8(257) AS x,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange example. toInt8(257) produces an internal overflow.

Can we do this (basically the same example as in docs of function CAST):

SELECT
    toInt8(-1) AS val,
    toTypeName(val),
    reinterpretAsUInt8(val) AS res,
    toTypeName(res);

?

There will still be an overflow but during re-interpretation as UInt8 ... which is what the description above warns about.

factory.registerFunction<FunctionReinterpretAsFloat64>(documentation_reinterpretAsFloat64);

FunctionDocumentation::Description description_reinterpretAsDate = R"(
Accepts a string, fixed string or numeric value and interprets the bytes as a number in host order (little endian). It returns a date from the interpreted number as the number of days since the beginning of the Unix Epoch.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just: Reinterprets the input value as a Date value (assuming little endian order) which is the number of days since the beginning of the Unix epoch 1970-01-01.

factory.registerFunction<FunctionReinterpretAsDate>(documentation_reinterpretAsDate);

FunctionDocumentation::Description description_reinterpretAsDateTime = R"(
These functions accept a string and interpret the bytes placed at the beginning of the string as a number in host order (little endian). Returns a date with time interpreted as the number of seconds since the beginning of the Unix Epoch.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

factory.registerFunction<FunctionReinterpretAsUUID>(documentation_reinterpretAsUUID);

FunctionDocumentation::Description description_reinterpretAsString = R"(
This function accepts a number, date or date with time and returns a string containing bytes representing the corresponding value in host order (little endian). Null bytes are dropped from the end. For example, a UInt32 type value of 255 is a string that is one byte long.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reinterprets the input value as a string (assuming little endian order). Null bytes at the end are ignored, for example, the function returns for UInt32 value 255 a string with a single character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-documentation Documentation PRs for the specific code PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants