Skip to content

Only use Field::safeGet - Field::get prone to type punning - #68135

Merged
rschu1ze merged 8 commits into
masterfrom
refactor-field-get
Aug 12, 2024
Merged

rschu1ze merged 8 commits into
masterfrom
refactor-field-get

Conversation

@yakov-olkhovskiy

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 10, 2024
@robot-ch-test-poll3

robot-ch-test-poll3 commented Aug 10, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 5c8665c with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
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
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ 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. Integration 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
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
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

Comment on lines -124 to +136
std::erase_if(tuple, [&](auto & child)
auto & tuple = tuple_literal->value.safeGet<Tuple>();
if (tuple.size() > 1)
{
return tuple.size() > 1 && !shardContains(child, name, data);
});
Tuple new_tuple;

for (auto & child : tuple)
if (shardContains(child, name, data))
new_tuple.emplace_back(std::move(child));

if (new_tuple.empty())
new_tuple.emplace_back(std::move(tuple.back()));

tuple_literal->value = std::move(new_tuple);
}

@yakov-olkhovskiy yakov-olkhovskiy Aug 12, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

original tuple.size() > 1 will not work in std::erase_if - refactored

Comment on lines 470 to 471
{
res = AggregateFunctionStateData();
res.get<AggregateFunctionStateData &>().name = type_string;
{
WriteBufferFromString buffer(res.get<AggregateFunctionStateData &>().data);
func->serialize(data[n], buffer, version);
}
res = operator[](n);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

duplicated code - refactored

if (which_type.isDate() && which_from_type.isDateTime())
{
return static_cast<UInt16>(static_cast<const DataTypeDateTime &>(*from_type_hint).getTimeZone().toDayNum(src.get<UInt64>()).toUnderType());
return static_cast<UInt16>(static_cast<const DataTypeDateTime &>(*from_type_hint).getTimeZone().toDayNum(src.safeGet<UInt64>()).toUnderType());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

bug found due to this PR - fix Field conversion to IPv4

auto & num_rebalance_assigments = assert_cast<ColumnUInt64 &>(*res_columns[index++]);
auto & is_currently_used = assert_cast<ColumnUInt8 &>(*res_columns[index++]);
auto & last_used = assert_cast<ColumnDateTime64 &>(*res_columns[index++]);
auto & last_used = assert_cast<ColumnUInt64 &>(*res_columns[index++]);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

bug found due to this PR - incorrect column type

@rschu1ze rschu1ze self-assigned this Aug 12, 2024
@yakov-olkhovskiy

Copy link
Copy Markdown
Member Author

@rschu1ze this is pretty simple PR despite apparent size - relevant changes - Field::get moved to private, Field::safeGet cleaned up (supposedly), all calls to Field::get outside of Field replaced by Field::safeGet. Couple other fixes are simple and annotated.

Comment thread src/Core/Field.h
/// This function is prone to type punning and should never be used outside of Field class,
/// whenever it is used within this class the stored type should be checked in advance.
template <typename T>
NearestFieldType<std::decay_t<T>> & get()

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.

What about naming

  • get as get_unsafe (or unsafeGet),
  • and safeGet as get
    ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought about this (and it would be much easier refactoring), but I decided that it's better to left it more obvious so whoever uses it would be aware that get is not that simple...

@rschu1ze
rschu1ze added this pull request to the merge queue Aug 12, 2024
Merged via the queue into master with commit 85f63b0 Aug 12, 2024
@rschu1ze
rschu1ze deleted the refactor-field-get branch August 12, 2024 15:17
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Aug 14, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Aug 14, 2024
baibaichen added a commit to Kyligence/ClickHouse that referenced this pull request Aug 15, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Aug 15, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Aug 15, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Aug 15, 2024
baibaichen added a commit to apache/gluten that referenced this pull request Aug 15, 2024
* [GLUTEN-1632][CH]Daily Update Clickhouse Version (20240815)

* Fix Build due to ClickHouse/ClickHouse#68107

* Fix Build due to ClickHouse/ClickHouse#68135

* Fix UT due to ClickHouse/ClickHouse#68135

* Add ut for #2584

- Rebase failed with ClickHouse/ClickHouse#67879, and hence we can remove Kyligence/ClickHouse#454

(cherry picked from commit 583aa8d6566a9e1c0924c1a3ab1d315fcc229fa6)

* Fix CH BUG due to ClickHouse/ClickHouse#68135

see Kyligence/ClickHouse@d87dbba

* Resolve conflict

---------

Co-authored-by: kyligence-git <[email protected]>
Co-authored-by: Chang Chen <[email protected]>
baibaichen added a commit to Kyligence/ClickHouse that referenced this pull request Aug 15, 2024
kyligence-git pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 15, 2024
sharkdtu pushed a commit to sharkdtu/gluten that referenced this pull request Nov 11, 2024
)

* [GLUTEN-1632][CH]Daily Update Clickhouse Version (20240815)

* Fix Build due to ClickHouse/ClickHouse#68107

* Fix Build due to ClickHouse/ClickHouse#68135

* Fix UT due to ClickHouse/ClickHouse#68135

* Add ut for apache#2584

- Rebase failed with ClickHouse/ClickHouse#67879, and hence we can remove Kyligence/ClickHouse#454

(cherry picked from commit 583aa8d6566a9e1c0924c1a3ab1d315fcc229fa6)

* Fix CH BUG due to ClickHouse/ClickHouse#68135

see Kyligence/ClickHouse@d87dbba

* Resolve conflict

---------

Co-authored-by: kyligence-git <[email protected]>
Co-authored-by: Chang Chen <[email protected]>
yl-lisen added a commit to timeplus-io/proton that referenced this pull request Dec 21, 2024
* Add aggregation function for Largest-Triangle-Three-Buckets (#53145)

* Added a simple lttb aggregate function

* Added support for multiple datatypes

* Added support for Date and Date32, updated LTTBData struct

* Updated code to handle bucket size 0 and 1

* Added sort for LTTBData

* Added tests and documentation

* Added some code style fixes

* Added function to new func ref file

* Removed function from new func ref file

* Apply suggestions from code review

* Updated unit tests

* updated LTTB data code

* Minor style fixes

* Updated code with std sort

* updated tests

* Renamed lttb to largestTriangleThreeBuckets

* Added alias lttb

---------

Co-authored-by: Alexey Milovidov <[email protected]>

* ClickHouse/ClickHouse#56350 (partial)

* fix: split lttb bucket strategy, first bucket and last bucket should only contain single point (#57003)

* fix: split lttb bucket policy, first bucket and last bucket should only
contain single point

* add comments and modify the corresponding query test

* style: update code format

* style: remove useless comments

* feat: add lttb bucket size test

* fix: typo, duplicate sql

* Merge pull request #62646 from Algunenano/i_like_triangles

Fix crash in largestTriangleThreeBuckets

* ClickHouse/ClickHouse#60469 (partial)

* ClickHouse/ClickHouse#68135 (partial)

* Merge pull request #73172 from ucasfl/fix-ubsan

Fix UBSAN in largestTriangleThreeBuckets

* fixes

---------

Co-authored-by: Sinan <[email protected]>
Co-authored-by: Alexey Milovidov <[email protected]>
Co-authored-by: FFish <[email protected]>
Co-authored-by: Raúl Marín <[email protected]>
Co-authored-by: Yarik Briukhovetskyi <[email protected]>
yl-lisen added a commit to timeplus-io/proton that referenced this pull request Dec 21, 2024
* Add aggregation function for Largest-Triangle-Three-Buckets (#53145)

* Added a simple lttb aggregate function

* Added support for multiple datatypes

* Added support for Date and Date32, updated LTTBData struct

* Updated code to handle bucket size 0 and 1

* Added sort for LTTBData

* Added tests and documentation

* Added some code style fixes

* Added function to new func ref file

* Removed function from new func ref file

* Apply suggestions from code review

* Updated unit tests

* updated LTTB data code

* Minor style fixes

* Updated code with std sort

* updated tests

* Renamed lttb to largestTriangleThreeBuckets

* Added alias lttb

---------

Co-authored-by: Alexey Milovidov <[email protected]>

* ClickHouse/ClickHouse#56350 (partial)

* fix: split lttb bucket strategy, first bucket and last bucket should only contain single point (#57003)

* fix: split lttb bucket policy, first bucket and last bucket should only
contain single point

* add comments and modify the corresponding query test

* style: update code format

* style: remove useless comments

* feat: add lttb bucket size test

* fix: typo, duplicate sql

* Merge pull request #62646 from Algunenano/i_like_triangles

Fix crash in largestTriangleThreeBuckets

* ClickHouse/ClickHouse#60469 (partial)

* ClickHouse/ClickHouse#68135 (partial)

* Merge pull request #73172 from ucasfl/fix-ubsan

Fix UBSAN in largestTriangleThreeBuckets

* fixes
yl-lisen added a commit to timeplus-io/proton that referenced this pull request Dec 21, 2024
* Add aggregation function for Largest-Triangle-Three-Buckets (#53145)

* Added a simple lttb aggregate function

* Added support for multiple datatypes

* Added support for Date and Date32, updated LTTBData struct

* Updated code to handle bucket size 0 and 1

* Added sort for LTTBData

* Added tests and documentation

* Added some code style fixes

* Added function to new func ref file

* Removed function from new func ref file

* Apply suggestions from code review

* Updated unit tests

* updated LTTB data code

* Minor style fixes

* Updated code with std sort

* updated tests

* Renamed lttb to largestTriangleThreeBuckets

* Added alias lttb

---------

Co-authored-by: Alexey Milovidov <[email protected]>

* ClickHouse/ClickHouse#56350 (partial)

* fix: split lttb bucket strategy, first bucket and last bucket should only contain single point (#57003)

* fix: split lttb bucket policy, first bucket and last bucket should only
contain single point

* add comments and modify the corresponding query test

* style: update code format

* style: remove useless comments

* feat: add lttb bucket size test

* fix: typo, duplicate sql

* Merge pull request #62646 from Algunenano/i_like_triangles

Fix crash in largestTriangleThreeBuckets

* ClickHouse/ClickHouse#60469 (partial)

* ClickHouse/ClickHouse#68135 (partial)

* Merge pull request #73172 from ucasfl/fix-ubsan

Fix UBSAN in largestTriangleThreeBuckets

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

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants