Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mode fot topK/topKWeighed function to also include count/error statistics #54508

Merged

Conversation

UnamedRus
Copy link
Contributor

@UnamedRus UnamedRus commented Sep 11, 2023

Changelog category (leave one):

  • New Feature

Fix for #42029

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

topK/topKWeighed support mode, which return count of values and it's error.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

SELECT
    topK(10, 900, 'include_statistics')(number % 3000) AS top,
    top.1 AS key,
    tupleElement(top, 'count') AS cnt_arr,
    tupleElement(top, 'error') AS err_arr
FROM numbers_mt(10000000)
FORMAT Vertical

Query id: b6d68539-5cb1-4fa5-812c-bc331c7c61dc

Row 1:
──────
top:     [(581,3334,0),(160,3334,0),(666,3334,0),(175,3334,0),(305,3334,0),(378,3334,0),(124,3334,0),(794,3334,0),(833,3334,0),(688,3334,0)]
key:     [581,160,666,175,305,378,124,794,833,688]
cnt_arr: [3334,3334,3334,3334,3334,3334,3334,3334,3334,3334]
err_arr: [0,0,0,0,0,0,0,0,0,0]

SELECT
    topK(10, 900, 'include_statistics')((number % 300, CAST(number % 30, 'DateTime'), toString(number % 2))) AS top,
    top.1 AS key,
    tupleElement(top, 'count') AS cnt_arr,
    tupleElement(top, 'error') AS err_arr
FROM numbers_mt(10000000)
FORMAT Vertical

Query id: 1f4e1f10-fde7-4608-aed3-3bfa8187f8aa

Row 1:
──────
top:     [((5,'1970-01-01 00:00:05','1'),33334,0),((27,'1970-01-01 00:00:27','1'),33334,0),((85,'1970-01-01 00:00:25','1'),33334,0),((41,'1970-01-01 00:00:11','1'),33334,0),((20,'1970-01-01 00:00:20','0'),33334,0),((50,'1970-01-01 00:00:20','0'),33334,0),((80,'1970-01-01 00:00:20','0'),33334,0),((52,'1970-01-01 00:00:22','0'),33334,0),((2,'1970-01-01 00:00:02','0'),33334,0),((62,'1970-01-01 00:00:02','0'),33334,0)]
key:     [(5,'1970-01-01 00:00:05','1'),(27,'1970-01-01 00:00:27','1'),(85,'1970-01-01 00:00:25','1'),(41,'1970-01-01 00:00:11','1'),(20,'1970-01-01 00:00:20','0'),(50,'1970-01-01 00:00:20','0'),(80,'1970-01-01 00:00:20','0'),(52,'1970-01-01 00:00:22','0'),(2,'1970-01-01 00:00:02','0'),(62,'1970-01-01 00:00:02','0')]
cnt_arr: [33334,33334,33334,33334,33334,33334,33334,33334,33334,33334]
err_arr: [0,0,0,0,0,0,0,0,0,0]

Parameter naming & handling can be better, i guess.

@yakov-olkhovskiy yakov-olkhovskiy self-assigned this Sep 13, 2023
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-feature Pull request with new product feature label Sep 13, 2023
@robot-ch-test-poll4
Copy link
Contributor

robot-ch-test-poll4 commented Sep 13, 2023

This is an automated comment for commit 912b8ba 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
A SyncThere'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
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 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. 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
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ 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
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
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❌ failure
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⏳ pending
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-status-❌ PR with some error/faliure statuses label Sep 13, 2023
@yakov-olkhovskiy yakov-olkhovskiy added the can be tested Allows running workflows for external contributors label Sep 27, 2023
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-status-⏳ PR with some pending statuses and removed pr-status-❌ PR with some error/faliure statuses labels Sep 27, 2023
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-status-❌ PR with some error/faliure statuses and removed pr-status-⏳ PR with some pending statuses labels Sep 27, 2023
Copy link
Member

@yakov-olkhovskiy yakov-olkhovskiy left a comment

Choose a reason for hiding this comment

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

overall looks good but it would be nice to add some tests

src/AggregateFunctions/AggregateFunctionTopK.cpp Outdated Show resolved Hide resolved
src/AggregateFunctions/AggregateFunctionTopK.cpp Outdated Show resolved Hide resolved
@UnamedRus
Copy link
Contributor Author

UnamedRus commented Oct 13, 2023

overall looks good but it would be nice to add some tests

It was more like POC example, will work on tests, if it's OK change.
I'm a little dislike, that change of parameter lead to change signature of function, but don't see any better way. (ie not use parameter for that)

Introduction of new aggregate function, like TopKWeighedCount, unfortunately will make people expect that they are different functions with different state and not same.

Anyway, it looks like, we better add

APPROX_TOP_K (TopK) and APPROX_TOP_SUM (TopKWeighed) aliases, because they are much more common in other dbms. Unfortunately, they don't have concept of parameters, so everything is being passed as arguments, so different signature, but ClickHouse way is slightly better to my taste.
Plus,

Third parameter value is slightly different, in ClickHouse its does mean load_factor, but in other dbms it does mean total amount of tracked elements. for ClickHouse it will be ( load_factor*N )

#42029 (comment)

@yakov-olkhovskiy
Copy link
Member

@UnamedRus could you please merge master again?

@yakov-olkhovskiy yakov-olkhovskiy merged commit bae4783 into ClickHouse:master Mar 2, 2024
228 of 240 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 2, 2024
@franz101 franz101 mentioned this pull request Mar 19, 2024
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-feature Pull request with new product feature pr-status-❌ PR with some error/faliure statuses 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.

None yet

6 participants