Skip to content

Analyzer: filtering by virtual columns for StorageS3#56668

Merged
vdimir merged 5 commits intomasterfrom
vdimir/analyzer_s3_partition_pruning
Nov 22, 2023
Merged

Analyzer: filtering by virtual columns for StorageS3#56668
vdimir merged 5 commits intomasterfrom
vdimir/analyzer_s3_partition_pruning

Conversation

@vdimir
Copy link
Copy Markdown
Member

@vdimir vdimir commented Nov 13, 2023

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 13, 2023
@robot-ch-test-poll4
Copy link
Copy Markdown
Contributor

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

This is an automated comment for commit 31a6c7c 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
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
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
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
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors❌ failure

@vdimir vdimir changed the title Analyzer: partition pruning for S3 Analyzer: filtering by virtual columns for StorageS3 Nov 14, 2023
@vdimir vdimir force-pushed the vdimir/analyzer_s3_partition_pruning branch from 3256a00 to bb8c30f Compare November 15, 2023 10:26
@novikd novikd self-assigned this Nov 15, 2023
Copy link
Copy Markdown
Member

@novikd novikd left a comment

Choose a reason for hiding this comment

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

The code around filter DAG creation seems to be incorrect.


header = renameColumnsInBlock(header, column_rename);
auto filter_dag = buildActionsDAGFromExpressionNode(
query_node->getWhere(), header.getColumnsWithTypeAndName(), query_info.planner_context);
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.

This looks very suspicious. You should not extract filter from the query tree. Filter must be stored in the SelectQueryInfo::filter_actions_dag.
PartitionPruner uses SelectQueryInfo::filter_actions_dag.

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 updated code to use filters from SourceStepWithFilter as it was done in #56391

@vdimir vdimir force-pushed the vdimir/analyzer_s3_partition_pruning branch from bb8c30f to ab99267 Compare November 20, 2023 17:49
@vdimir vdimir force-pushed the vdimir/analyzer_s3_partition_pruning branch from ab99267 to 95e9a27 Compare November 20, 2023 18:00
@vdimir vdimir requested a review from novikd November 22, 2023 10:46
@vdimir
Copy link
Copy Markdown
Member Author

vdimir commented Nov 22, 2023

Integration tests (tsan) [4/6] — fail: 1, passed: 422 Details

test_storage_rabbitmq

Stress test (tsan) — Sanitizer assert (in stderr.log) Details

#57009

@vdimir vdimir merged commit ffbe85d into master Nov 22, 2023
@vdimir vdimir deleted the vdimir/analyzer_s3_partition_pruning branch November 22, 2023 15:44
@Avogar
Copy link
Copy Markdown
Member

Avogar commented Dec 29, 2023

I don't understand these changes. New filtering with filterKeysForPartitionPruning is used only before creating KeysIterator, but this iterator in most cases contains only 1 key, because for urls with globs we use DisclosedGlobIterator, and you didn't change the filtering in this iterator, so filtering still doesn't work when we have StorarteS3 with url that contains globs (and it's the main use case of filtering).
Also interesting why with analyzer filtering works with s3 table function without these changes and doesn't work with table created with S3 engine

size_t num_streams)
{
auto query_configuration = updateConfigurationAndGetCopy(local_context);
auto read_from_format_info = prepareReadingFromFormat(column_names, storage_snapshot, supportsSubsetOfColumns(local_context), virtual_columns);
Copy link
Copy Markdown
Member

@Avogar Avogar Dec 29, 2023

Choose a reason for hiding this comment

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

This read_from_format_info is used only for getting source_header, and then we call prepareReadingFromFormat again in ReadFromStorageS3Step::initializePipeline. Why don't just pass read_from_format_info as an argument in ReadFromStorageS3Step constructor so we don't do the same work twice?

@Avogar
Copy link
Copy Markdown
Member

Avogar commented Dec 29, 2023

:) create table test (number UInt64) engine=S3('http://localhost:11111/test/data*.jsonl');
:) select count(), _file from test where _file='data1.jsonl' group by _file settings allow_experimental_analyzer = 1;

┌─count()─┬─_file───────┐
│      10data1.jsonl │
└─────────┴─────────────┘

[avogar-dev] 2023.12.29 13:49:56 [ 0 ] EngineFileLikeReadFiles: 2 (increment)

So we still read 2 files instead of 1. But when we do the same using table function, it works:

:) select count(), _file from s3('http://localhost:11111/test/data*.jsonl') where _file = 'data1.jsonl' group by _file settings allow_experimental_analyzer=1

┌─count()─┬─_file───────┐
│      10data1.jsonl │
└─────────┴─────────────┘
[avogar-dev] 2023.12.29 13:51:49 [ 0 ] EngineFileLikeReadFiles: 1 (increment)

What is the difference between reading from storage and table function in analyzer?

@Avogar
Copy link
Copy Markdown
Member

Avogar commented Dec 29, 2023

And should we do smth similar with other engines like File, URL, HDFS, AzureBlob that support filtering

@Avogar
Copy link
Copy Markdown
Member

Avogar commented Dec 29, 2023

And also new functions getBlockWithVirtuals/filterKeysForPartitionPruning duplicate some logic from VirtualColumnUtils::filterByPathOrFile/getFilterByPathAndFileIndexes. As I understand the new approach with filter using ActionsDAG should work with both current infrastructure and new analyzer, why not to rewrite all filtering in S3/URL/HDFS/File/Azure to new approach? We will need to just rewrite common functions in VirtualColumnUtils and use them in that engines (most filtering functions from VirtualColumnUtils are used only in these engines).
Right now this new code in single engine for single use case with KeysIterator looks really strange.

If you don't have time to do it, tell me, I will do it.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants