|
| 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 <gtest/gtest.h> |
| 19 | + |
| 20 | +#include "vec/columns/column_string.h" |
| 21 | +#include "vec/olap/olap_data_convertor.h" |
| 22 | + |
| 23 | +namespace doris::vectorized { |
| 24 | + |
| 25 | +using ConvertorChar = OlapBlockDataConvertor::OlapColumnDataConvertorChar; |
| 26 | + |
| 27 | +TEST(CharTypePaddingTest, CharTypePaddingFullTest) { |
| 28 | + auto input = ColumnString::create(); |
| 29 | + |
| 30 | + std::string str = "Allemande"; |
| 31 | + size_t rows = 10; |
| 32 | + |
| 33 | + for (size_t i = 0; i < rows; i++) { |
| 34 | + input->insert_data(str.data(), str.length()); |
| 35 | + } |
| 36 | + EXPECT_FALSE(ConvertorChar::should_padding(input, str.length())); |
| 37 | + |
| 38 | + input->insert_data(str.data(), str.length() - 1); |
| 39 | + EXPECT_TRUE(ConvertorChar::should_padding(input, str.length())); |
| 40 | +} |
| 41 | + |
| 42 | +TEST(CharTypePaddingTest, CharTypePaddingDataTest) { |
| 43 | + auto input = ColumnString::create(); |
| 44 | + |
| 45 | + std::string str = "Allemande"; |
| 46 | + |
| 47 | + size_t rows = str.length(); |
| 48 | + for (int i = 0; i < rows; i++) { |
| 49 | + input->insert_data(str.data(), str.length() - i); |
| 50 | + } |
| 51 | + |
| 52 | + auto output = ConvertorChar::clone_and_padding(input, str.length()); |
| 53 | + |
| 54 | + for (int i = 0; i < rows; i++) { |
| 55 | + auto cell = output->get_data_at(i).to_string(); |
| 56 | + EXPECT_EQ(cell.length(), str.length()); |
| 57 | + |
| 58 | + auto str_real = std::string(cell.data(), str.length() - i); |
| 59 | + auto str_expect = str.substr(0, str.length() - i); |
| 60 | + EXPECT_EQ(str_real, str_expect); |
| 61 | + |
| 62 | + for (int j = str.length() - i; j < str.length(); j++) { |
| 63 | + EXPECT_EQ(cell[j], 0); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +} // namespace doris::vectorized |
0 commit comments