github-actions[bot] commented on code in PR #66824: URL: https://github.com/apache/doris/pull/66824#discussion_r3793727503
########## be/test/storage/segment/segment_iterator_predicate_null_state_test.cpp: ########## @@ -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) { Review Comment: Please exercise the production state producer in this test file. All three tests assign `_predicate_column_null_states` directly, so a regression in `_read_columns_by_index`—for example, a NULL-containing later chunk incorrectly remaining `NO_NULLS`, or every real no-NULL batch remaining conservative—would still pass even though that state controls predicate evaluation and null-map elision. Add a `SegmentIterator` test 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
