Skip to content

Add parquet bloom filters support#62966

Merged
al13n321 merged 128 commits intoClickHouse:masterfrom
arthurpassos:add_parquet_bloom_filters_support
Oct 16, 2024
Merged

Add parquet bloom filters support#62966
al13n321 merged 128 commits intoClickHouse:masterfrom
arthurpassos:add_parquet_bloom_filters_support

Conversation

@arthurpassos
Copy link
Contributor

@arthurpassos arthurpassos commented Apr 25, 2024

Changelog category (leave one):

  • Performance Improvement

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

Add support for parquet bloom filters

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/


Modify your CI run:

NOTE: If your merge the PR with modified CI you MUST KNOW what you are doing
NOTE: Checked options will be applied if set before CI RunConfig/PrepareRunConfig step

Include tests (required builds will be added automatically):

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • All with ASAN
  • All with TSAN
  • All with Analyzer
  • Add your option here

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Performance tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All with Aarch64
  • Add your option here

Extra options:

  • do not test (only style check)
  • disable merge-commit (no merge from master before tests)
  • disable CI cache (job reuse)

Only specified batches in multi-batch jobs:

  • 1
  • 2
  • 3
  • 4

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Apr 25, 2024
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-feature Pull request with new product feature label Apr 25, 2024
@robot-ch-test-poll1
Copy link
Contributor

robot-ch-test-poll1 commented Apr 25, 2024

This is an automated comment for commit 424cd1b 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

@robot-ch-test-poll robot-ch-test-poll added pr-improvement Pull request with some product improvements and removed pr-feature Pull request with new product feature labels Apr 25, 2024
Copy link
Member

@al13n321 al13n321 left a comment

Choose a reason for hiding this comment

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

I'm confused about the if (hashes.size() != data_column->size()) line, and there are a couple remaining optional nitpicks, otherwise good to go.

Comment on lines +352 to +353
* `KeyCondition::RPNElement::FUNCTION_IN_RANGE` becomes:
* `KeyCondition::RPNElement::FUNCTION_IN_SET` becomes
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `KeyCondition::RPNElement::FUNCTION_IN_RANGE` becomes:
* `KeyCondition::RPNElement::FUNCTION_IN_SET` becomes
* `KeyCondition::RPNElement::FUNCTION_IN_RANGE` or `FUNCTION_IN_SET` becomes:

}
}

if (hashes.size() != data_column->size())
Copy link
Member

Choose a reason for hiding this comment

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

Wait, how does this not fail when hashes.empty()? How do tests pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed this case, sorry. Fixed by returning optional vector. Also added a test that confirmed the LOGICAL_ERROR exception.

Copy link
Member

@al13n321 al13n321 left a comment

Choose a reason for hiding this comment

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

One more bug, need to check if monotonic_functions_chain is empty.

* 1. file(..., 'string_column UInt64') where str_column = '50'; Field.type == UInt64. Parquet type string. Not supported.
* 2. file(...) where str_column = 50; Field.type == String (conversion already taken care by `KeyCondition`). Parquet type string.
* 3. file(...) where uint32_column = toIPv4(5). Field.type == IPv4. Incompatible column types, resolved by `KeyCondition` itself.
* 4. file(...) where toIPv4(uint32_column) = toIPv4(5). Field.type == IPv4. We know it is safe to hash it using an int32 API.
Copy link
Member

Choose a reason for hiding this comment

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

Oh, KeyCondition accepts this because toIPv4 is a monotonic function, and it puts the function in RPNElement::monotonic_functions_chain.

Wait, but then does it do the same for other functions? E.g. negate(x) = -42 - negate is a monotonic function. I.e. RPNElement will have range = [-42, -42] and monotonic_functions_chain = {negate}. I checked, and this is indeed what happens. So keyConditionRPNToParquetBloomFilterCondition will incorrectly look for value -42 in the bloom filter instead of 42. You have to check if monotonic_functions_chain is empty and do FUNCTION_UNKNOWN if not. Please add a test to reproduce the error first.

(The same happens for x + 10 = 52 - it handles binary function with one const argument.)

(Instead of FUNCTION_UNKNOWN we could try to apply the inverse function using IFunction::getPreimage, but that's not important.)

@arthurpassos
Copy link
Contributor Author

One more bug, need to check if monotonic_functions_chain is empty.

Fairly interesting. I just tested it and it would indeed be a problem. It is a problem for min/max stats evaluation as well:

arthur :) select * from file('afile.parquet', Parquet) where negate(int8_logical) = -58;

