|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#include "vec/common/schema_util.h" |
| 19 | + |
| 20 | +#include <gtest/gtest.h> |
| 21 | + |
| 22 | +namespace doris { |
| 23 | + |
| 24 | +class SchemaUtilTest : public testing::Test {}; |
| 25 | + |
| 26 | +void construct_column(ColumnPB* column_pb, TabletIndexPB* tablet_index, int64_t index_id, |
| 27 | + const std::string& index_name, int32_t col_unique_id, |
| 28 | + const std::string& column_type, const std::string& column_name, |
| 29 | + const IndexType& index_type) { |
| 30 | + column_pb->set_unique_id(col_unique_id); |
| 31 | + column_pb->set_name(column_name); |
| 32 | + column_pb->set_type(column_type); |
| 33 | + column_pb->set_is_nullable(true); |
| 34 | + column_pb->set_is_bf_column(true); |
| 35 | + tablet_index->set_index_id(index_id); |
| 36 | + tablet_index->set_index_name(index_name); |
| 37 | + tablet_index->set_index_type(index_type); |
| 38 | + tablet_index->add_col_unique_id(col_unique_id); |
| 39 | +} |
| 40 | + |
| 41 | +void construct_subcolumn(TabletSchemaSPtr schema, const FieldType& type, int32_t col_unique_id, |
| 42 | + std::string_view path, std::vector<TabletColumn>* subcolumns) { |
| 43 | + TabletColumn subcol; |
| 44 | + subcol.set_type(type); |
| 45 | + subcol.set_is_nullable(true); |
| 46 | + subcol.set_unique_id(-1); |
| 47 | + subcol.set_parent_unique_id(col_unique_id); |
| 48 | + vectorized::PathInData col_path(path); |
| 49 | + subcol.set_path_info(col_path); |
| 50 | + subcol.set_name(col_path.get_path()); |
| 51 | + schema->append_column(subcol); |
| 52 | + subcolumns->emplace_back(std::move(subcol)); |
| 53 | +} |
| 54 | + |
| 55 | +TEST_F(SchemaUtilTest, inherit_column_attributes) { |
| 56 | + TabletSchemaPB schema_pb; |
| 57 | + schema_pb.set_keys_type(KeysType::DUP_KEYS); |
| 58 | + schema_pb.set_inverted_index_storage_format(InvertedIndexStorageFormatPB::V2); |
| 59 | + |
| 60 | + construct_column(schema_pb.add_column(), schema_pb.add_index(), 10000, "key_index", 0, "INT", |
| 61 | + "key", IndexType::INVERTED); |
| 62 | + construct_column(schema_pb.add_column(), schema_pb.add_index(), 10001, "v1_index", 1, "VARIANT", |
| 63 | + "v1", IndexType::INVERTED); |
| 64 | + construct_column(schema_pb.add_column(), schema_pb.add_index(), 10003, "v3_index", 3, "VARIANT", |
| 65 | + "v3", IndexType::INVERTED); |
| 66 | + |
| 67 | + TabletSchemaSPtr tablet_schema = std::make_shared<TabletSchema>(); |
| 68 | + tablet_schema->init_from_pb(schema_pb); |
| 69 | + std::vector<TabletColumn> subcolumns; |
| 70 | + |
| 71 | + construct_subcolumn(tablet_schema, FieldType::OLAP_FIELD_TYPE_STRING, 1, "v1.b", &subcolumns); |
| 72 | + construct_subcolumn(tablet_schema, FieldType::OLAP_FIELD_TYPE_INT, 1, "v1.c", &subcolumns); |
| 73 | + |
| 74 | + construct_subcolumn(tablet_schema, FieldType::OLAP_FIELD_TYPE_ARRAY, 3, "v3.d", &subcolumns); |
| 75 | + construct_subcolumn(tablet_schema, FieldType::OLAP_FIELD_TYPE_FLOAT, 3, "v3.a", &subcolumns); |
| 76 | + |
| 77 | + vectorized::schema_util::inherit_column_attributes(tablet_schema); |
| 78 | + for (const auto& col : subcolumns) { |
| 79 | + switch (col._parent_col_unique_id) { |
| 80 | + case 1: |
| 81 | + EXPECT_TRUE(tablet_schema->inverted_index(col) != nullptr); |
| 82 | + break; |
| 83 | + case 3: |
| 84 | + EXPECT_TRUE(tablet_schema->inverted_index(col) == nullptr); |
| 85 | + break; |
| 86 | + default: |
| 87 | + EXPECT_TRUE(false); |
| 88 | + } |
| 89 | + } |
| 90 | + EXPECT_EQ(tablet_schema->inverted_indexes().size(), 7); |
| 91 | + |
| 92 | + for (const auto& col : tablet_schema->_cols) { |
| 93 | + if (!col->is_extracted_column()) { |
| 94 | + continue; |
| 95 | + } |
| 96 | + switch (col->_parent_col_unique_id) { |
| 97 | + case 1: |
| 98 | + EXPECT_TRUE(col->is_bf_column()); |
| 99 | + break; |
| 100 | + case 3: |
| 101 | + EXPECT_TRUE(!col->is_bf_column()); |
| 102 | + break; |
| 103 | + default: |
| 104 | + EXPECT_TRUE(false); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +} // namespace doris |
0 commit comments