Skip to content

More precise Integer type inference, and fix #51236#53003

Merged
Avogar merged 19 commits intoClickHouse:masterfrom
Chen768959:fix-51236
Sep 12, 2023
Merged

More precise Integer type inference, and fix #51236#53003
Avogar merged 19 commits intoClickHouse:masterfrom
Chen768959:fix-51236

Conversation

@Chen768959
Copy link
Copy Markdown
Contributor

@Chen768959 Chen768959 commented Aug 3, 2023

Changelog category (leave one):

  • Improvement

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

More precise Integer type inference, fix #51236

Documentation entry for user-facing changes

FieldToDataType<on_error>::operator() (const Array & x) and FieldToDataType<on_error>::operator() (const Map & map) will be able to recognize whether an UInt64 is unsigned, signed, or both, which means that an Int will have multiple possible types. This will make the getLeastSupertype function more accurate.
Example :
select [-4741124612489978151, -3236599669630092879, 5607475129431807682]
'-4741124612489978151' is Int64, '-3236599669630092879' is Int64, '5607475129431807682' is UInt64 or Int64.
So, their least supertype is Int64

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 3, 2023
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-improvement Pull request with some product improvements label Aug 3, 2023
@robot-ch-test-poll4
Copy link
Copy Markdown
Contributor

robot-ch-test-poll4 commented Aug 3, 2023

This is an automated comment for commit 5c2fd38 with description of existing statuses. It's updated for the latest CI running
The full report is available here
The overall status of the commit is 🟢 success

Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help🟢 success
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR🟢 success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process🟢 success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help🟢 success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub🟢 success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here🟢 success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc🟢 success
Install packagesChecks that the built packages are installable in a clear environment🟢 success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests🟢 success
Mergeable CheckChecks if all other necessary checks are successful🟢 success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests🟢 success
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub🟢 success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS🟢 success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool🟢 success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed🟢 success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🟢 success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🟢 success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors🟢 success
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report🟢 success
Unit testsRuns the unit tests for different release types🟢 success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts🟢 success

fix style.
if UInt64(possible: Int64), UInt64(possible: Int64) = UInt64, UInt64
if Int64(possible: UInt32), Int64(possible: UInt32) = Int64, Int64
…if it is causing the zk validation failure issue.
@Avogar Avogar self-assigned this Aug 7, 2023
@Chen768959 Chen768959 force-pushed the fix-51236 branch 2 times, most recently from ca71c39 to 12d262e Compare August 9, 2023 15:00
@Chen768959
Copy link
Copy Markdown
Contributor Author

@Avogar I have completed all the modifications, and I believe this pull request is now ready for review. I would greatly appreciate it if you could take a look when you have some free time.

@Avogar
Copy link
Copy Markdown
Member

Avogar commented Aug 11, 2023

Sure, I will look at it today

@Chen768959
Copy link
Copy Markdown
Contributor Author

Thank you for the review and suggestions! I will make the necessary changes promptly.

@Chen768959 Chen768959 force-pushed the fix-51236 branch 3 times, most recently from 6cd6c23 to 5719505 Compare August 12, 2023 17:15
@Chen768959 Chen768959 force-pushed the fix-51236 branch 2 times, most recently from 22fe673 to 74485f3 Compare August 15, 2023 18:35
@Avogar
Copy link
Copy Markdown
Member

Avogar commented Sep 6, 2023

Sorry for long review, I was on vacation.
I see you changed the approach, so we don't change getLeastSupertype anymore. That's a really good Idea, I like it. Let me check the details

DataTypes element_types;
element_types.reserve(x.size());

auto checkIfConversionSigned = [&](bool& has_signed_int, bool& has_uint64, bool& uint64_could_opposite,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see we have 2 identical lambdas here and during Map processing. Let's move this code to a separate function in anonimous namespace in this cpp file.

Copy link
Copy Markdown
Member

@Avogar Avogar Sep 6, 2023

Choose a reason for hiding this comment

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

And also the logic is the same here and later during Map processing. Maybe we can extract all this logic to a separate function?
Like

void convertUInt64ToInt64IfPossible(DataTypes & data_types);

So the code here will look like this:

...
for (const Field & elem : x)
    element_types.emplace_back(applyVisitor(*this, elem));
convertUInt64ToInt64IfPossible(element_types);
...

It will be much better for future readers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll handle it.

@Chen768959
Copy link
Copy Markdown
Contributor Author

Sorry for long review, I was on vacation.

No worries, I hope you had a great vacation!

Copy link
Copy Markdown
Member

@Avogar Avogar left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the contribution!

@Avogar Avogar merged commit 5354af0 into ClickHouse:master Sep 12, 2023
@Avogar
Copy link
Copy Markdown
Member

Avogar commented Sep 12, 2023

I just realized that this approach with changes only in FieldToDataType is actually not general, because it won't work with nested types and some functions like map/tuple:

:) select [[-4741124612489978151, 1, -3236599669630092879], [2, 5607475129431807682]]

Received exception:
Code: 386. DB::Exception: There is no supertype for types UInt64, Int64 because some of them are signed integers and some are unsigned integers, but there is no signed integer type, that can exactly represent all required unsigned integer values: While processing [[-4741124612489978151, 1, -3236599669630092879], [2, 5607475129431807682]]. (NO_COMMON_TYPE)

:) select map(-4741124612489978151, 1, -3236599669630092879, 2, 5607475129431807682, 3)

Received exception:
Code: 386. DB::Exception: There is no supertype for types UInt64, Int64 because some of them are signed integers and some are unsigned integers, but there is no signed integer type, that can exactly represent all required unsigned integer values: While processing map(-4741124612489978151, 1, -3236599669630092879, 2, 5607475129431807682, 3). (NO_COMMON_TYPE)

I think we can get back to the approach with changes in getLeastSuperType and separate constructor for DataTypeNumber (yes, I didn't like it, but as I remember there were problems with separate type because of typeid_cast, so I think it's ok).

@Avogar
Copy link
Copy Markdown
Member

Avogar commented Sep 12, 2023

No worries, I will do such changes by myself, so, no need to do anything, I just wanted you to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integer type inference seems confusing

4 participants