SELECT *
FROM file('afile.parquet', Parquet)
WHERE (-int8_logical) = -58

Query id: 7e350ea0-0e79-4cc6-867a-b58b06659f52

Ok.

0 rows in set. Elapsed: 15.389 sec. 

arthur :) select * from file('afile.parquet', Parquet) where negate(int8_logical) = -58 SETTINGS input_format_parquet_filter_push_down=false;

SELECT *
FROM file('afile.parquet', Parquet)
WHERE (-int8_logical) = -58
SETTINGS input_format_parquet_filter_push_down = false

Query id: 3bff6c4b-92ca-4f06-b2e9-1829a8c7873f

   ┌─int8_logical─┬─uint16_logical─┬─ipv4─┬──────int64─┬──────uint64_logical─┬─boolean─┬─string─┬─json─────────────────────────┬─flba─┬─uuid────┐
1. │           58 │          57159 │  631 │ 4294967365 │ 9829797005067372154 │ true    │ RRBT   │ {"key":291, "value":"DUBPO"} │ NDBX │ �G�)@��譔�:� │
   └──────────────┴────────────────┴──────┴────────────┴─────────────────────┴─────────┴────────┴──────────────────────────────┴──────┴─────────┘
   ┌─int8_logical─┬─uint16_logical─┬─ipv4─┬──────int64─┬───────uint64_logical─┬─boolean─┬─string─┬─json─────────────────────────┬─flba─┬─uuid──────┐
2. │           58 │          63254 │  986 │ 4294967373 │ 12146296632881510326 │ false   │ SOOF   │ {"key":244, "value":"XPHCW"} │ BBET │ XH�rBr�,����SN  │
3. │           58 │          14652 │  334 │ 4294967346 │ 16224854854285702292 │ false   │ MWPY   │ {"key":592, "value":"NJOJN"} │ PADH │ L^�e�
                                                                                                                                              A;�� Y�f�, │
   └──────────────┴────────────────┴──────┴────────────┴──────────────────────┴─────────┴────────┴──────────────────────────────┴──────┴───────────┘
   ┌─int8_logical─┬─uint16_logical─┬─ipv4─┬──────int64─┬──────uint64_logical─┬─boolean─┬─string─┬─json─────────────────────────┬─flba─┬─uuid────┐
4. │           58 │          29205 │  586 │ 4294967321 │ 4503168388465453601 │ true    │ CDTD   │ {"key":208, "value":"LOCNZ"} │ UVDZ │ 4��|B���zo?�" │
�B�� │         58 │          22488 │   75 │ 4294967378 │ 1882125239624409868 │ false   │ NGRD   │ {"key":22, "value":"OVAPX"}  │ CDOA │ Cn��pO�� 
   └──────────────┴────────────────┴──────┴────────────┴─────────────────────┴─────────┴────────┴──────────────────────────────┴──────┴─────────┘

5 rows in set. Elapsed: 2.629 sec. Processed 1.00 thousand rows, 47.42 KB (380.38 rows/s., 18.04 KB/s.)
Peak memory usage: 129.99 KiB.

@al13n321
Copy link
Member

It is a problem for min/max stats evaluation as well:

I couldn't reproduce. What's in afile.parquet?

insert into function file('t.parquet') select 42::Int64 as x settings engine_file_truncate_on_insert=1;

select * from file('t.parquet') where negate(x) = -42 settings input_format_parquet_filter_push_down=1

SELECT *
FROM file('t.parquet')
WHERE (-x) = -42
SETTINGS input_format_parquet_filter_push_down = 1

Query id: 472f9083-ac38-4aa5-9cc4-2191f45639ca

   ┌──x─┐
1. │ 42 │
   └────┘

1 row in set. Elapsed: 0.003 sec. 

-- check that index is used at all:
select * from file('t.parquet') where indexHint(negate(x) = -43) settings input_format_parquet_filter_push_down=1

SELECT *
FROM file('t.parquet')
WHERE indexHint((-x) = -43)
SETTINGS input_format_parquet_filter_push_down = 1

Query id: 3f2e7936-ec56-431d-a399-c0e6914257d4

