iceberg-cpp
Loading...
Searching...
No Matches
schema_util.h
Go to the documentation of this file.
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
24
25#include <memory>
26#include <string>
27#include <variant>
28#include <vector>
29
32#include "iceberg/result.h"
33#include "iceberg/type_fwd.h"
34
35namespace iceberg {
36
38struct ICEBERG_EXPORT FieldProjection {
40 enum class Kind {
43 kProjected,
45 kMetadata,
47 kConstant,
49 kDefault,
51 kNull,
52 };
53
60 using From = std::variant<std::monostate, size_t, Literal>;
61
66 virtual ~ExtraAttributes() = default;
67 };
68
74 std::vector<FieldProjection> children;
76 std::shared_ptr<ExtraAttributes> attributes;
77};
78
80struct ICEBERG_EXPORT SchemaProjection {
81 std::vector<FieldProjection> fields;
82};
83
85enum class ProjectionMode {
87 kRead,
89 kWrite,
90};
91
104 const Schema& expected_schema, const Schema& source_schema, bool prune_source,
106
107ICEBERG_EXPORT std::string_view ToString(FieldProjection::Kind kind);
108ICEBERG_EXPORT std::string ToString(const FieldProjection& projection);
109ICEBERG_EXPORT std::string ToString(const SchemaProjection& projection);
110
111} // namespace iceberg
A schema for a Table.
Definition schema.h:51
Definition expected.h:1199
Define symbol visibility macros for core Iceberg APIs.
Define typed literal values used by expressions.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
ICEBERG_EXPORT Result< SchemaProjection > Project(const Schema &expected_schema, const Schema &source_schema, bool prune_source, ProjectionMode mode=ProjectionMode::kRead)
Project the expected schema on top of the source schema.
ICEBERG_EXPORT std::string_view ToString(Expression::Operation op)
Returns a string representation of an expression operation.
ProjectionMode
Whether schema projection is used for reading or writing.
Definition schema_util.h:85
@ kRead
Use initial-default and allow type promotion.
@ kWrite
Use write-default, require matching types, and reject optional-to-required.
Define Result, Status, and error helpers.
Format-specific attributes for the field. For example, for Parquet it might store column id and level...
Definition schema_util.h:65
A field schema partner to carry projection information.
Definition schema_util.h:38
std::variant< std::monostate, size_t, Literal > From
A variant to indicate how to set the value of the field.
Definition schema_util.h:60
std::vector< FieldProjection > children
The children of the field if it is a nested field.
Definition schema_util.h:74
Kind kind
The kind of projection of the field it partners with.
Definition schema_util.h:70
From from
The source to set the value of the field.
Definition schema_util.h:72
Kind
How the field is projected.
Definition schema_util.h:40
std::shared_ptr< ExtraAttributes > attributes
Format-specific attributes for the field.
Definition schema_util.h:76
A schema partner to carry projection information.
Definition schema_util.h:80