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

A native parquet reader for primitive types #60361

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

copperybean
Copy link
Contributor

@copperybean copperybean commented Feb 23, 2024

Changelog category (leave one):

  • Performance Improvement

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

A native parquet reader, which can read parquet binary to ClickHouse Columns directly. Now this feature can be activated by setting input_format_parquet_use_native_reader to true.

Currently, parquet file is read by arrow library, and it's read to arrow table first, and then copy the arrow table to ClickHouse Columns. There are some shortcomings in performance.

  • 1st, it's a redundant operation of copying data from arrow table to ClickHouse Columns.
  • 2nd, in arrow's implementation, repetition and definition levels are read to int16_t array first; then nullability related valid_bits_ is generated. While, the null_map and offsets (not included this time) can be generated directly when reading definition and repetition levels.
  • 3rd, for some situation, the arrow's implementation is inefficient, such as DataTypeDecimal32 type and dictionary parquet row group.

This feature is first implemented in the product BMR of Baidu AI Cloud, which has been fully tested.

Performance Test

As a result, the perforation of current implementation is speedup obviously. To generate the test data, a parquet file src.parquet of TPCDS table store_sales with scale 5000 is used, there are 35207247 rows in this file. Next, the test data is generated with following query:

select
  ss_item_sk,
  ss_wholesale_cost,
  ss_sales_price * ss_item_sk * ss_customer_sk as ss_sales_price_,
  concat('test string with ', toString(ss_item_sk % 1000)) as dict_str,
  concat('test string with ', toString(ss_item_sk * ss_cdemo_sk * ss_hdemo_sk)) as normal_str
from file('<path>/src.parquet', 'Parquet', 'ss_item_sk Nullable(Int32), ss_customer_sk Nullable(Int32), ss_cdemo_sk Nullable(Int32), ss_hdemo_sk Nullable(Int32), ss_wholesale_cost Nullable(Decimal(7, 2)), ss_sales_price Nullable(Decimal(21,6))')
into outfile '<path>/test.parquet' format Parquet

Then the performance is tested by following command

clickhouse-local --query "select max(<field-name>) from file('<path>/test.parquet', 'Parquet')" \
  --max_threads 1 --input_format_parquet_use_native_reader <flag>

For each field, two types tests are triggered with different input_format_parquet_use_native_reader setting, and single thread is used. The parquet reading duration is counted as commit log duration while reading parquet. The CPU model used by this test is Intel(R) Xeon(R) Gold 6271C CPU @ 2.60GHz.

The test result is detailed in following table

Column Current Duration Previous Duration SpeedUp
ss_item_sk Nullable(Int32) 117ms 141ms 1.2
ss_wholesale_cost Nullable(Decimal(7, 2)) 341ms 1132ms 3.3
ss_sales_price_ Nullable(Decimal(21, 6)) 720ms 1185ms 1.6
dict_str Nullable(String) 259ms 624ms 2.4
normal_str Nullable(String) 717ms 1154ms 1.6

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/

Copy link

clickhouse-ci bot commented Feb 23, 2024

This is an automatic comment. The PR descriptions does not match the template.

Please, edit it accordingly.

The error is: More than one changelog category specified: 'Improvement', 'Performance Improvement'

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Feb 23, 2024
@al13n321 al13n321 self-assigned this Feb 23, 2024
@robot-clickhouse robot-clickhouse added the pr-performance Pull request with some performance improvements label Feb 23, 2024
@robot-clickhouse
Copy link
Member

robot-clickhouse commented Feb 23, 2024

This is an automated comment for commit 5166d8b 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
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
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
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
Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS❌ failure
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
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Mergeable CheckChecks if all other necessary checks are successful❌ failure
Unit testsRuns the unit tests for different release types❌ error
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❌ failure

Change-Id: I83a8ec8271edefcd96cb5b3bcd12f6b545d9dec0
Change-Id: I57f025b17a04e2c5dded3f18e7f477841287a2c2
Change-Id: I38b8368b022263d9a71cb3f3e9fdad5d6ca26753
Change-Id: If79741b7456667a8dde3e355d9dc684c2dd84f4f
Change-Id: I53ade40ba24a742a21f9e09dbab7fff90b032b4b
Change-Id: I8f7ebd173558b16d94d3161cb0b5300e7e78833d
Change-Id: Ia7dbf1d762f7f054a9aa677caaaff6bfe1a42c38
@copperybean
Copy link
Contributor Author

copperybean commented Feb 29, 2024

Well, I think these break tests are not caused by my commit. UnitTestsAsan and ASTFuzzerTestAsan have succeeded in former test. While the integration test is failed because of logical error.

Hope for further suggestion.

@alexey-milovidov
Copy link
Member

Yes, we need to start the investigation, and then check and fix every failure one by one.

@copperybean
Copy link
Contributor Author

copperybean commented Mar 13, 2024

Yes, we need to start the investigation, and then check and fix every failure one by one.

@alexey-milovidov
About the investigation, do you refer to the investigation about this PR, or just about the failure tests?
And, should I rebase to master and trigger the checks again?

@alexey-milovidov
Copy link
Member

@copperybean, please resolve conflicts.

std::shared_ptr<::arrow::io::RandomAccessFile> arrow_file)
{
std::unique_ptr<parquet::ParquetFileReader> res;
THROW_PARQUET_EXCEPTION(res = parquet::ParquetFileReader::Open(std::move(arrow_file)));
Copy link
Contributor

Choose a reason for hiding this comment

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

File metadata should be passed in here, otherwise file footer will be read again here.

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-performance Pull request with some performance improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants