-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[opt](exec) Skip null maps for predicate batches without nulls #66824
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
Open
Mryange
wants to merge
1
commit into
apache:master
Choose a base branch
from
Mryange:opt-null-free-predicate-batch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+222
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
be/test/storage/segment/segment_iterator_predicate_null_state_test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "core/assert_cast.h" | ||
| #include "core/column/column_nullable.h" | ||
| #include "core/column/column_vector.h" | ||
| #include "storage/olap_common.h" | ||
| #include "storage/predicate/null_predicate.h" | ||
| #include "storage/tablet/tablet_schema.h" | ||
|
|
||
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wkeyword-macro" | ||
| #endif | ||
| #include "storage/segment/segment_iterator.h" | ||
| #if defined(__clang__) | ||
| #pragma clang diagnostic pop | ||
| #endif | ||
|
|
||
| namespace doris::segment_v2 { | ||
| namespace { | ||
|
|
||
| MutableColumnPtr make_nullable_int_column(const std::vector<int32_t>& values, | ||
| const std::vector<uint8_t>& null_map) { | ||
| auto nested = ColumnInt32::create(); | ||
| auto nulls = ColumnUInt8::create(); | ||
| for (auto value : values) { | ||
| nested->insert_value(value); | ||
| } | ||
| for (auto is_null : null_map) { | ||
| nulls->insert_value(is_null); | ||
| } | ||
| return ColumnNullable::create(std::move(nested), std::move(nulls)); | ||
| } | ||
|
|
||
| TabletSchemaSPtr make_nullable_int_schema() { | ||
| TabletSchemaPB schema_pb; | ||
| schema_pb.set_keys_type(KeysType::DUP_KEYS); | ||
| auto* column = schema_pb.add_column(); | ||
| column->set_unique_id(0); | ||
| column->set_name("c0"); | ||
| column->set_type("INT"); | ||
| column->set_is_key(true); | ||
| column->set_is_nullable(true); | ||
|
|
||
| auto tablet_schema = std::make_shared<TabletSchema>(); | ||
| tablet_schema->init_from_pb(schema_pb); | ||
| return tablet_schema; | ||
| } | ||
|
|
||
| SchemaSPtr make_read_schema(const TabletSchemaSPtr& tablet_schema) { | ||
| return std::make_shared<Schema>(tablet_schema->columns(), std::vector<ColumnId> {0}); | ||
| } | ||
|
|
||
| void expect_nullable_int_column(const MutableColumnPtr& column, | ||
| const std::vector<int32_t>& expected_values, | ||
| const std::vector<uint8_t>& expected_null_map) { | ||
| const auto& nullable = assert_cast<const ColumnNullable&>(*column); | ||
| const auto& nested = assert_cast<const ColumnInt32&>(nullable.get_nested_column()); | ||
| ASSERT_EQ(expected_values.size(), nested.size()); | ||
| ASSERT_EQ(expected_null_map.size(), nullable.get_null_map_data().size()); | ||
| for (size_t i = 0; i < expected_values.size(); ++i) { | ||
| EXPECT_EQ(expected_values[i], nested.get_data()[i]); | ||
| EXPECT_EQ(expected_null_map[i], nullable.get_null_map_data()[i]); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| class SegmentIteratorPredicateNullStateTest : public ::testing::Test { | ||
| protected: | ||
| void SetUp() override { | ||
| _tablet_schema = make_nullable_int_schema(); | ||
| _read_schema = make_read_schema(_tablet_schema); | ||
| } | ||
|
|
||
| std::unique_ptr<SegmentIterator> make_iter() { | ||
| return std::make_unique<SegmentIterator>(nullptr, _read_schema); | ||
| } | ||
|
|
||
| TabletSchemaSPtr _tablet_schema; | ||
| SchemaSPtr _read_schema; | ||
| }; | ||
|
|
||
| TEST_F(SegmentIteratorPredicateNullStateTest, UsesNestedColumnOnlyWhenNoNullsAreKnown) { | ||
| auto iter = make_iter(); | ||
| auto input = make_nullable_int_column({10, 20, 30}, {0, 0, 0}); | ||
| const auto* input_ptr = input.get(); | ||
| const auto* nested_ptr = &assert_cast<const ColumnNullable&>(*input).get_nested_column(); | ||
| iter->_current_return_columns.emplace_back(std::move(input)); | ||
| iter->_predicate_column_null_states.resize(1); | ||
| auto predicate = NullPredicate::create_shared(0, "c0", true, PrimitiveType::TYPE_INT); | ||
|
|
||
| iter->_predicate_column_null_states[0] = SegmentIterator::PredicateColumnNullState::NO_NULLS; | ||
| EXPECT_EQ(nested_ptr, iter->_get_predicate_column(*predicate)); | ||
|
|
||
| iter->_predicate_column_null_states[0] = SegmentIterator::PredicateColumnNullState::HAS_NULLS; | ||
| EXPECT_EQ(input_ptr, iter->_get_predicate_column(*predicate)); | ||
|
|
||
| iter->_predicate_column_null_states[0] = SegmentIterator::PredicateColumnNullState::UNKNOWN; | ||
| EXPECT_EQ(input_ptr, iter->_get_predicate_column(*predicate)); | ||
| } | ||
|
|
||
| TEST_F(SegmentIteratorPredicateNullStateTest, CopiesNullableColumnWithoutFilteringNullMap) { | ||
| auto iter = make_iter(); | ||
| auto input = make_nullable_int_column({10, 20, 30}, {0, 0, 0}); | ||
| MutableColumnPtr output = ColumnNullable::create(ColumnInt32::create(), ColumnUInt8::create()); | ||
| uint16_t selector[] = {2, 0}; | ||
|
|
||
| auto status = | ||
| iter->copy_column_data_by_selector(input.get(), output, selector, 2, 3, | ||
| SegmentIterator::PredicateColumnNullState::NO_NULLS); | ||
|
|
||
| ASSERT_TRUE(status.ok()) << status.to_string(); | ||
| ASSERT_TRUE(output->is_nullable()); | ||
| EXPECT_FALSE(assert_cast<const ColumnNullable&>(*output).has_null()); | ||
| expect_nullable_int_column(output, {30, 10}, {0, 0}); | ||
| } | ||
|
|
||
| TEST_F(SegmentIteratorPredicateNullStateTest, PreservesNullsForKnownAndUnknownStates) { | ||
| for (auto null_state : {SegmentIterator::PredicateColumnNullState::HAS_NULLS, | ||
| SegmentIterator::PredicateColumnNullState::UNKNOWN}) { | ||
| SCOPED_TRACE(static_cast<int>(null_state)); | ||
| auto iter = make_iter(); | ||
| auto input = make_nullable_int_column({10, 20, 30}, {0, 1, 0}); | ||
| MutableColumnPtr output = | ||
| ColumnNullable::create(ColumnInt32::create(), ColumnUInt8::create()); | ||
| uint16_t selector[] = {1, 2}; | ||
|
|
||
| auto status = | ||
| iter->copy_column_data_by_selector(input.get(), output, selector, 2, 3, null_state); | ||
|
|
||
| ASSERT_TRUE(status.ok()) << status.to_string(); | ||
| EXPECT_TRUE(assert_cast<const ColumnNullable&>(*output).has_null()); | ||
| expect_nullable_int_column(output, {20, 30}, {1, 0}); | ||
| } | ||
| } | ||
|
|
||
| } // namespace doris::segment_v2 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please exercise the production state producer in this test file. All three tests assign
_predicate_column_null_statesdirectly, so a regression in_read_columns_by_index—for example, a NULL-containing later chunk incorrectly remainingNO_NULLS, or every real no-NULL batch remaining conservative—would still pass even though that state controls predicate evaluation and null-map elision. Add aSegmentIteratortest backed by real nullable segment data that covers no-NULL and NULL-containing batches plus continuous and rowid-fallback/discontinuous reads, and asserts returned rows/null maps for representative vectorized and short-circuit predicates.