Ok.

0 rows in set. Elapsed: 0.003 sec. 

Min/max thing shouldn't have this exact problem because it calls KeyCondition::checkInHyperrectangle, which applies the monotonic functions.

@arthurpassos
Copy link
Contributor Author

It is a problem for min/max stats evaluation as well:

I couldn't reproduce. What's in afile.parquet?

insert into function file('t.parquet') select 42::Int64 as x settings engine_file_truncate_on_insert=1;



select * from file('t.parquet') where negate(x) = -42 settings input_format_parquet_filter_push_down=1



SELECT *

FROM file('t.parquet')

WHERE (-x) = -42

SETTINGS input_format_parquet_filter_push_down = 1



Query id: 472f9083-ac38-4aa5-9cc4-2191f45639ca



   ┌──x─┐

1. │ 42 │

   └────┘



1 row in set. Elapsed: 0.003 sec. 



-- check that index is used at all:

select * from file('t.parquet') where indexHint(negate(x) = -43) settings input_format_parquet_filter_push_down=1



SELECT *

FROM file('t.parquet')

WHERE indexHint((-x) = -43)

SETTINGS input_format_parquet_filter_push_down = 1



Query id: 3f2e7936-ec56-431d-a399-c0e6914257d4



Ok.



0 rows in set. Elapsed: 0.003 sec. 

Min/max thing shouldn't have this exact problem because it calls KeyCondition::checkInHyperrectangle, which applies the monotonic functions.

It should be the same as the file in this PR. Maybe I missed something while testing, will double check tomorrow.

@al13n321 al13n321 added this pull request to the merge queue Oct 16, 2024
Merged via the queue into ClickHouse:master with commit 1c45f9f Oct 16, 2024
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Oct 16, 2024
(cherry picked from commit cbbf128e9403b1598cfe62543414d7d2378c33ed)
baibaichen added a commit to Kyligence/gluten that referenced this pull request Oct 16, 2024
(cherry picked from commit cbbf128e9403b1598cfe62543414d7d2378c33ed)
baibaichen added a commit to apache/gluten that referenced this pull request Oct 16, 2024
* [GLUTEN-1632][CH]Daily Update Clickhouse Version (20241016)

* Fix Build due to ClickHouse/ClickHouse#70158

* Fix build due to ClickHouse/ClickHouse#62966

* add more info for exception

* Fix ut due to ClickHouse/ClickHouse#69481

---------

Co-authored-by: kyligence-git <[email protected]>
Co-authored-by: Chang Chen <[email protected]>
@arthurpassos
Copy link
Contributor Author

It is a problem for min/max stats evaluation as well:

I couldn't reproduce. What's in afile.parquet?

insert into function file('t.parquet') select 42::Int64 as x settings engine_file_truncate_on_insert=1;

select * from file('t.parquet') where negate(x) = -42 settings input_format_parquet_filter_push_down=1

SELECT *
FROM file('t.parquet')
WHERE (-x) = -42
SETTINGS input_format_parquet_filter_push_down = 1

Query id: 472f9083-ac38-4aa5-9cc4-2191f45639ca

   ┌──x─┐
1. │ 42 │
   └────┘

1 row in set. Elapsed: 0.003 sec. 

-- check that index is used at all:
select * from file('t.parquet') where indexHint(negate(x) = -43) settings input_format_parquet_filter_push_down=1

SELECT *
FROM file('t.parquet')
WHERE indexHint((-x) = -43)
SETTINGS input_format_parquet_filter_push_down = 1

Query id: 3f2e7936-ec56-431d-a399-c0e6914257d4

Ok.

0 rows in set. Elapsed: 0.003 sec. 

Min/max thing shouldn't have this exact problem because it calls KeyCondition::checkInHyperrectangle, which applies the monotonic functions.

Running this query with bloom_filter = false and minmax_filter = true returns inconsistent results

@al13n321
Copy link
Member

al13n321 commented Nov 5, 2024

Minimized to:

insert into function file('t.parquet') select 12345678901234567890::UInt64 as x union all select 42::UInt64 as x settings engine_file_truncate_on_insert=1;
select * from file('t.parquet') where -x = -42;

The problem is that negate overflows on the max value from statistics, and KeyCondition doesn't notice and ends up with inverted range. Fix: #71440

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 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.

8 participants