iceberg-cpp
Loading...
Searching...
No Matches
metrics_config.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 <string_view>
28#include <unordered_map>
29#include <unordered_set>
30#include <variant>
31
32#include "iceberg/iceberg_export.h"
33#include "iceberg/result.h"
34#include "iceberg/type_fwd.h"
35#include "iceberg/util/string_util.h"
36
37namespace iceberg {
38
39struct ICEBERG_EXPORT MetricsMode {
40 public:
41 enum class Kind : uint8_t {
42 kNone,
43 kCounts,
45 kFull,
46 };
47
48 static Result<MetricsMode> FromString(std::string_view mode);
49 static MetricsMode None();
50 static MetricsMode Counts();
51 static MetricsMode Full();
52
53 Kind kind;
54 std::variant<std::monostate, int32_t> length;
55
59 int32_t TruncateLength() const;
60};
61
63class ICEBERG_EXPORT MetricsConfig {
64 public:
66 static const std::shared_ptr<MetricsConfig>& Default();
67
69 static Result<std::shared_ptr<MetricsConfig>> Make(const Table& table);
70
74 static Result<std::shared_ptr<MetricsConfig>> Make(
75 std::unordered_map<std::string, std::string> properties);
76
78 static Result<std::unordered_set<int32_t>> LimitFieldIds(const Schema& schema,
79 int32_t limit);
80
85 static Status VerifyReferencedColumns(
86 const std::unordered_map<std::string, std::string>& updates, const Schema& schema);
87
91 MetricsMode ColumnMode(std::string_view column_name) const;
92
93 private:
94 using ColumnModeMap =
95 std::unordered_map<std::string, MetricsMode, StringHash, StringEqual>;
96
97 MetricsConfig(ColumnModeMap column_modes, MetricsMode default_mode);
98
109 static Result<std::shared_ptr<MetricsConfig>> MakeInternal(const TableProperties& props,
110 const Schema* schema,
111 const SortOrder* order);
112
113 ColumnModeMap column_modes_;
114 MetricsMode default_mode_;
115};
116
117} // namespace iceberg
Configuration for collecting column metrics for an Iceberg table.
Definition metrics_config.h:63
A schema for a Table.
Definition schema.h:51
A sort order for a table.
Definition sort_order.h:40
Table properties for Iceberg tables.
Definition table_properties.h:37
Represents an Iceberg table.
Definition table.h:38
Definition metrics_config.h:39
@ kTruncate
Value truncated to width W