iceberg-cpp
Loading...
Searching...
No Matches
schema_util_internal.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <map>
23
24#include "iceberg/schema_util.h"
25
26namespace iceberg {
27
28// Fix `from` field of `FieldProjection` to use pruned field index.
29inline void PruneFieldProjection(FieldProjection& field_projection) {
30 std::map<size_t, size_t> local_index_to_pruned_index;
31 for (const auto& child_projection : field_projection.children) {
32 if (child_projection.kind == FieldProjection::Kind::kProjected) {
33 local_index_to_pruned_index.emplace(std::get<1>(child_projection.from), 0);
34 }
35 }
36 for (size_t pruned_index = 0; auto& [_, value] : local_index_to_pruned_index) {
37 value = pruned_index++;
38 }
39 for (auto& child_projection : field_projection.children) {
40 if (child_projection.kind == FieldProjection::Kind::kProjected) {
41 child_projection.from =
42 local_index_to_pruned_index.at(std::get<1>(child_projection.from));
43 }
44 }
45}
46
47} // namespace iceberg
@ kProjected
The field is projected from the source with possible conversion for supported schema evolution.