|
| 1 | +/* |
| 2 | + * Copyright 2026-present Alibaba Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "paimon/common/utils/arrow/arrow_utils.h" |
| 18 | + |
| 19 | +#include "arrow/api.h" |
| 20 | +#include "gtest/gtest.h" |
| 21 | +#include "paimon/common/types/data_field.h" |
| 22 | + |
| 23 | +namespace paimon::test { |
| 24 | + |
| 25 | +TEST(ArrowUtilsTest, TestCreateProjection) { |
| 26 | + std::vector<DataField> read_fields = {DataField(1, arrow::field("k1", arrow::int32())), |
| 27 | + DataField(3, arrow::field("p1", arrow::int32())), |
| 28 | + DataField(5, arrow::field("s1", arrow::utf8())), |
| 29 | + DataField(6, arrow::field("v0", arrow::float64())), |
| 30 | + DataField(7, arrow::field("v1", arrow::boolean()))}; |
| 31 | + auto read_schema = DataField::ConvertDataFieldsToArrowSchema(read_fields); |
| 32 | + |
| 33 | + std::vector<DataField> file_fields = {DataField(0, arrow::field("k0", arrow::int32())), |
| 34 | + DataField(1, arrow::field("k1", arrow::int32())), |
| 35 | + DataField(3, arrow::field("p1", arrow::int32())), |
| 36 | + DataField(5, arrow::field("s1", arrow::utf8())), |
| 37 | + DataField(6, arrow::field("v0", arrow::float64())), |
| 38 | + DataField(7, arrow::field("v1", arrow::boolean())), |
| 39 | + DataField(4, arrow::field("s0", arrow::utf8()))}; |
| 40 | + auto file_schema = DataField::ConvertDataFieldsToArrowSchema(file_fields); |
| 41 | + |
| 42 | + auto projection = ArrowUtils::CreateProjection(file_schema, read_schema->fields()); |
| 43 | + std::vector<int32_t> expected_projection = {1, 2, 3, 4, 5}; |
| 44 | + ASSERT_EQ(projection, expected_projection); |
| 45 | +} |
| 46 | + |
| 47 | +} // namespace paimon::test |
0 commit comments